@ -156,6 +156,8 @@ class TestCompactionListener : public EventListener {
compacted_dbs_ . push_back ( db ) ;
ASSERT_GT ( ci . input_files . size ( ) , 0U ) ;
ASSERT_GT ( ci . output_files . size ( ) , 0U ) ;
ASSERT_EQ ( db - > GetEnv ( ) - > GetThreadID ( ) , ci . thread_id ) ;
ASSERT_GT ( ci . thread_id , 0U ) ;
}
std : : vector < DB * > compacted_dbs_ ;
@ -177,7 +179,9 @@ TEST_F(EventListenerTest, OnSingleDBCompactionTest) {
options . max_bytes_for_level_base = options . target_file_size_base * 2 ;
options . max_bytes_for_level_multiplier = 2 ;
options . compression = kNoCompression ;
# if ROCKSDB_USING_THREAD_STATUS
options . enable_thread_tracking = true ;
# endif // ROCKSDB_USING_THREAD_STATUS
options . level0_file_num_compaction_trigger = kNumL0Files ;
TestCompactionListener * listener = new TestCompactionListener ( ) ;
@ -211,6 +215,11 @@ TEST_F(EventListenerTest, OnSingleDBCompactionTest) {
// This simple Listener can only handle one flush at a time.
class TestFlushListener : public EventListener {
public :
explicit TestFlushListener ( Env * env ) :
slowdown_count ( 0 ) ,
stop_count ( 0 ) ,
db_closed ( false ) ,
env_ ( env ) { }
void OnTableFileCreated (
const TableFileCreationInfo & info ) override {
// remember the info for later checking the FlushJobInfo.
@ -224,6 +233,25 @@ class TestFlushListener : public EventListener {
ASSERT_GT ( info . table_properties . raw_value_size , 0U ) ;
ASSERT_GT ( info . table_properties . num_data_blocks , 0U ) ;
ASSERT_GT ( info . table_properties . num_entries , 0U ) ;
# if ROCKSDB_USING_THREAD_STATUS
// Verify the id of the current thread that created this table
// file matches the id of any active flush or compaction thread.
uint64_t thread_id = env_ - > GetThreadID ( ) ;
std : : vector < ThreadStatus > thread_list ;
ASSERT_OK ( env_ - > GetThreadList ( & thread_list ) ) ;
bool found_match = false ;
for ( auto thread_status : thread_list ) {
if ( thread_status . operation_type = = ThreadStatus : : OP_FLUSH | |
thread_status . operation_type = = ThreadStatus : : OP_COMPACTION ) {
if ( thread_id = = thread_status . thread_id ) {
found_match = true ;
break ;
}
}
}
ASSERT_TRUE ( found_match ) ;
# endif // ROCKSDB_USING_THREAD_STATUS
}
void OnFlushCompleted (
@ -241,19 +269,29 @@ class TestFlushListener : public EventListener {
ASSERT_EQ ( prev_fc_info_ . cf_name , info . cf_name ) ;
ASSERT_EQ ( prev_fc_info_ . job_id , info . job_id ) ;
ASSERT_EQ ( prev_fc_info_ . file_path , info . file_path ) ;
ASSERT_EQ ( db - > GetEnv ( ) - > GetThreadID ( ) , info . thread_id ) ;
ASSERT_GT ( info . thread_id , 0U ) ;
}
std : : vector < std : : string > flushed_column_family_names_ ;
std : : vector < DB * > flushed_dbs_ ;
int slowdown_count ;
int stop_count ;
bool db_closing ;
std : : atomic_bool db_closed ;
TableFileCreationInfo prev_fc_info_ ;
protected :
Env * env_ ;
} ;
TEST_F ( EventListenerTest , OnSingleDBFlushTest ) {
Options options ;
options . write_buffer_size = 100000 ;
TestFlushListener * listener = new TestFlushListener ( ) ;
# if ROCKSDB_USING_THREAD_STATUS
options . enable_thread_tracking = true ;
# endif // ROCKSDB_USING_THREAD_STATUS
TestFlushListener * listener = new TestFlushListener ( options . env ) ;
options . listeners . emplace_back ( listener ) ;
std : : vector < std : : string > cf_names = {
" pikachu " , " ilya " , " muromec " , " dobrynia " ,
@ -284,7 +322,10 @@ TEST_F(EventListenerTest, OnSingleDBFlushTest) {
TEST_F ( EventListenerTest , MultiCF ) {
Options options ;
options . write_buffer_size = 100000 ;
TestFlushListener * listener = new TestFlushListener ( ) ;
# if ROCKSDB_USING_THREAD_STATUS
options . enable_thread_tracking = true ;
# endif // ROCKSDB_USING_THREAD_STATUS
TestFlushListener * listener = new TestFlushListener ( options . env ) ;
options . listeners . emplace_back ( listener ) ;
std : : vector < std : : string > cf_names = {
" pikachu " , " ilya " , " muromec " , " dobrynia " ,
@ -312,18 +353,21 @@ TEST_F(EventListenerTest, MultiCF) {
}
TEST_F ( EventListenerTest , MultiDBMultiListeners ) {
Options options ;
# if ROCKSDB_USING_THREAD_STATUS
options . enable_thread_tracking = true ;
# endif // ROCKSDB_USING_THREAD_STATUS
std : : vector < TestFlushListener * > listeners ;
const int kNumDBs = 5 ;
const int kNumListeners = 10 ;
for ( int i = 0 ; i < kNumListeners ; + + i ) {
listeners . emplace_back ( new TestFlushListener ( ) ) ;
listeners . emplace_back ( new TestFlushListener ( options . env ) ) ;
}
std : : vector < std : : string > cf_names = {
" pikachu " , " ilya " , " muromec " , " dobrynia " ,
" nikitich " , " alyosha " , " popovich " } ;
Options options ;
options . create_if_missing = true ;
for ( int i = 0 ; i < kNumListeners ; + + i ) {
options . listeners . emplace_back ( listeners [ i ] ) ;
@ -374,6 +418,7 @@ TEST_F(EventListenerTest, MultiDBMultiListeners) {
}
}
for ( auto handles : vec_handles ) {
for ( auto h : handles ) {
delete h ;
@ -389,7 +434,10 @@ TEST_F(EventListenerTest, MultiDBMultiListeners) {
TEST_F ( EventListenerTest , DisableBGCompaction ) {
Options options ;
TestFlushListener * listener = new TestFlushListener ( ) ;
# if ROCKSDB_USING_THREAD_STATUS
options . enable_thread_tracking = true ;
# endif // ROCKSDB_USING_THREAD_STATUS
TestFlushListener * listener = new TestFlushListener ( options . env ) ;
const int kSlowdownTrigger = 5 ;
const int kStopTrigger = 10 ;
options . level0_slowdown_writes_trigger = kSlowdownTrigger ;
@ -409,6 +457,7 @@ TEST_F(EventListenerTest, DisableBGCompaction) {
// keep writing until writes are forced to stop.
for ( int i = 0 ; static_cast < int > ( cf_meta . file_count ) < kStopTrigger ; + + i ) {
Put ( 1 , ToString ( i ) , std : : string ( 100000 , ' x ' ) , wopts ) ;
db_ - > Flush ( FlushOptions ( ) ) ;
db_ - > GetColumnFamilyMetaData ( handles_ [ 1 ] , & cf_meta ) ;
}
ASSERT_GE ( listener - > slowdown_count , kStopTrigger - kSlowdownTrigger ) ;