Fix VerifyChecksum readahead with mmap mode (#5945)

Summary:
A recent change introduced readahead inside VerifyChecksum(). However it is not compatible with mmap mode and generated wrong checksum verification failure. Fix it by not enabling readahead in mmap
 mode.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5945

Test Plan: Add a unit test that used to fail.

Differential Revision: D18021443

fbshipit-source-id: 6f2eb600f81b26edb02222563a4006869d576bff
main
sdong 5 years ago committed by Facebook Github Bot
parent 1a21afa789
commit 30e2dc02f0
  1. 7
      db/corruption_test.cc
  2. 8
      table/block_based/block_based_table_reader.cc

@ -369,6 +369,13 @@ TEST_F(CorruptionTest, VerifyChecksumReadahead) {
ASSERT_GE(senv.random_read_counter_.Read(), 213);
ASSERT_LE(senv.random_read_counter_.Read(), 447);
// Test readahead shouldn't break mmap mode (where it should be
// disabled).
options.allow_mmap_reads = true;
Reopen(&options);
dbi = static_cast<DBImpl*>(db_);
ASSERT_OK(dbi->VerifyChecksum(ro));
CloseDb();
}

@ -3781,8 +3781,12 @@ Status BlockBasedTable::VerifyChecksumInBlocks(
size_t readahead_size = (read_options.readahead_size != 0)
? read_options.readahead_size
: kMaxAutoReadaheadSize;
FilePrefetchBuffer prefetch_buffer(rep_->file.get(), readahead_size,
readahead_size);
// FilePrefetchBuffer doesn't work in mmap mode and readahead is not
// needed there.
FilePrefetchBuffer prefetch_buffer(
rep_->file.get(), readahead_size /* readadhead_size */,
readahead_size /* max_readahead_size */,
!rep_->ioptions.allow_mmap_reads /* enable */);
for (index_iter->SeekToFirst(); index_iter->Valid(); index_iter->Next()) {
s = index_iter->status();

Loading…
Cancel
Save