@ -417,14 +417,25 @@ class CompactionJobStatsTest : public testing::Test,
// test CompactionJobStatsTest.
// test CompactionJobStatsTest.
class CompactionJobStatsChecker : public EventListener {
class CompactionJobStatsChecker : public EventListener {
public :
public :
CompactionJobStatsChecker ( ) : compression_enabled_ ( false ) { }
CompactionJobStatsChecker ( )
: compression_enabled_ ( false ) , verify_next_comp_io_stats_ ( false ) { }
size_t NumberOfUnverifiedStats ( ) { return expected_stats_ . size ( ) ; }
size_t NumberOfUnverifiedStats ( ) { return expected_stats_ . size ( ) ; }
void set_verify_next_comp_io_stats ( bool v ) { verify_next_comp_io_stats_ = v ; }
// Once a compaction completed, this function will verify the returned
// Once a compaction completed, this function will verify the returned
// CompactionJobInfo with the oldest CompactionJobInfo added earlier
// CompactionJobInfo with the oldest CompactionJobInfo added earlier
// in "expected_stats_" which has not yet being used for verification.
// in "expected_stats_" which has not yet being used for verification.
virtual void OnCompactionCompleted ( DB * db , const CompactionJobInfo & ci ) {
virtual void OnCompactionCompleted ( DB * db , const CompactionJobInfo & ci ) {
if ( verify_next_comp_io_stats_ ) {
ASSERT_GT ( ci . stats . file_write_nanos , 0 ) ;
ASSERT_GT ( ci . stats . file_range_sync_nanos , 0 ) ;
ASSERT_GT ( ci . stats . file_fsync_nanos , 0 ) ;
ASSERT_GT ( ci . stats . file_prepare_write_nanos , 0 ) ;
verify_next_comp_io_stats_ = false ;
}
std : : lock_guard < std : : mutex > lock ( mutex_ ) ;
std : : lock_guard < std : : mutex > lock ( mutex_ ) ;
if ( expected_stats_ . size ( ) ) {
if ( expected_stats_ . size ( ) ) {
Verify ( ci . stats , expected_stats_ . front ( ) ) ;
Verify ( ci . stats , expected_stats_ . front ( ) ) ;
@ -498,10 +509,13 @@ class CompactionJobStatsChecker : public EventListener {
compression_enabled_ = flag ;
compression_enabled_ = flag ;
}
}
bool verify_next_comp_io_stats ( ) const { return verify_next_comp_io_stats_ ; }
private :
private :
std : : mutex mutex_ ;
std : : mutex mutex_ ;
std : : queue < CompactionJobStats > expected_stats_ ;
std : : queue < CompactionJobStats > expected_stats_ ;
bool compression_enabled_ ;
bool compression_enabled_ ;
bool verify_next_comp_io_stats_ ;
} ;
} ;
// An EventListener which helps verify the compaction statistics in
// An EventListener which helps verify the compaction statistics in
@ -643,7 +657,9 @@ TEST_P(CompactionJobStatsTest, CompactionJobStatsTest) {
options . num_levels = 3 ;
options . num_levels = 3 ;
options . compression = kNoCompression ;
options . compression = kNoCompression ;
options . num_subcompactions = num_subcompactions_ ;
options . num_subcompactions = num_subcompactions_ ;
options . bytes_per_sync = 512 * 1024 ;
options . compaction_measure_io_stats = true ;
for ( int test = 0 ; test < 2 ; + + test ) {
for ( int test = 0 ; test < 2 ; + + test ) {
DestroyAndReopen ( options ) ;
DestroyAndReopen ( options ) ;
CreateAndReopenWithCF ( { " pikachu " } , options ) ;
CreateAndReopenWithCF ( { " pikachu " } , options ) ;
@ -766,6 +782,7 @@ TEST_P(CompactionJobStatsTest, CompactionJobStatsTest) {
num_keys_per_L0_file ) ) ;
num_keys_per_L0_file ) ) ;
ASSERT_EQ ( stats_checker - > NumberOfUnverifiedStats ( ) , 1U ) ;
ASSERT_EQ ( stats_checker - > NumberOfUnverifiedStats ( ) , 1U ) ;
Compact ( 1 , smallest_key , largest_key ) ;
Compact ( 1 , smallest_key , largest_key ) ;
num_L1_files = options . num_subcompactions > 1 ? 7 : 4 ;
num_L1_files = options . num_subcompactions > 1 ? 7 : 4 ;
char L1_buf [ 4 ] ;
char L1_buf [ 4 ] ;
snprintf ( L1_buf , sizeof ( L1_buf ) , " 0,%d " , num_L1_files ) ;
snprintf ( L1_buf , sizeof ( L1_buf ) , " 0,%d " , num_L1_files ) ;
@ -777,6 +794,61 @@ TEST_P(CompactionJobStatsTest, CompactionJobStatsTest) {
}
}
stats_checker - > EnableCompression ( true ) ;
stats_checker - > EnableCompression ( true ) ;
compression_ratio = kCompressionRatio ;
compression_ratio = kCompressionRatio ;
for ( int i = 0 ; i < 5 ; i + + ) {
ASSERT_OK ( Put ( 1 , Slice ( Key ( key_base + i , 10 ) ) ,
Slice ( RandomString ( & rnd , 512 * 1024 , 1 ) ) ) ) ;
}
ASSERT_OK ( Flush ( 1 ) ) ;
reinterpret_cast < DBImpl * > ( db_ ) - > TEST_WaitForCompact ( ) ;
stats_checker - > set_verify_next_comp_io_stats ( true ) ;
std : : atomic < bool > first_prepare_write ( true ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > SetCallBack (
" WritableFileWriter::Append:BeforePrepareWrite " , [ & ] ( void * arg ) {
if ( first_prepare_write . load ( ) ) {
options . env - > SleepForMicroseconds ( 3 ) ;
first_prepare_write . store ( false ) ;
}
} ) ;
std : : atomic < bool > first_flush ( true ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > SetCallBack (
" WritableFileWriter::Flush:BeforeAppend " , [ & ] ( void * arg ) {
if ( first_flush . load ( ) ) {
options . env - > SleepForMicroseconds ( 3 ) ;
first_flush . store ( false ) ;
}
} ) ;
std : : atomic < bool > first_sync ( true ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > SetCallBack (
" WritableFileWriter::SyncInternal:0 " , [ & ] ( void * arg ) {
if ( first_sync . load ( ) ) {
options . env - > SleepForMicroseconds ( 3 ) ;
first_sync . store ( false ) ;
}
} ) ;
std : : atomic < bool > first_range_sync ( true ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > SetCallBack (
" WritableFileWriter::RangeSync:0 " , [ & ] ( void * arg ) {
if ( first_range_sync . load ( ) ) {
options . env - > SleepForMicroseconds ( 3 ) ;
first_range_sync . store ( false ) ;
}
} ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > EnableProcessing ( ) ;
Compact ( 1 , smallest_key , largest_key ) ;
ASSERT_TRUE ( ! stats_checker - > verify_next_comp_io_stats ( ) ) ;
ASSERT_TRUE ( ! first_prepare_write . load ( ) ) ;
ASSERT_TRUE ( ! first_flush . load ( ) ) ;
ASSERT_TRUE ( ! first_sync . load ( ) ) ;
ASSERT_TRUE ( ! first_range_sync . load ( ) ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > DisableProcessing ( ) ;
}
}
ASSERT_EQ ( stats_checker - > NumberOfUnverifiedStats ( ) , 0U ) ;
ASSERT_EQ ( stats_checker - > NumberOfUnverifiedStats ( ) , 0U ) ;
}
}