@ -12,9 +12,9 @@ namespace ROCKSDB_NAMESPACE {
class MyTestCompactionService : public CompactionService {
public :
MyTestCompactionService ( const std : : string & db_path ,
std : : shared_ptr < FileSystem > fs , Options & options )
: db_path_ ( db_path ) , fs_ ( fs ) , options_ ( option s) { }
MyTestCompactionService ( const std : : string & db_path , Options & options ,
std : : shared_ptr < Statistics > statistics = nullptr )
: db_path_ ( db_path ) , options_ ( options ) , statistics_ ( statistic s) { }
static const char * kClassName ( ) { return " MyTestCompactionService " ; }
@ -54,6 +54,7 @@ class MyTestCompactionService : public CompactionService {
options_override . prefix_extractor = options_ . prefix_extractor ;
options_override . table_factory = options_ . table_factory ;
options_override . sst_partitioner_factory = options_ . sst_partitioner_factory ;
options_override . statistics = statistics_ ;
Status s = DB : : OpenAndCompact (
db_path_ , db_path_ + " / " + ROCKSDB_NAMESPACE : : ToString ( job_id ) ,
@ -75,8 +76,8 @@ class MyTestCompactionService : public CompactionService {
std : : atomic_int compaction_num_ { 0 } ;
std : : map < uint64_t , std : : string > jobs_ ;
const std : : string db_path_ ;
std : : shared_ptr < FileSystem > fs_ ;
Options options_ ;
std : : shared_ptr < Statistics > statistics_ ;
} ;
class CompactionServiceTest : public DBTestBase {
@ -123,8 +124,10 @@ class CompactionServiceTest : public DBTestBase {
TEST_F ( CompactionServiceTest , BasicCompactions ) {
Options options = CurrentOptions ( ) ;
options . env = env_ ;
options . statistics = CreateDBStatistics ( ) ;
std : : shared_ptr < Statistics > compactor_statistics = CreateDBStatistics ( ) ;
options . compaction_service = std : : make_shared < MyTestCompactionService > (
dbname_ , env_ - > GetFileSystem ( ) , options ) ;
dbname_ , options , compactor_statistic s) ;
DestroyAndReopen ( options ) ;
@ -158,6 +161,12 @@ TEST_F(CompactionServiceTest, BasicCompactions) {
dynamic_cast < MyTestCompactionService * > ( options . compaction_service . get ( ) ) ;
ASSERT_GE ( my_cs - > GetCompactionNum ( ) , 1 ) ;
// make sure the compaction statistics is only recorded on remote side
ASSERT_GE (
compactor_statistics - > getTickerCount ( COMPACTION_KEY_DROP_NEWER_ENTRY ) , 1 ) ;
ASSERT_EQ ( options . statistics - > getTickerCount ( COMPACTION_KEY_DROP_NEWER_ENTRY ) ,
0 ) ;
// Test failed compaction
SyncPoint : : GetInstance ( ) - > SetCallBack (
" DBImplSecondary::CompactWithoutInstallation::End " , [ & ] ( void * status ) {
@ -195,8 +204,8 @@ TEST_F(CompactionServiceTest, ManualCompaction) {
Options options = CurrentOptions ( ) ;
options . env = env_ ;
options . disable_auto_compactions = true ;
options . compaction_service = std : : make_shared < MyTestCompactionService > (
dbname_ , env_ - > GetFileSystem ( ) , options ) ;
options . compaction_service =
std : : make_shared < MyTestCompactionService > ( dbname_ , options ) ;
DestroyAndReopen ( options ) ;
GenerateTestData ( ) ;
@ -236,8 +245,8 @@ TEST_F(CompactionServiceTest, FailedToStart) {
Options options = CurrentOptions ( ) ;
options . env = env_ ;
options . disable_auto_compactions = true ;
options . compaction_service = std : : make_shared < MyTestCompactionService > (
dbname_ , env_ - > GetFileSystem ( ) , options ) ;
options . compaction_service =
std : : make_shared < MyTestCompactionService > ( dbname_ , options ) ;
DestroyAndReopen ( options ) ;
GenerateTestData ( ) ;
@ -261,8 +270,8 @@ TEST_F(CompactionServiceTest, InvalidResult) {
Options options = CurrentOptions ( ) ;
options . env = env_ ;
options . disable_auto_compactions = true ;
options . compaction_service = std : : make_shared < MyTestCompactionService > (
dbname_ , env_ - > GetFileSystem ( ) , options ) ;
options . compaction_service =
std : : make_shared < MyTestCompactionService > ( dbname_ , options ) ;
DestroyAndReopen ( options ) ;
GenerateTestData ( ) ;
@ -288,8 +297,8 @@ TEST_F(CompactionServiceTest, SubCompaction) {
options . max_subcompactions = 10 ;
options . target_file_size_base = 1 < < 10 ; // 1KB
options . disable_auto_compactions = true ;
options . compaction_service = std : : make_shared < MyTestCompactionService > (
dbname_ , env_ - > GetFileSystem ( ) , options ) ;
options . compaction_service =
std : : make_shared < MyTestCompactionService > ( dbname_ , options ) ;
DestroyAndReopen ( options ) ;
GenerateTestData ( ) ;
@ -330,8 +339,8 @@ TEST_F(CompactionServiceTest, CompactionFilter) {
options . env = env_ ;
auto delete_comp_filter = PartialDeleteCompactionFilter ( ) ;
options . compaction_filter = & delete_comp_filter ;
options . compaction_service = std : : make_shared < MyTestCompactionService > (
dbname_ , env_ - > GetFileSystem ( ) , options ) ;
options . compaction_service =
std : : make_shared < MyTestCompactionService > ( dbname_ , options ) ;
DestroyAndReopen ( options ) ;
@ -373,8 +382,8 @@ TEST_F(CompactionServiceTest, CompactionFilter) {
TEST_F ( CompactionServiceTest , Snapshot ) {
Options options = CurrentOptions ( ) ;
options . env = env_ ;
options . compaction_service = std : : make_shared < MyTestCompactionService > (
dbname_ , env_ - > GetFileSystem ( ) , options ) ;
options . compaction_service =
std : : make_shared < MyTestCompactionService > ( dbname_ , options ) ;
DestroyAndReopen ( options ) ;
@ -400,8 +409,8 @@ TEST_F(CompactionServiceTest, ConcurrentCompaction) {
Options options = CurrentOptions ( ) ;
options . level0_file_num_compaction_trigger = 100 ;
options . env = env_ ;
options . compaction_service = std : : make_shared < MyTestCompactionService > (
dbname_ , env_ - > GetFileSystem ( ) , options ) ;
options . compaction_service =
std : : make_shared < MyTestCompactionService > ( dbname_ , options ) ;
options . max_background_jobs = 20 ;
DestroyAndReopen ( options ) ;