@ -15,13 +15,17 @@ class MyTestCompactionService : public CompactionService {
MyTestCompactionService (
MyTestCompactionService (
std : : string db_path , Options & options ,
std : : string db_path , Options & options ,
std : : shared_ptr < Statistics > & statistics ,
std : : shared_ptr < Statistics > & statistics ,
std : : vector < std : : shared_ptr < EventListener > > & listeners )
std : : vector < std : : shared_ptr < EventListener > > & listeners ,
std : : vector < std : : shared_ptr < TablePropertiesCollectorFactory > >
table_properties_collector_factories )
: db_path_ ( std : : move ( db_path ) ) ,
: db_path_ ( std : : move ( db_path ) ) ,
options_ ( options ) ,
options_ ( options ) ,
statistics_ ( statistics ) ,
statistics_ ( statistics ) ,
start_info_ ( " na " , " na " , " na " , 0 , Env : : TOTAL ) ,
start_info_ ( " na " , " na " , " na " , 0 , Env : : TOTAL ) ,
wait_info_ ( " na " , " na " , " na " , 0 , Env : : TOTAL ) ,
wait_info_ ( " na " , " na " , " na " , 0 , Env : : TOTAL ) ,
listeners_ ( listeners ) { }
listeners_ ( listeners ) ,
table_properties_collector_factories_ (
std : : move ( table_properties_collector_factories ) ) { }
static const char * kClassName ( ) { return " MyTestCompactionService " ; }
static const char * kClassName ( ) { return " MyTestCompactionService " ; }
@ -78,6 +82,11 @@ class MyTestCompactionService : public CompactionService {
options_override . listeners = listeners_ ;
options_override . listeners = listeners_ ;
}
}
if ( ! table_properties_collector_factories_ . empty ( ) ) {
options_override . table_properties_collector_factories =
table_properties_collector_factories_ ;
}
OpenAndCompactOptions options ;
OpenAndCompactOptions options ;
options . canceled = & canceled_ ;
options . canceled = & canceled_ ;
@ -141,6 +150,8 @@ class MyTestCompactionService : public CompactionService {
bool is_override_wait_result_ = false ;
bool is_override_wait_result_ = false ;
std : : string override_wait_result_ ;
std : : string override_wait_result_ ;
std : : vector < std : : shared_ptr < EventListener > > listeners_ ;
std : : vector < std : : shared_ptr < EventListener > > listeners_ ;
std : : vector < std : : shared_ptr < TablePropertiesCollectorFactory > >
table_properties_collector_factories_ ;
std : : atomic_bool canceled_ { false } ;
std : : atomic_bool canceled_ { false } ;
} ;
} ;
@ -157,7 +168,8 @@ class CompactionServiceTest : public DBTestBase {
compactor_statistics_ = CreateDBStatistics ( ) ;
compactor_statistics_ = CreateDBStatistics ( ) ;
compaction_service_ = std : : make_shared < MyTestCompactionService > (
compaction_service_ = std : : make_shared < MyTestCompactionService > (
dbname_ , * options , compactor_statistics_ , remote_listeners ) ;
dbname_ , * options , compactor_statistics_ , remote_listeners ,
remote_table_properties_collector_factories ) ;
options - > compaction_service = compaction_service_ ;
options - > compaction_service = compaction_service_ ;
DestroyAndReopen ( * options ) ;
DestroyAndReopen ( * options ) ;
}
}
@ -206,6 +218,8 @@ class CompactionServiceTest : public DBTestBase {
}
}
std : : vector < std : : shared_ptr < EventListener > > remote_listeners ;
std : : vector < std : : shared_ptr < EventListener > > remote_listeners ;
std : : vector < std : : shared_ptr < TablePropertiesCollectorFactory > >
remote_table_properties_collector_factories ;
private :
private :
std : : shared_ptr < Statistics > compactor_statistics_ ;
std : : shared_ptr < Statistics > compactor_statistics_ ;
@ -827,6 +841,96 @@ TEST_F(CompactionServiceTest, RemoteEventListener) {
}
}
}
}
TEST_F ( CompactionServiceTest , TablePropertiesCollector ) {
const static std : : string kUserPropertyName = " TestCount " ;
class TablePropertiesCollectorTest : public TablePropertiesCollector {
public :
Status Finish ( UserCollectedProperties * properties ) override {
* properties = UserCollectedProperties {
{ kUserPropertyName , std : : to_string ( count_ ) } ,
} ;
return Status : : OK ( ) ;
}
UserCollectedProperties GetReadableProperties ( ) const override {
return UserCollectedProperties ( ) ;
}
const char * Name ( ) const override { return " TablePropertiesCollectorTest " ; }
Status AddUserKey ( const Slice & /*user_key*/ , const Slice & /*value*/ ,
EntryType /*type*/ , SequenceNumber /*seq*/ ,
uint64_t /*file_size*/ ) override {
count_ + + ;
return Status : : OK ( ) ;
}
private :
uint32_t count_ = 0 ;
} ;
class TablePropertiesCollectorFactoryTest
: public TablePropertiesCollectorFactory {
public :
TablePropertiesCollector * CreateTablePropertiesCollector (
TablePropertiesCollectorFactory : : Context /*context*/ ) override {
return new TablePropertiesCollectorTest ( ) ;
}
const char * Name ( ) const override {
return " TablePropertiesCollectorFactoryTest " ;
}
} ;
auto factory = new TablePropertiesCollectorFactoryTest ( ) ;
remote_table_properties_collector_factories . emplace_back ( factory ) ;
const int kNumSst = 3 ;
const int kLevel0Trigger = 4 ;
Options options = CurrentOptions ( ) ;
options . level0_file_num_compaction_trigger = kLevel0Trigger ;
ReopenWithCompactionService ( & options ) ;
// generate a few SSTs locally which should not have user property
for ( int i = 0 ; i < kNumSst ; i + + ) {
for ( int j = 0 ; j < 100 ; j + + ) {
ASSERT_OK ( Put ( Key ( i * 10 + j ) , " value " ) ) ;
}
ASSERT_OK ( Flush ( ) ) ;
}
TablePropertiesCollection fname_to_props ;
ASSERT_OK ( db_ - > GetPropertiesOfAllTables ( & fname_to_props ) ) ;
for ( const auto & file_props : fname_to_props ) {
auto properties = file_props . second - > user_collected_properties ;
auto it = properties . find ( kUserPropertyName ) ;
ASSERT_EQ ( it , properties . end ( ) ) ;
}
// trigger compaction
for ( int i = kNumSst ; i < kLevel0Trigger ; i + + ) {
for ( int j = 0 ; j < 100 ; j + + ) {
ASSERT_OK ( Put ( Key ( i * 10 + j ) , " value " ) ) ;
}
ASSERT_OK ( Flush ( ) ) ;
}
ASSERT_OK ( dbfull ( ) - > TEST_WaitForCompact ( true ) ) ;
ASSERT_OK ( db_ - > GetPropertiesOfAllTables ( & fname_to_props ) ) ;
bool has_user_property = false ;
for ( const auto & file_props : fname_to_props ) {
auto properties = file_props . second - > user_collected_properties ;
auto it = properties . find ( kUserPropertyName ) ;
if ( it ! = properties . end ( ) ) {
has_user_property = true ;
ASSERT_GT ( std : : stoi ( it - > second ) , 0 ) ;
}
}
ASSERT_TRUE ( has_user_property ) ;
}
} // namespace ROCKSDB_NAMESPACE
} // namespace ROCKSDB_NAMESPACE
int main ( int argc , char * * argv ) {
int main ( int argc , char * * argv ) {