@ -11175,6 +11175,85 @@ TEST_F(DBTest, DynamicLevelMaxBytesBase2) {
ASSERT_EQ ( 1U , int_prop ) ;
}
// Test specific cases in dynamic max bytes
TEST_F ( DBTest , DynamicLevelMaxBytesCompactRange ) {
Random rnd ( 301 ) ;
int kMaxKey = 1000000 ;
Options options = CurrentOptions ( ) ;
options . create_if_missing = true ;
options . db_write_buffer_size = 2048 ;
options . write_buffer_size = 2048 ;
options . max_write_buffer_number = 2 ;
options . level0_file_num_compaction_trigger = 2 ;
options . level0_slowdown_writes_trigger = 9999 ;
options . level0_stop_writes_trigger = 9999 ;
options . target_file_size_base = 2 ;
options . level_compaction_dynamic_level_bytes = true ;
options . max_bytes_for_level_base = 10240 ;
options . max_bytes_for_level_multiplier = 4 ;
options . max_background_compactions = 1 ;
const int kNumLevels = 5 ;
options . num_levels = kNumLevels ;
options . expanded_compaction_factor = 0 ; // Force not expanding in compactions
BlockBasedTableOptions table_options ;
table_options . block_size = 1024 ;
options . table_factory . reset ( NewBlockBasedTableFactory ( table_options ) ) ;
DestroyAndReopen ( options ) ;
// Compact against empty DB
dbfull ( ) - > CompactRange ( nullptr , nullptr ) ;
uint64_t int_prop ;
std : : string str_prop ;
// Initial base level is the last level
ASSERT_TRUE ( db_ - > GetIntProperty ( " rocksdb.base-level " , & int_prop ) ) ;
ASSERT_EQ ( 4U , int_prop ) ;
// Put about 7K to L0
for ( int i = 0 ; i < 140 ; i + + ) {
ASSERT_OK ( Put ( Key ( static_cast < int > ( rnd . Uniform ( kMaxKey ) ) ) ,
RandomString ( & rnd , 80 ) ) ) ;
}
Flush ( ) ;
dbfull ( ) - > TEST_WaitForCompact ( ) ;
ASSERT_OK (
Put ( Key ( static_cast < int > ( rnd . Uniform ( kMaxKey ) ) ) , RandomString ( & rnd , 80 ) ) ) ;
Flush ( ) ;
ASSERT_TRUE ( db_ - > GetIntProperty ( " rocksdb.base-level " , & int_prop ) ) ;
ASSERT_EQ ( 3U , int_prop ) ;
ASSERT_TRUE ( db_ - > GetProperty ( " rocksdb.num-files-at-level1 " , & str_prop ) ) ;
ASSERT_EQ ( " 0 " , str_prop ) ;
ASSERT_TRUE ( db_ - > GetProperty ( " rocksdb.num-files-at-level2 " , & str_prop ) ) ;
ASSERT_EQ ( " 0 " , str_prop ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > DisableProcessing ( ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > ClearAllCallBacks ( ) ;
std : : set < int > output_levels ;
rocksdb : : SyncPoint : : GetInstance ( ) - > SetCallBack (
" CompactionPicker::CompactRange:Return " , [ & ] ( void * arg ) {
Compaction * compaction = reinterpret_cast < Compaction * > ( arg ) ;
output_levels . insert ( compaction - > output_level ( ) ) ;
} ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > EnableProcessing ( ) ;
dbfull ( ) - > CompactRange ( nullptr , nullptr ) ;
ASSERT_EQ ( output_levels . size ( ) , 2 ) ;
ASSERT_TRUE ( output_levels . find ( 3 ) ! = output_levels . end ( ) ) ;
ASSERT_TRUE ( output_levels . find ( 4 ) ! = output_levels . end ( ) ) ;
ASSERT_TRUE ( db_ - > GetProperty ( " rocksdb.num-files-at-level0 " , & str_prop ) ) ;
ASSERT_EQ ( " 0 " , str_prop ) ;
ASSERT_TRUE ( db_ - > GetProperty ( " rocksdb.num-files-at-level3 " , & str_prop ) ) ;
ASSERT_EQ ( " 0 " , str_prop ) ;
// Base level is still level 3.
ASSERT_TRUE ( db_ - > GetIntProperty ( " rocksdb.base-level " , & int_prop ) ) ;
ASSERT_EQ ( 3U , int_prop ) ;
}
TEST_F ( DBTest , DynamicLevelMaxBytesBaseInc ) {
Options options = CurrentOptions ( ) ;
options . create_if_missing = true ;