@ -580,6 +580,101 @@ TEST_F(CompactionPickerTest, OverlappingUserKeys3) {
ASSERT_EQ ( 7U , compaction - > input ( 1 , 1 ) - > fd . GetNumber ( ) ) ;
}
TEST_F ( CompactionPickerTest , NotScheduleL1IfL0WithHigherPri1 ) {
NewVersionStorage ( 6 , kCompactionStyleLevel ) ;
mutable_cf_options_ . level0_file_num_compaction_trigger = 2 ;
mutable_cf_options_ . max_bytes_for_level_base = 900000000U ;
// 6 L0 files, score 3.
Add ( 0 , 1U , " 000 " , " 400 " , 1U ) ;
Add ( 0 , 2U , " 001 " , " 400 " , 1U , 0 , 0 ) ;
Add ( 0 , 3U , " 001 " , " 400 " , 1000000000U , 0 , 0 ) ;
Add ( 0 , 31U , " 001 " , " 400 " , 1000000000U , 0 , 0 ) ;
Add ( 0 , 32U , " 001 " , " 400 " , 1000000000U , 0 , 0 ) ;
Add ( 0 , 33U , " 001 " , " 400 " , 1000000000U , 0 , 0 ) ;
// L1 total size 2GB, score 2.2. If one file being comapcted, score 1.1.
Add ( 1 , 4U , " 050 " , " 300 " , 1000000000U , 0 , 0 ) ;
file_map_ [ 4u ] . first - > being_compacted = true ;
Add ( 1 , 5U , " 301 " , " 350 " , 1000000000U , 0 , 0 ) ;
// Output level overlaps with the beginning and the end of the chain
Add ( 2 , 6U , " 050 " , " 100 " , 1U ) ;
Add ( 2 , 7U , " 300 " , " 400 " , 1U ) ;
// No compaction should be scheduled, if L0 has higher priority than L1
// but L0->L1 compaction is blocked by a file in L1 being compacted.
UpdateVersionStorageInfo ( ) ;
ASSERT_EQ ( 0 , vstorage_ - > CompactionScoreLevel ( 0 ) ) ;
ASSERT_EQ ( 1 , vstorage_ - > CompactionScoreLevel ( 1 ) ) ;
std : : unique_ptr < Compaction > compaction ( level_compaction_picker . PickCompaction (
cf_name_ , mutable_cf_options_ , vstorage_ . get ( ) , & log_buffer_ ) ) ;
ASSERT_TRUE ( compaction . get ( ) = = nullptr ) ;
}
TEST_F ( CompactionPickerTest , NotScheduleL1IfL0WithHigherPri2 ) {
NewVersionStorage ( 6 , kCompactionStyleLevel ) ;
mutable_cf_options_ . level0_file_num_compaction_trigger = 2 ;
mutable_cf_options_ . max_bytes_for_level_base = 900000000U ;
// 6 L0 files, score 3.
Add ( 0 , 1U , " 000 " , " 400 " , 1U ) ;
Add ( 0 , 2U , " 001 " , " 400 " , 1U , 0 , 0 ) ;
Add ( 0 , 3U , " 001 " , " 400 " , 1000000000U , 0 , 0 ) ;
Add ( 0 , 31U , " 001 " , " 400 " , 1000000000U , 0 , 0 ) ;
Add ( 0 , 32U , " 001 " , " 400 " , 1000000000U , 0 , 0 ) ;
Add ( 0 , 33U , " 001 " , " 400 " , 1000000000U , 0 , 0 ) ;
// L1 total size 2GB, score 2.2. If one file being comapcted, score 1.1.
Add ( 1 , 4U , " 050 " , " 300 " , 1000000000U , 0 , 0 ) ;
Add ( 1 , 5U , " 301 " , " 350 " , 1000000000U , 0 , 0 ) ;
// Output level overlaps with the beginning and the end of the chain
Add ( 2 , 6U , " 050 " , " 100 " , 1U ) ;
Add ( 2 , 7U , " 300 " , " 400 " , 1U ) ;
// If no file in L1 being compacted, L0->L1 compaction will be scheduled.
UpdateVersionStorageInfo ( ) ; // being_compacted flag is cleared here.
ASSERT_EQ ( 0 , vstorage_ - > CompactionScoreLevel ( 0 ) ) ;
ASSERT_EQ ( 1 , vstorage_ - > CompactionScoreLevel ( 1 ) ) ;
std : : unique_ptr < Compaction > compaction ( level_compaction_picker . PickCompaction (
cf_name_ , mutable_cf_options_ , vstorage_ . get ( ) , & log_buffer_ ) ) ;
ASSERT_TRUE ( compaction . get ( ) ! = nullptr ) ;
}
TEST_F ( CompactionPickerTest , NotScheduleL1IfL0WithHigherPri3 ) {
NewVersionStorage ( 6 , kCompactionStyleLevel ) ;
mutable_cf_options_ . level0_file_num_compaction_trigger = 2 ;
mutable_cf_options_ . max_bytes_for_level_base = 900000000U ;
// 6 L0 files, score 3.
Add ( 0 , 1U , " 000 " , " 400 " , 1U ) ;
Add ( 0 , 2U , " 001 " , " 400 " , 1U , 0 , 0 ) ;
Add ( 0 , 3U , " 001 " , " 400 " , 1000000000U , 0 , 0 ) ;
Add ( 0 , 31U , " 001 " , " 400 " , 1000000000U , 0 , 0 ) ;
Add ( 0 , 32U , " 001 " , " 400 " , 1000000000U , 0 , 0 ) ;
Add ( 0 , 33U , " 001 " , " 400 " , 1000000000U , 0 , 0 ) ;
// L1 score more than 6.
Add ( 1 , 4U , " 050 " , " 300 " , 1000000000U , 0 , 0 ) ;
file_map_ [ 4u ] . first - > being_compacted = true ;
Add ( 1 , 5U , " 301 " , " 350 " , 1000000000U , 0 , 0 ) ;
Add ( 1 , 51U , " 351 " , " 400 " , 6000000000U , 0 , 0 ) ;
// Output level overlaps with the beginning and the end of the chain
Add ( 2 , 6U , " 050 " , " 100 " , 1U ) ;
Add ( 2 , 7U , " 300 " , " 400 " , 1U ) ;
// If score in L1 is larger than L0, L1 compaction goes through despite
// there is pending L0 compaction.
UpdateVersionStorageInfo ( ) ;
ASSERT_EQ ( 1 , vstorage_ - > CompactionScoreLevel ( 0 ) ) ;
ASSERT_EQ ( 0 , vstorage_ - > CompactionScoreLevel ( 1 ) ) ;
std : : unique_ptr < Compaction > compaction ( level_compaction_picker . PickCompaction (
cf_name_ , mutable_cf_options_ , vstorage_ . get ( ) , & log_buffer_ ) ) ;
ASSERT_TRUE ( compaction . get ( ) ! = nullptr ) ;
}
TEST_F ( CompactionPickerTest , EstimateCompactionBytesNeeded1 ) {
int num_levels = ioptions_ . num_levels ;
ioptions_ . level_compaction_dynamic_level_bytes = false ;