@ -5968,7 +5968,7 @@ TEST_F(DBTest, EmptyCompactedDB) {
# endif // ROCKSDB_LITE
# ifndef ROCKSDB_LITE
TEST_F ( DBTest , DISABLED_ SuggestCompactRangeTest) {
TEST_F ( DBTest , SuggestCompactRangeTest ) {
class CompactionFilterFactoryGetContext : public CompactionFilterFactory {
public :
std : : unique_ptr < CompactionFilter > CreateCompactionFilter (
@ -6007,51 +6007,86 @@ TEST_F(DBTest, DISABLED_SuggestCompactRangeTest) {
Random rnd ( 301 ) ;
for ( int num = 0 ; num < 3 ; num + + ) {
for ( int num = 0 ; num < 10 ; num + + ) {
GenerateNewRandomFile ( & rnd ) ;
}
GenerateNewRandomFile ( & rnd ) ;
ASSERT_EQ ( " 0,4 " , FilesPerLevel ( 0 ) ) ;
ASSERT_TRUE ( ! CompactionFilterFactoryGetContext : : IsManual (
options . compaction_filter_factory . get ( ) ) ) ;
GenerateNewRandomFile ( & rnd ) ;
ASSERT_EQ ( " 1,4 " , FilesPerLevel ( 0 ) ) ;
// make sure either L0 or L1 has file
while ( NumTableFilesAtLevel ( 0 ) = = 0 & & NumTableFilesAtLevel ( 1 ) = = 0 ) {
GenerateNewRandomFile ( & rnd ) ;
}
GenerateNewRandomFile ( & rnd ) ;
ASSERT_EQ ( " 2,4 " , FilesPerLevel ( 0 ) ) ;
// compact it three times
for ( int i = 0 ; i < 3 ; + + i ) {
ASSERT_OK ( experimental : : SuggestCompactRange ( db_ , nullptr , nullptr ) ) ;
ASSERT_OK ( dbfull ( ) - > TEST_WaitForCompact ( ) ) ;
}
GenerateNewRandomFile ( & rnd ) ;
ASSERT_EQ ( " 3,4 " , FilesPerLevel ( 0 ) ) ;
// All files are compacted
ASSERT_EQ ( 0 , NumTableFilesAtLevel ( 0 ) ) ;
ASSERT_EQ ( 0 , NumTableFilesAtLevel ( 1 ) ) ;
GenerateNewRandomFile ( & rnd ) ;
ASSERT_EQ ( " 0,4,4 " , FilesPer Level( 0 ) ) ;
ASSERT_EQ ( 1 , NumTableFilesAt Level( 0 ) ) ;
GenerateNewRandomFile ( & rnd ) ;
ASSERT_EQ ( " 1,4,4 " , FilesPerLevel ( 0 ) ) ;
// nonoverlapping with the file on level 0
Slice start ( " a " ) , end ( " b " ) ;
ASSERT_OK ( experimental : : SuggestCompactRange ( db_ , & start , & end ) ) ;
ASSERT_OK ( dbfull ( ) - > TEST_WaitForCompact ( ) ) ;
GenerateNewRandomFile ( & rnd ) ;
ASSERT_EQ ( " 2,4,4 " , FilesPer Level( 0 ) ) ;
// should not compact the level 0 file
ASSERT_EQ ( 1 , NumTableFilesAt Level( 0 ) ) ;
GenerateNewRandomFile ( & rnd ) ;
ASSERT_EQ ( " 3,4,4 " , FilesPerLevel ( 0 ) ) ;
start = Slice ( " j " ) ;
end = Slice ( " m " ) ;
ASSERT_OK ( experimental : : SuggestCompactRange ( db_ , & start , & end ) ) ;
ASSERT_OK ( dbfull ( ) - > TEST_WaitForCompact ( ) ) ;
// SuggestCompactRange() is not going to be reported as manual compaction
ASSERT_TRUE ( ! CompactionFilterFactoryGetContext : : IsManual (
options . compaction_filter_factory . get ( ) ) ) ;
GenerateNewRandomFile ( & rnd ) ;
ASSERT_EQ ( " 0,4,8 " , FilesPerLevel ( 0 ) ) ;
// now it should compact the level 0 file
// as it's a trivial move to L1, it triggers another one to compact to L2
ASSERT_EQ ( 0 , NumTableFilesAtLevel ( 0 ) ) ;
ASSERT_EQ ( 0 , NumTableFilesAtLevel ( 1 ) ) ;
}
GenerateNewRandomFile ( & rnd ) ;
ASSERT_EQ ( " 1,4,8 " , FilesPerLevel ( 0 ) ) ;
TEST_F ( DBTest , SuggestCompactRangeUniversal ) {
Options options = CurrentOptions ( ) ;
options . memtable_factory . reset ( test : : NewSpecialSkipListFactory (
DBTestBase : : kNumKeysByGenerateNewRandomFile ) ) ;
options . compaction_style = kCompactionStyleUniversal ;
options . write_buffer_size = 200 < < 10 ;
options . arena_block_size = 4 < < 10 ;
options . level0_file_num_compaction_trigger = 4 ;
options . num_levels = 4 ;
options . compression = kNoCompression ;
options . max_bytes_for_level_base = 450 < < 10 ;
options . target_file_size_base = 98 < < 10 ;
options . max_compaction_bytes = static_cast < uint64_t > ( 1 ) < < 60 ; // inf
// compact it three times
for ( int i = 0 ; i < 3 ; + + i ) {
ASSERT_OK ( experimental : : SuggestCompactRange ( db_ , nullptr , nullptr ) ) ;
Reopen ( options ) ;
Random rnd ( 301 ) ;
for ( int num = 0 ; num < 10 ; num + + ) {
GenerateNewRandomFile ( & rnd ) ;
}
ASSERT_EQ ( " 1,2,3,4 " , FilesPerLevel ( ) ) ;
for ( int i = 0 ; i < 3 ; i + + ) {
ASSERT_OK (
db_ - > SuggestCompactRange ( db_ - > DefaultColumnFamily ( ) , nullptr , nullptr ) ) ;
ASSERT_OK ( dbfull ( ) - > TEST_WaitForCompact ( ) ) ;
}
// All files are compacted
ASSERT_EQ ( 0 , NumTableFilesAtLevel ( 0 ) ) ;
ASSERT_EQ ( 0 , NumTableFilesAtLevel ( 1 ) ) ;
ASSERT_EQ ( 0 , NumTableFilesAtLevel ( 2 ) ) ;
GenerateNewRandomFile ( & rnd ) ;
ASSERT_EQ ( 1 , NumTableFilesAtLevel ( 0 ) ) ;
@ -6068,12 +6103,10 @@ TEST_F(DBTest, DISABLED_SuggestCompactRangeTest) {
end = Slice ( " m " ) ;
ASSERT_OK ( experimental : : SuggestCompactRange ( db_ , & start , & end ) ) ;
ASSERT_OK ( dbfull ( ) - > TEST_WaitForCompact ( ) ) ;
ASSERT_TRUE ( CompactionFilterFactoryGetContext : : IsManual (
options . compaction_filter_factory . get ( ) ) ) ;
// now it should compact the level 0 file
// now it should compact the level 0 file to the last level
ASSERT_EQ ( 0 , NumTableFilesAtLevel ( 0 ) ) ;
ASSERT_EQ ( 1 , NumTableFilesAtLevel ( 1 ) ) ;
ASSERT_EQ ( 0 , NumTableFilesAtLevel ( 1 ) ) ;
}
TEST_F ( DBTest , PromoteL0 ) {