Skip to content

Commit d72cceb

Browse files
committed
Fix VerifyChecksum readahead with mmap mode (facebook#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: facebook#5945 Test Plan: Add a unit test that used to fail. Differential Revision: D18021443 fbshipit-source-id: 6f2eb600f81b26edb02222563a4006869d576bff
1 parent 1d5083a commit d72cceb

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

db/corruption_test.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,13 @@ TEST_F(CorruptionTest, VerifyChecksumReadahead) {
369369
ASSERT_GE(senv.random_read_counter_.Read(), 213);
370370
ASSERT_LE(senv.random_read_counter_.Read(), 447);
371371

372+
// Test readahead shouldn't break mmap mode (where it should be
373+
// disabled).
374+
options.allow_mmap_reads = true;
375+
Reopen(&options);
376+
dbi = static_cast<DBImpl*>(db_);
377+
ASSERT_OK(dbi->VerifyChecksum(ro));
378+
372379
CloseDb();
373380
}
374381

table/block_based/block_based_table_reader.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3746,8 +3746,12 @@ Status BlockBasedTable::VerifyChecksumInBlocks(
37463746
size_t readahead_size = (read_options.readahead_size != 0)
37473747
? read_options.readahead_size
37483748
: kMaxAutoReadaheadSize;
3749-
FilePrefetchBuffer prefetch_buffer(rep_->file.get(), readahead_size,
3750-
readahead_size);
3749+
// FilePrefetchBuffer doesn't work in mmap mode and readahead is not
3750+
// needed there.
3751+
FilePrefetchBuffer prefetch_buffer(
3752+
rep_->file.get(), readahead_size /* readadhead_size */,
3753+
readahead_size /* max_readahead_size */,
3754+
!rep_->ioptions.allow_mmap_reads /* enable */);
37513755

37523756
for (index_iter->SeekToFirst(); index_iter->Valid(); index_iter->Next()) {
37533757
s = index_iter->status();

0 commit comments

Comments
 (0)