From fe5fbe32cb56c5c0990b843572112e963e17af5f Mon Sep 17 00:00:00 2001 From: Andrew Kryczka Date: Sun, 4 Sep 2022 14:55:09 -0700 Subject: [PATCH] Deflake DBBlockCacheTest1.WarmCacheWithBlocksDuringFlush (#10635) Summary: Previously, automatic compaction could be triggered prior to the test invoking CompactRange(). It could lead to the following flaky failure: ``` /root/project/db/db_block_cache_test.cc:753: Failure Expected equality of these values: 1 + kNumBlocks Which is: 11 options.statistics->getTickerCount(BLOCK_CACHE_INDEX_ADD) Which is: 10 ``` A sequence leading to this failure was: * Automatic compaction * files [1] [2] trivially moved * files [3] [4] [5] [6] trivially moved * CompactRange() * files [7] [8] [9] trivially moved * file [10] trivially moved In such a case, the index/filter block adds that the test expected did not happen since there were no new files. This PR just tweaks settings to ensure the `CompactRange()` produces one new file. Pull Request resolved: https://github.com/facebook/rocksdb/pull/10635 Reviewed By: cbi42 Differential Revision: D39250869 Pulled By: ajkr fbshipit-source-id: a3c94c49069e28c49c40b4b80dae0059739d19fd --- db/db_block_cache_test.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/db/db_block_cache_test.cc b/db/db_block_cache_test.cc index 5e549ab6a5..df03695d4d 100644 --- a/db/db_block_cache_test.cc +++ b/db/db_block_cache_test.cc @@ -678,8 +678,8 @@ INSTANTIATE_TEST_CASE_P(DBBlockCacheTest1, DBBlockCacheTest1, TEST_P(DBBlockCacheTest1, WarmCacheWithBlocksDuringFlush) { Options options = CurrentOptions(); options.create_if_missing = true; + options.disable_auto_compactions = true; options.statistics = ROCKSDB_NAMESPACE::CreateDBStatistics(); - options.max_compaction_bytes = 2000; BlockBasedTableOptions table_options; table_options.block_cache = NewLRUCache(1 << 25, 0, false); @@ -737,8 +737,10 @@ TEST_P(DBBlockCacheTest1, WarmCacheWithBlocksDuringFlush) { } // Verify compaction not counted - ASSERT_OK(db_->CompactRange(CompactRangeOptions(), /*begin=*/nullptr, - /*end=*/nullptr)); + CompactRangeOptions cro; + // Ensure files are rewritten, not just trivially moved. + cro.bottommost_level_compaction = BottommostLevelCompaction::kForceOptimized; + ASSERT_OK(db_->CompactRange(cro, /*begin=*/nullptr, /*end=*/nullptr)); EXPECT_EQ(kNumBlocks, options.statistics->getTickerCount(BLOCK_CACHE_DATA_ADD)); // Index and filter blocks are automatically warmed when the new table file