In-memory environment read beyond EOF

Summary:
Made it consistent with posix Env, which uses pread() that returns 0
(success) when an offset is given beyond EOF. The purpose of making these Envs
behave consistently is I am repurposing the in-memory Envs' tests for the basic
Env tests in D58635.

Test Plan: ran mock_env_test and memenv_test

Reviewers: IslamAbdelRahman, lightmark, sdong

Reviewed By: sdong

Subscribers: andrewkr, dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D58845
This commit is contained in:
Andrew Kryczka 2016-05-27 12:10:26 -07:00
parent 0e20000171
commit 57461fba8c
4 changed files with 11 additions and 14 deletions

View File

@ -2,14 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.
#include <string.h>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include "rocksdb/env.h"
#include "rocksdb/status.h"
#include "port/port.h"
#include "util/mutexlock.h"
#include <map>
#include <string.h>
#include <string>
#include <vector>
namespace rocksdb {
@ -70,10 +73,7 @@ class FileState {
uint64_t Size() const { return size_; }
Status Read(uint64_t offset, size_t n, Slice* result, char* scratch) const {
if (offset > size_) {
return Status::IOError("Offset greater than file size.");
}
const uint64_t available = size_ - offset;
const uint64_t available = size_ - std::min(size_, offset);
if (n > available) {
n = available;
}

View File

@ -124,7 +124,7 @@ TEST_F(MemEnvTest, ReadWrite) {
ASSERT_EQ(0, result.compare("d"));
// Too high offset.
ASSERT_TRUE(!rand_file->Read(1000, 5, &result, scratch).ok());
ASSERT_TRUE(rand_file->Read(1000, 5, &result, scratch).ok());
}
TEST_F(MemEnvTest, Locks) {

View File

@ -99,10 +99,7 @@ class MemFile {
Status Read(uint64_t offset, size_t n, Slice* result, char* scratch) const {
MutexLock lock(&mutex_);
if (offset > Size()) {
return Status::IOError("Offset greater than file size.");
}
const uint64_t available = Size() - offset;
const uint64_t available = Size() - std::min(Size(), offset);
if (n > available) {
n = available;
}

View File

@ -123,7 +123,7 @@ TEST_F(MockEnvTest, ReadWrite) {
ASSERT_EQ(0, result.compare("d"));
// Too high offset.
ASSERT_TRUE(!rand_file->Read(1000, 5, &result, scratch).ok());
ASSERT_TRUE(rand_file->Read(1000, 5, &result, scratch).ok());
}
TEST_F(MockEnvTest, Locks) {