From b92bc04ab000d4e4d64605ca8123f41940d4a5e7 Mon Sep 17 00:00:00 2001 From: sdong Date: Tue, 21 Mar 2023 15:38:33 -0700 Subject: [PATCH] Deflake DBCompactionTest.CancelCompactionWaitingOnConflict (#11318) Summary: In DBCompactionTest::CancelCompactionWaitingOnConflict, when generating SST files to trigger a compaction, we don't wait after each file, which may cause multiple memtables going to the same SST file, causing insufficient files to trigger the compaction. We do the waiting instead, except the last one, which would trigger compaction. Pull Request resolved: https://github.com/facebook/rocksdb/pull/11318 Test Plan: Run DBCompactionTest.CancelCompactionWaitingOnConflict multiple times. Reviewed By: ajkr Differential Revision: D44267273 fbshipit-source-id: 86af49b05fc67ea3335312f0f5f3d22df1520bf8 --- db/db_compaction_test.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/db/db_compaction_test.cc b/db/db_compaction_test.cc index 55852aacd..96b579c24 100644 --- a/db/db_compaction_test.cc +++ b/db/db_compaction_test.cc @@ -3613,7 +3613,10 @@ TEST_F(DBCompactionTest, CancelCompactionWaitingOnConflict) { Random rnd(301); for (int i = 0; i < kNumSortedRuns; ++i) { int key_idx = 0; - GenerateNewFile(&rnd, &key_idx, true /* nowait */); + // We hold the compaction from happening, so when generating the last SST + // file, we cannot wait. Otherwise, we'll hit a deadlock. + GenerateNewFile(&rnd, &key_idx, + (i == kNumSortedRuns - 1) ? true : false /* nowait */); } auto_compaction_sleeping_task.WaitUntilSleeping();