From d4d9fe8e57ca6b5705c7ee2a234331c0e6d2c2ea Mon Sep 17 00:00:00 2001 From: Yanqin Jin Date: Fri, 6 Jul 2018 13:09:57 -0700 Subject: [PATCH] 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 --- include/rocksdb/sst_file_manager.h | 3 +-- table/block_fetcher.cc | 7 ++++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/rocksdb/sst_file_manager.h b/include/rocksdb/sst_file_manager.h index d1133d871..439537e2a 100644 --- a/include/rocksdb/sst_file_manager.h +++ b/include/rocksdb/sst_file_manager.h @@ -104,7 +104,6 @@ extern SstFileManager* NewSstFileManager( Env* env, std::shared_ptr 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 diff --git a/table/block_fetcher.cc b/table/block_fetcher.cc index e893c9592..8a35137c5 100644 --- a/table/block_fetcher.cc +++ b/table/block_fetcher.cc @@ -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);