mirror of https://github.com/facebook/rocksdb.git
21d5a8f54f
Summary: ### Summary: The sst_dump tool occur IO Error when reading data in PlainTable, as shown in the follow ```bash ❯ ./sst_dump --file=/tmp/write_example --command=scan --show_properties --verify_checksum options.env is 0x60000282dc00 Process /tmp/write_example/001630.sst Sst file format: plain table /tmp/filepicker_example/001630.sst: IO error: While pread offset 0 len 758: /tmp/filepicker_example/001630.sst: Bad address Process /tmp/filepicker_example/001624.sst ``` #### Reason The root cause is that `fopts.use_mmap_reads` is false, `NewRandomAccessFile` will produce an `PosixRandomAccessFile` file. but `soptions_.use_mmap_reads` is true, This will result in unexpected calls in the `MmapDataIfNeeded` function. ```c++ Status SstFileDumper::GetTableReader(const std::string& file_path) { ... if (s.ok()) { if (magic_number == kPlainTableMagicNumber || magic_number == kLegacyPlainTableMagicNumber || magic_number == kCuckooTableMagicNumber) { soptions_.use_mmap_reads = true; ... // WARN: fopts.use_mmap_reads is false fs->NewRandomAccessFile(file_path, fopts, &file, nullptr); file_.reset(new RandomAccessFileReader(std::move(file), file_path)); } ... } if (s.ok()) { // soptions_.use_mmap_reads is true s = NewTableReader(ioptions_, soptions_, internal_comparator_, file_size, &table_reader_); } return s; } ``` The following read logic was executed on a `PosixRandomAccessFile` file, Eventually, `PosixRandomAccessFile::Read` will be called with a `nullptr` `scratch` ```c++ Status PlainTableReader::MmapDataIfNeeded() { if (file_info_.is_mmap_mode) { // Get mmapped memory. // Executing the following logic on the PosixRandomAccessFile file is incorrect return file_info_.file->Read( IOOptions(), 0, static_cast<size_t>(file_size_), &file_info_.file_data, nullptr, nullptr, Env::IO_TOTAL /* rate_limiter_priority */); } return Status::OK(); } ``` #### Fix: When parsing PlainTable, set the variable `fopts.use_mmap_reads` equal `soptions_.use_mmap_reads`, When the `soptions_.use_mmap_reads` is true, `NewRandomAccessFile` will produce an `PosixMmapReadableFile` file. This will work correctly in the `MmapDataIfNeeded` function ``` ❯ ./sst_dump --file=/tmp/write_example --command=scan --show_properties --verify_checksum options.env is 0x6000009323e0 Process /tmp/write_example/001630.sst Sst file format: plain table from [] to [] 'keys496' seq:0, type:1 => values1496 'keys497' seq:0, type:1 => values1497 'keys498' seq:0, type:1 => values1498 Table Properties: ------------------------------ # data blocks: 1 # entries: 3 # deletions: 0 # merge operands: 0 # range deletions: 0 raw key size: 45 raw average key size: 15.000000 raw value size: 42 ``` Pull Request resolved: https://github.com/facebook/rocksdb/pull/12223 Reviewed By: cbi42 Differential Revision: D52706238 Pulled By: ajkr fbshipit-source-id: 2f9f518ec81d1cbde00bd65ab6bd304796836c0a |
||
---|---|---|
.. | ||
adaptive | ||
block_based | ||
cuckoo | ||
plain | ||
block_fetcher.cc | ||
block_fetcher.h | ||
block_fetcher_test.cc | ||
cleanable_test.cc | ||
compaction_merging_iterator.cc | ||
compaction_merging_iterator.h | ||
format.cc | ||
format.h | ||
get_context.cc | ||
get_context.h | ||
internal_iterator.h | ||
iter_heap.h | ||
iterator.cc | ||
iterator_wrapper.h | ||
merger_test.cc | ||
merging_iterator.cc | ||
merging_iterator.h | ||
meta_blocks.cc | ||
meta_blocks.h | ||
mock_table.cc | ||
mock_table.h | ||
multiget_context.h | ||
persistent_cache_helper.cc | ||
persistent_cache_helper.h | ||
persistent_cache_options.h | ||
scoped_arena_iterator.h | ||
sst_file_dumper.cc | ||
sst_file_dumper.h | ||
sst_file_reader.cc | ||
sst_file_reader_test.cc | ||
sst_file_writer.cc | ||
sst_file_writer_collectors.h | ||
table_builder.h | ||
table_factory.cc | ||
table_properties.cc | ||
table_properties_internal.h | ||
table_reader.h | ||
table_reader_bench.cc | ||
table_test.cc | ||
two_level_iterator.cc | ||
two_level_iterator.h | ||
unique_id.cc | ||
unique_id_impl.h |