@ -8702,8 +8702,9 @@ TEST(DBTest, DynamicCompactionOptions) {
dbfull ( ) - > TEST_WaitForFlushMemTable ( ) ;
} ;
// Write 3 files that have the same key range, trigger compaction and
// result in one L1 file
// Write 3 files that have the same key range.
// Since level0_file_num_compaction_trigger is 3, compaction should be
// triggered. The compaction should result in one L1 file
gen_l0_kb ( 0 , 64 , 1 ) ;
ASSERT_EQ ( NumTableFilesAtLevel ( 0 ) , 1 ) ;
gen_l0_kb ( 0 , 64 , 1 ) ;
@ -8718,6 +8719,10 @@ TEST(DBTest, DynamicCompactionOptions) {
ASSERT_GE ( metadata [ 0 ] . size , k64KB - k4KB ) ;
// Test compaction trigger and target_file_size_base
// Reduce compaction trigger to 2, and reduce L1 file size to 32KB.
// Writing to 64KB L0 files should trigger a compaction. Since these
// 2 L0 files have the same key range, compaction merge them and should
// result in 2 32KB L1 files.
ASSERT_TRUE ( dbfull ( ) - > SetOptions ( {
{ " level0_file_num_compaction_trigger " , " 2 " } ,
{ " target_file_size_base " , std : : to_string ( k32KB ) }
@ -8733,8 +8738,13 @@ TEST(DBTest, DynamicCompactionOptions) {
ASSERT_EQ ( 2U , metadata . size ( ) ) ;
ASSERT_LE ( metadata [ 0 ] . size , k32KB + k4KB ) ;
ASSERT_GE ( metadata [ 0 ] . size , k32KB - k4KB ) ;
ASSERT_LE ( metadata [ 1 ] . size , k32KB + k4KB ) ;
ASSERT_GE ( metadata [ 1 ] . size , k32KB - k4KB ) ;
// Test max_bytes_for_level_base
// Increase level base size to 256KB and write enough data that will
// fill L1 and L2. L1 size should be around 256KB while L2 size should be
// around 256KB x 4.
ASSERT_TRUE ( dbfull ( ) - > SetOptions ( {
{ " max_bytes_for_level_base " , std : : to_string ( k256KB ) }
} ) ) ;
@ -8751,7 +8761,9 @@ TEST(DBTest, DynamicCompactionOptions) {
SizeAtLevel ( 2 ) < 4 * k256KB * 1.2 ) ;
// Test max_bytes_for_level_multiplier and
// max_bytes_for_level_base (reduce)
// max_bytes_for_level_base. Now, reduce both mulitplier and level base,
// After filling enough data that can fit in L1 - L3, we should see L1 size
// reduces to 128KB from 256KB which was asserted previously. Same for L2.
ASSERT_TRUE ( dbfull ( ) - > SetOptions ( {
{ " max_bytes_for_level_multiplier " , " 2 " } ,
{ " max_bytes_for_level_base " , std : : to_string ( k128KB ) }
@ -8767,7 +8779,10 @@ TEST(DBTest, DynamicCompactionOptions) {
ASSERT_TRUE ( SizeAtLevel ( 2 ) < 2 * k128KB * 1.2 ) ;
ASSERT_TRUE ( SizeAtLevel ( 3 ) < 4 * k128KB * 1.2 ) ;
// Clean up memtable and L0
// Test level0_stop_writes_trigger.
// Clean up memtable and L0. Block compaction threads. If continue to write
// and flush memtables. We should see put timeout after 8 memtable flushes
// since level0_stop_writes_trigger = 8
dbfull ( ) - > CompactRange ( nullptr , nullptr ) ;
// Block compaction
SleepingBackgroundTask sleeping_task_low1 ;
@ -8788,7 +8803,9 @@ TEST(DBTest, DynamicCompactionOptions) {
sleeping_task_low1 . WakeUp ( ) ;
sleeping_task_low1 . WaitUntilDone ( ) ;
// Test: stop trigger (reduce)
// Now reduce level0_stop_writes_trigger to 6. Clear up memtables and L0.
// Block compaction thread again. Perform the put and memtable flushes
// until we see timeout after 6 memtable flushes.
ASSERT_TRUE ( dbfull ( ) - > SetOptions ( {
{ " level0_stop_writes_trigger " , " 6 " }
} ) ) ;
@ -8810,6 +8827,10 @@ TEST(DBTest, DynamicCompactionOptions) {
sleeping_task_low2 . WaitUntilDone ( ) ;
// Test disable_auto_compactions
// Compaction thread is unblocked but auto compaction is disabled. Write
// 4 L0 files and compaction should be triggered. If auto compaction is
// disabled, then TEST_WaitForCompact will be waiting for nothing. Number of
// L0 files do not change after the call.
ASSERT_TRUE ( dbfull ( ) - > SetOptions ( {
{ " disable_auto_compactions " , " true " }
} ) ) ;
@ -8824,6 +8845,8 @@ TEST(DBTest, DynamicCompactionOptions) {
dbfull ( ) - > TEST_WaitForCompact ( ) ;
ASSERT_EQ ( NumTableFilesAtLevel ( 0 ) , 4 ) ;
// Enable auto compaction and perform the same test, # of L0 files should be
// reduced after compaction.
ASSERT_TRUE ( dbfull ( ) - > SetOptions ( {
{ " disable_auto_compactions " , " false " }
} ) ) ;
@ -8838,8 +8861,10 @@ TEST(DBTest, DynamicCompactionOptions) {
dbfull ( ) - > TEST_WaitForCompact ( ) ;
ASSERT_LT ( NumTableFilesAtLevel ( 0 ) , 4 ) ;
// Test for hard_rate_limit, change max_bytes_for_level_base to make level
// size big
// Test for hard_rate_limit.
// First change max_bytes_for_level_base to a big value and populate
// L1 - L3. Then thrink max_bytes_for_level_base and disable auto compaction
// at the same time, we should see some level with score greater than 2.
ASSERT_TRUE ( dbfull ( ) - > SetOptions ( {
{ " max_bytes_for_level_base " , std : : to_string ( k256KB ) }
} ) ) ;
@ -8869,7 +8894,9 @@ TEST(DBTest, DynamicCompactionOptions) {
SizeAtLevel ( 2 ) / k64KB > 4 | |
SizeAtLevel ( 3 ) / k64KB > 8 ) ;
// Enfoce hard rate limit, L0 score is not regulated by this limit
// Enfoce hard rate limit. Now set hard_rate_limit to 2,
// we should start to see put delay (1000 us) and timeout as a result
// (L0 score is not regulated by this limit).
ASSERT_TRUE ( dbfull ( ) - > SetOptions ( {
{ " hard_rate_limit " , " 2 " }
} ) ) ;
@ -8881,7 +8908,7 @@ TEST(DBTest, DynamicCompactionOptions) {
wo . timeout_hint_us = 500 ;
ASSERT_TRUE ( Put ( Key ( count ) , RandomString ( & rnd , 1024 ) , wo ) . IsTimedOut ( ) ) ;
// Bump up limi t
// Lift the limit and no timeou t
ASSERT_TRUE ( dbfull ( ) - > SetOptions ( {
{ " hard_rate_limit " , " 100 " }
} ) ) ;