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
main
Yanqin Jin 6 years ago committed by Facebook Github Bot
parent 35b83327a7
commit d4d9fe8e57
  1. 3
      include/rocksdb/sst_file_manager.h
  2. 7
      table/block_fetcher.cc

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

@ -166,10 +166,11 @@ void BlockFetcher::GetBlockContents() {
*contents_ = BlockContents(Slice(slice_.data(), block_size_), *contents_ = BlockContents(Slice(slice_.data(), block_size_),
immortal_source_, compression_type); immortal_source_, compression_type);
} else { } 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]) { if (got_from_prefetch_buffer_ || used_buf_ == &stack_buf_[0]) {
heap_buf_.reset(new char[block_size_]); heap_buf_.reset(new char[block_size_ + kBlockTrailerSize]);
memcpy(heap_buf_.get(), used_buf_, block_size_); memcpy(heap_buf_.get(), used_buf_, block_size_ + kBlockTrailerSize);
} }
*contents_ = BlockContents(std::move(heap_buf_), block_size_, true, *contents_ = BlockContents(std::move(heap_buf_), block_size_, true,
compression_type); compression_type);

Loading…
Cancel
Save