@@ -76,7 +76,7 @@ class CompactionStatsCollector : public EventListener {
76
76
class DBCompactionTest : public DBTestBase {
77
77
public:
78
78
DBCompactionTest()
79
- : DBTestBase("db_compaction_test", /*env_do_fsync=*/true ) {}
79
+ : DBTestBase("db_compaction_test", /*env_do_fsync=*/false ) {}
80
80
81
81
protected:
82
82
/*
@@ -121,7 +121,7 @@ class DBCompactionTestWithParam
121
121
public testing::WithParamInterface<std::tuple<uint32_t, bool>> {
122
122
public:
123
123
DBCompactionTestWithParam()
124
- : DBTestBase("db_compaction_test", /*env_do_fsync=*/true ) {
124
+ : DBTestBase("db_compaction_test", /*env_do_fsync=*/false ) {
125
125
max_subcompactions_ = std::get<0>(GetParam());
126
126
exclusive_manual_compaction_ = std::get<1>(GetParam());
127
127
}
@@ -140,7 +140,7 @@ class DBCompactionTestWithBottommostParam
140
140
std::tuple<BottommostLevelCompaction, bool>> {
141
141
public:
142
142
DBCompactionTestWithBottommostParam()
143
- : DBTestBase("db_compaction_test", /*env_do_fsync=*/true ) {
143
+ : DBTestBase("db_compaction_test", /*env_do_fsync=*/false ) {
144
144
bottommost_level_compaction_ = std::get<0>(GetParam());
145
145
}
146
146
@@ -160,7 +160,7 @@ class DBCompactionWaitForCompactTest
160
160
std::tuple<bool, bool, bool, std::chrono::microseconds>> {
161
161
public:
162
162
DBCompactionWaitForCompactTest()
163
- : DBTestBase("db_compaction_test", /*env_do_fsync=*/true ) {
163
+ : DBTestBase("db_compaction_test", /*env_do_fsync=*/false ) {
164
164
abort_on_pause_ = std::get<0>(GetParam());
165
165
flush_ = std::get<1>(GetParam());
166
166
close_db_ = std::get<2>(GetParam());
@@ -845,6 +845,20 @@ TEST_F(DBCompactionTest, BGCompactionsAllowed) {
845
845
options.memtable_factory.reset(
846
846
test::NewSpecialSkipListFactory(kNumKeysPerFile));
847
847
848
+ CreateAndReopenWithCF({"one", "two", "three"}, options);
849
+
850
+ Random rnd(301);
851
+ for (int cf = 0; cf < 4; cf++) {
852
+ // Make a trivial L1 for L0 to compact into. L2 will be large so debt ratio
853
+ // will not cause compaction pressure.
854
+ ASSERT_OK(Put(cf, Key(0), rnd.RandomString(102400)));
855
+ ASSERT_OK(Flush(cf));
856
+ MoveFilesToLevel(2, cf);
857
+ ASSERT_OK(Put(cf, Key(0), ""));
858
+ ASSERT_OK(Flush(cf));
859
+ MoveFilesToLevel(1, cf);
860
+ }
861
+
848
862
// Block all threads in thread pool.
849
863
const size_t kTotalTasks = 4;
850
864
env_->SetBackgroundThreads(4, Env::LOW);
@@ -855,9 +869,6 @@ TEST_F(DBCompactionTest, BGCompactionsAllowed) {
855
869
sleeping_tasks[i].WaitUntilSleeping();
856
870
}
857
871
858
- CreateAndReopenWithCF({"one", "two", "three"}, options);
859
-
860
- Random rnd(301);
861
872
for (int cf = 0; cf < 4; cf++) {
862
873
for (int num = 0; num < options.level0_file_num_compaction_trigger; num++) {
863
874
for (int i = 0; i < kNumKeysPerFile; i++) {
@@ -6150,7 +6161,7 @@ class CompactionPriTest : public DBTestBase,
6150
6161
public testing::WithParamInterface<uint32_t> {
6151
6162
public:
6152
6163
CompactionPriTest()
6153
- : DBTestBase("compaction_pri_test", /*env_do_fsync=*/true ) {
6164
+ : DBTestBase("compaction_pri_test", /*env_do_fsync=*/false ) {
6154
6165
compaction_pri_ = GetParam();
6155
6166
}
6156
6167
@@ -6270,26 +6281,30 @@ TEST_F(DBCompactionTest, PersistRoundRobinCompactCursor) {
6270
6281
6271
6282
TEST_P(RoundRobinSubcompactionsAgainstPressureToken, PressureTokenTest) {
6272
6283
const int kKeysPerBuffer = 100;
6284
+ const int kNumSubcompactions = 2;
6285
+ const int kFilesPerLevel = 50;
6273
6286
Options options = CurrentOptions();
6274
- options.num_levels = 4 ;
6287
+ options.num_levels = 3 ;
6275
6288
options.max_bytes_for_level_multiplier = 2;
6276
6289
options.level0_file_num_compaction_trigger = 4;
6277
6290
options.target_file_size_base = kKeysPerBuffer * 1024;
6278
6291
options.compaction_pri = CompactionPri::kRoundRobin;
6279
- options.max_bytes_for_level_base = 8 * kKeysPerBuffer * 1024;
6292
+ // Target size is chosen so that filling the level with `kFilesPerLevel` files
6293
+ // will make it oversized by `kNumSubcompactions` files.
6294
+ options.max_bytes_for_level_base =
6295
+ (kFilesPerLevel - kNumSubcompactions) * kKeysPerBuffer * 1024;
6280
6296
options.disable_auto_compactions = true;
6281
- // Setup 7 threads but limited subcompactions so that
6282
- // RoundRobin requires extra compactions from reserved threads
6297
+ // Setup `kNumSubcompactions` threads but limited subcompactions so
6298
+ // that RoundRobin requires extra compactions from reserved threads
6283
6299
options.max_subcompactions = 1;
6284
- options.max_background_compactions = 7 ;
6300
+ options.max_background_compactions = kNumSubcompactions ;
6285
6301
options.max_compaction_bytes = 100000000;
6286
6302
DestroyAndReopen(options);
6287
- env_->SetBackgroundThreads(7 , Env::LOW);
6303
+ env_->SetBackgroundThreads(kNumSubcompactions , Env::LOW);
6288
6304
6289
6305
Random rnd(301);
6290
- const std::vector<int> files_per_level = {0, 15, 25};
6291
6306
for (int lvl = 2; lvl > 0; lvl--) {
6292
- for (int i = 0; i < files_per_level[lvl] ; i++) {
6307
+ for (int i = 0; i < kFilesPerLevel ; i++) {
6293
6308
for (int j = 0; j < kKeysPerBuffer; j++) {
6294
6309
// Add (lvl-1) to ensure nearly equivallent number of files
6295
6310
// in L2 are overlapped with fils selected to compact from
@@ -6300,9 +6315,8 @@ TEST_P(RoundRobinSubcompactionsAgainstPressureToken, PressureTokenTest) {
6300
6315
ASSERT_OK(Flush());
6301
6316
}
6302
6317
MoveFilesToLevel(lvl);
6303
- ASSERT_EQ(files_per_level[lvl] , NumTableFilesAtLevel(lvl, 0));
6318
+ ASSERT_EQ(kFilesPerLevel , NumTableFilesAtLevel(lvl, 0));
6304
6319
}
6305
- // 15 files in L1; 25 files in L2
6306
6320
6307
6321
// This is a variable for making sure the following callback is called
6308
6322
// and the assertions in it are indeed excuted.
@@ -6311,10 +6325,10 @@ TEST_P(RoundRobinSubcompactionsAgainstPressureToken, PressureTokenTest) {
6311
6325
"CompactionJob::GenSubcompactionBoundaries:0", [&](void* arg) {
6312
6326
uint64_t num_planned_subcompactions = *(static_cast<uint64_t*>(arg));
6313
6327
if (grab_pressure_token_) {
6314
- // 7 files are selected for round-robin under auto
6328
+ // `kNumSubcompactions` files are selected for round-robin under auto
6315
6329
// compaction. The number of planned subcompaction is restricted by
6316
6330
// the limited number of max_background_compactions
6317
- ASSERT_EQ(num_planned_subcompactions, 7 );
6331
+ ASSERT_EQ(num_planned_subcompactions, kNumSubcompactions );
6318
6332
} else {
6319
6333
ASSERT_EQ(num_planned_subcompactions, 1);
6320
6334
}
0 commit comments