From d72cceb443f02e5343b43a26de86676ee7a1d468 Mon Sep 17 00:00:00 2001 From: sdong Date: Mon, 21 Oct 2019 11:37:09 -0700 Subject: [PATCH] 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 --- db/corruption_test.cc | 7 +++++++ table/block_based/block_based_table_reader.cc | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/db/corruption_test.cc b/db/corruption_test.cc index 3fd85953d..4add9b26a 100644 --- a/db/corruption_test.cc +++ b/db/corruption_test.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(db_); + ASSERT_OK(dbi->VerifyChecksum(ro)); + CloseDb(); } diff --git a/table/block_based/block_based_table_reader.cc b/table/block_based/block_based_table_reader.cc index be06c74da..b0971cf72 100644 --- a/table/block_based/block_based_table_reader.cc +++ b/table/block_based/block_based_table_reader.cc @@ -3746,8 +3746,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();