Fix for ReadaheadSequentialFile crash in ldb_cmd_test (#5586)

Summary:
Fixing a corner case crash when there was no data read from file, but status is still OK
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5586

Differential Revision: D16348117

Pulled By: elipoz

fbshipit-source-id: f97973308024f020d8be79ca3c56466b84d80656
This commit is contained in:
Eli Pozniansky 2019-07-17 17:01:30 -07:00 committed by Facebook Github Bot
parent 8a008d4170
commit 9f5cfb8e71
2 changed files with 8 additions and 3 deletions

View File

@ -738,7 +738,7 @@ private:
if (s.ok()) { if (s.ok()) {
buffer_offset_ = offset; buffer_offset_ = offset;
buffer_.Size(result.size()); buffer_.Size(result.size());
assert(buffer_.BufferStart() == result.data()); assert(result.size() == 0 || buffer_.BufferStart() == result.data());
} }
return s; return s;
} }
@ -886,7 +886,7 @@ class ReadaheadSequentialFile : public SequentialFile {
if (s.ok()) { if (s.ok()) {
buffer_offset_ = read_offset_; buffer_offset_ = read_offset_;
buffer_.Size(result.size()); buffer_.Size(result.size());
assert(buffer_.BufferStart() == result.data()); assert(result.size() == 0 || buffer_.BufferStart() == result.data());
} }
return s; return s;
} }
@ -1027,6 +1027,11 @@ std::unique_ptr<RandomAccessFile> NewReadaheadRandomAccessFile(
std::unique_ptr<SequentialFile> std::unique_ptr<SequentialFile>
SequentialFileReader::NewReadaheadSequentialFile( SequentialFileReader::NewReadaheadSequentialFile(
std::unique_ptr<SequentialFile>&& file, size_t readahead_size) { std::unique_ptr<SequentialFile>&& file, size_t readahead_size) {
if (file->GetRequiredBufferAlignment() >= readahead_size) {
// Short-circuit and return the original file if readahead_size is
// too small and hence doesn't make sense to be used for prefetching.
return std::move(file);
}
std::unique_ptr<SequentialFile> result( std::unique_ptr<SequentialFile> result(
new ReadaheadSequentialFile(std::move(file), readahead_size)); new ReadaheadSequentialFile(std::move(file), readahead_size));
return result; return result;

View File

@ -325,7 +325,7 @@ class ReadaheadSequentialFileTest : public testing::Test,
public testing::WithParamInterface<size_t> { public testing::WithParamInterface<size_t> {
public: public:
static std::vector<size_t> GetReadaheadSizeList() { static std::vector<size_t> GetReadaheadSizeList() {
return {1lu << 12, 1lu << 16}; return {1lu << 8, 1lu << 12, 1lu << 16, 1lu << 18};
} }
void SetUp() override { void SetUp() override {
readahead_size_ = GetParam(); readahead_size_ = GetParam();