@ -419,6 +419,76 @@ TEST_F(CompactionPickerTest, ParentIndexResetBug) {
cf_name_ , mutable_cf_options_ , vstorage_ . get ( ) , & log_buffer_ ) ) ;
cf_name_ , mutable_cf_options_ , vstorage_ . get ( ) , & log_buffer_ ) ) ;
}
}
// This test checks ExpandWhileOverlapping() by having overlapping user keys
// ranges (with different sequence numbers) in the input files.
TEST_F ( CompactionPickerTest , OverlappingUserKeys ) {
NewVersionStorage ( 6 , kCompactionStyleLevel ) ;
Add ( 1 , 1U , " 100 " , " 150 " , 1U ) ;
// Overlapping user keys
Add ( 1 , 2U , " 200 " , " 400 " , 1U ) ;
Add ( 1 , 3U , " 400 " , " 500 " , 1000000000U , 0 , 0 ) ;
Add ( 2 , 4U , " 600 " , " 700 " , 1U ) ;
UpdateVersionStorageInfo ( ) ;
std : : unique_ptr < Compaction > compaction ( level_compaction_picker . PickCompaction (
cf_name_ , mutable_cf_options_ , vstorage_ . get ( ) , & log_buffer_ ) ) ;
ASSERT_TRUE ( compaction . get ( ) ! = nullptr ) ;
ASSERT_EQ ( 1U , compaction - > num_input_levels ( ) ) ;
ASSERT_EQ ( 2U , compaction - > num_input_files ( 0 ) ) ;
ASSERT_EQ ( 2U , compaction - > input ( 0 , 0 ) - > fd . GetNumber ( ) ) ;
ASSERT_EQ ( 3U , compaction - > input ( 0 , 1 ) - > fd . GetNumber ( ) ) ;
}
TEST_F ( CompactionPickerTest , OverlappingUserKeys2 ) {
NewVersionStorage ( 6 , kCompactionStyleLevel ) ;
// Overlapping user keys on same level and output level
Add ( 1 , 1U , " 200 " , " 400 " , 1000000000U ) ;
Add ( 1 , 2U , " 400 " , " 500 " , 1U , 0 , 0 ) ;
Add ( 2 , 3U , " 400 " , " 600 " , 1U ) ;
// The following file is not in the compaction despite overlapping user keys
Add ( 2 , 4U , " 600 " , " 700 " , 1U , 0 , 0 ) ;
UpdateVersionStorageInfo ( ) ;
std : : unique_ptr < Compaction > compaction ( level_compaction_picker . PickCompaction (
cf_name_ , mutable_cf_options_ , vstorage_ . get ( ) , & log_buffer_ ) ) ;
ASSERT_TRUE ( compaction . get ( ) ! = nullptr ) ;
ASSERT_EQ ( 2U , compaction - > num_input_levels ( ) ) ;
ASSERT_EQ ( 2U , compaction - > num_input_files ( 0 ) ) ;
ASSERT_EQ ( 1U , compaction - > num_input_files ( 1 ) ) ;
ASSERT_EQ ( 1U , compaction - > input ( 0 , 0 ) - > fd . GetNumber ( ) ) ;
ASSERT_EQ ( 2U , compaction - > input ( 0 , 1 ) - > fd . GetNumber ( ) ) ;
ASSERT_EQ ( 3U , compaction - > input ( 1 , 0 ) - > fd . GetNumber ( ) ) ;
}
TEST_F ( CompactionPickerTest , OverlappingUserKeys3 ) {
NewVersionStorage ( 6 , kCompactionStyleLevel ) ;
// Chain of overlapping user key ranges (forces ExpandWhileOverlapping() to
// expand multiple times)
Add ( 1 , 1U , " 100 " , " 150 " , 1U ) ;
Add ( 1 , 2U , " 150 " , " 200 " , 1U , 0 , 0 ) ;
Add ( 1 , 3U , " 200 " , " 250 " , 1000000000U , 0 , 0 ) ;
Add ( 1 , 4U , " 250 " , " 300 " , 1U , 0 , 0 ) ;
Add ( 1 , 5U , " 300 " , " 350 " , 1U , 0 , 0 ) ;
// Output level overlaps with the beginning and the end of the chain
Add ( 2 , 6U , " 050 " , " 100 " , 1U ) ;
Add ( 2 , 7U , " 350 " , " 400 " , 1U ) ;
UpdateVersionStorageInfo ( ) ;
std : : unique_ptr < Compaction > compaction ( level_compaction_picker . PickCompaction (
cf_name_ , mutable_cf_options_ , vstorage_ . get ( ) , & log_buffer_ ) ) ;
ASSERT_TRUE ( compaction . get ( ) ! = nullptr ) ;
ASSERT_EQ ( 2U , compaction - > num_input_levels ( ) ) ;
ASSERT_EQ ( 5U , compaction - > num_input_files ( 0 ) ) ;
ASSERT_EQ ( 2U , compaction - > num_input_files ( 1 ) ) ;
ASSERT_EQ ( 1U , compaction - > input ( 0 , 0 ) - > fd . GetNumber ( ) ) ;
ASSERT_EQ ( 2U , compaction - > input ( 0 , 1 ) - > fd . GetNumber ( ) ) ;
ASSERT_EQ ( 3U , compaction - > input ( 0 , 2 ) - > fd . GetNumber ( ) ) ;
ASSERT_EQ ( 4U , compaction - > input ( 0 , 3 ) - > fd . GetNumber ( ) ) ;
ASSERT_EQ ( 5U , compaction - > input ( 0 , 4 ) - > fd . GetNumber ( ) ) ;
ASSERT_EQ ( 6U , compaction - > input ( 1 , 0 ) - > fd . GetNumber ( ) ) ;
ASSERT_EQ ( 7U , compaction - > input ( 1 , 1 ) - > fd . GetNumber ( ) ) ;
}
} // namespace rocksdb
} // namespace rocksdb
int main ( int argc , char * * argv ) {
int main ( int argc , char * * argv ) {