Skip to content

Commit d2db80c

Browse files
cbi42facebook-github-bot
authored andcommitted
Try to deflake unit test RoundRobinSubcompactionsAgainstPressureToken (#13254)
Summary: unit test `RoundRobinSubcompactionsAgainstPressureToken.PressureTokenTest` has been [flaky](https://github.com/facebook/rocksdb/actions/runs/12220443012/job/34088263578?fbclid=IwZXh0bgNhZW0CMTEAAR3Vi0p8xxzU1tSpvaeB0RfP_97nOMiONGyZbhdcnN8IXW4tChNVHN3iIhc_aem_SGy-iqplt0GaEHAel_BGQQ). num_planned_subcompactions can be 1 for two reasons: compactions not having enough input files or that there were not enough bg threads. This PR updates the test to try to trigger a larger compaction for subcompactions, and added a callback to verify compactions have enough input files. Pull Request resolved: #13254 Test Plan: monitor future failure. Reviewed By: hx235 Differential Revision: D67764944 Pulled By: cbi42 fbshipit-source-id: 4fc9c0bef76c8bfaa54be4f3d78071e2bebee8aa
1 parent 00a3eb6 commit d2db80c

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

db/db_compaction_test.cc

+28-12
Original file line numberDiff line numberDiff line change
@@ -6417,10 +6417,13 @@ TEST_P(RoundRobinSubcompactionsAgainstPressureToken, PressureTokenTest) {
64176417
options.level0_file_num_compaction_trigger = 4;
64186418
options.target_file_size_base = kKeysPerBuffer * 1024;
64196419
options.compaction_pri = CompactionPri::kRoundRobin;
6420-
// Target size is chosen so that filling the level with `kFilesPerLevel` files
6421-
// will make it oversized by `kNumSubcompactions` files.
6420+
// Pick a small target level size so that round-robin compaction will pick
6421+
// more files to compact and trigger subcompactions. Actual number of
6422+
// subcompactions will be limited by number of bg threads available.
6423+
// Cannot be too small to cause compaction pressure. See
6424+
// GetPendingCompactionBytesForCompactionSpeedup().
64226425
options.max_bytes_for_level_base =
6423-
(kFilesPerLevel - kNumSubcompactions) * kKeysPerBuffer * 1024;
6426+
(kFilesPerLevel - 10) * kKeysPerBuffer * 1024;
64246427
options.disable_auto_compactions = true;
64256428
// Setup `kNumSubcompactions` threads but limited subcompactions so
64266429
// that RoundRobin requires extra compactions from reserved threads
@@ -6446,21 +6449,34 @@ TEST_P(RoundRobinSubcompactionsAgainstPressureToken, PressureTokenTest) {
64466449
ASSERT_EQ(kFilesPerLevel, NumTableFilesAtLevel(lvl, 0));
64476450
}
64486451

6452+
bool compaction_num_input_file_verified = false;
6453+
SyncPoint::GetInstance()->SetCallBack(
6454+
"LevelCompactionPicker::PickCompaction:Return", [&](void* arg) {
6455+
if (!compaction_num_input_file_verified) {
6456+
Compaction* compaction = static_cast<Compaction*>(arg);
6457+
// In Round-Robin, # of subcompactions needed is the # of input files
6458+
ASSERT_GT(compaction->num_input_files(0), 1);
6459+
compaction_num_input_file_verified = true;
6460+
}
6461+
});
6462+
64496463
// This is a variable for making sure the following callback is called
64506464
// and the assertions in it are indeed excuted.
64516465
bool num_planned_subcompactions_verified = false;
64526466
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
64536467
"CompactionJob::GenSubcompactionBoundaries:0", [&](void* arg) {
6454-
uint64_t num_planned_subcompactions = *(static_cast<uint64_t*>(arg));
6455-
if (grab_pressure_token_) {
6456-
// `kNumSubcompactions` files are selected for round-robin under auto
6457-
// compaction. The number of planned subcompaction is restricted by
6458-
// the limited number of max_background_compactions
6459-
ASSERT_EQ(num_planned_subcompactions, kNumSubcompactions);
6460-
} else {
6461-
ASSERT_EQ(num_planned_subcompactions, 1);
6468+
if (!num_planned_subcompactions_verified) {
6469+
uint64_t num_planned_subcompactions = *(static_cast<uint64_t*>(arg));
6470+
if (grab_pressure_token_) {
6471+
// `kNumSubcompactions` files are selected for round-robin under
6472+
// auto compaction. The number of planned subcompaction is
6473+
// restricted by the limited number of max_background_compactions
6474+
ASSERT_EQ(num_planned_subcompactions, kNumSubcompactions);
6475+
} else {
6476+
ASSERT_EQ(num_planned_subcompactions, 1);
6477+
}
6478+
num_planned_subcompactions_verified = true;
64626479
}
6463-
num_planned_subcompactions_verified = true;
64646480
});
64656481

64666482
// The following 3 dependencies have to be added to ensure the auto

0 commit comments

Comments
 (0)