提交 57461fba 编写于 作者: A Andrew Kryczka

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
上级 0e200001
......@@ -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;
}
......
......@@ -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) {
......
......@@ -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;
}
......
......@@ -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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册