Fix a bug caused by not copying the block trailer. (#4096)

Summary:
This was caught by crash test, and the following is a simple way to reproduce it and verify the fix.
One way to trigger this code path is to use the following configuration:
- Compress SST file
- Enable direct IO and prefetch buffer
- Do NOT use compressed block cache
Closes https://github.com/facebook/rocksdb/pull/4096

Differential Revision: D8742009

Pulled By: riversand963

fbshipit-source-id: f13381078bbb0dce92f60bd313a78ab602bcacd2
This commit is contained in:
Yanqin Jin 2018-07-06 13:09:57 -07:00 committed by Facebook Github Bot
parent 35b83327a7
commit d4d9fe8e57
2 changed files with 5 additions and 5 deletions

View File

@ -104,7 +104,6 @@ extern SstFileManager* NewSstFileManager(
Env* env, std::shared_ptr<Logger> info_log = nullptr,
std::string trash_dir = "", int64_t rate_bytes_per_sec = 0,
bool delete_existing_trash = true, Status* status = nullptr,
double max_trash_db_ratio = 0.25,
uint64_t bytes_max_delete_chunk = 0);
double max_trash_db_ratio = 0.25, uint64_t bytes_max_delete_chunk = 0);
} // namespace rocksdb

View File

@ -166,10 +166,11 @@ void BlockFetcher::GetBlockContents() {
*contents_ = BlockContents(Slice(slice_.data(), block_size_),
immortal_source_, compression_type);
} else {
// page is uncompressed, the buffer either stack or heap provided
// page can be either uncompressed or compressed, the buffer either stack
// or heap provided. Refer to https://github.com/facebook/rocksdb/pull/4096
if (got_from_prefetch_buffer_ || used_buf_ == &stack_buf_[0]) {
heap_buf_.reset(new char[block_size_]);
memcpy(heap_buf_.get(), used_buf_, block_size_);
heap_buf_.reset(new char[block_size_ + kBlockTrailerSize]);
memcpy(heap_buf_.get(), used_buf_, block_size_ + kBlockTrailerSize);
}
*contents_ = BlockContents(std::move(heap_buf_), block_size_, true,
compression_type);