@ -974,7 +974,7 @@ class DelayFilter : public CompactionFilter {
bool Filter ( int /*level*/ , const Slice & /*key*/ , const Slice & /*value*/ ,
bool Filter ( int /*level*/ , const Slice & /*key*/ , const Slice & /*value*/ ,
std : : string * /*new_value*/ ,
std : : string * /*new_value*/ ,
bool * /*value_changed*/ ) const override {
bool * /*value_changed*/ ) const override {
db_test - > env_ - > addon_time_ . fetch_add ( 1000 ) ;
db_test - > env_ - > MockSleepForMicroseconds ( 1000 ) ;
return true ;
return true ;
}
}
@ -1719,6 +1719,7 @@ TEST_F(DBTest, ApproximateSizes_MixOfSmallAndLarge) {
# ifndef ROCKSDB_LITE
# ifndef ROCKSDB_LITE
TEST_F ( DBTest , Snapshot ) {
TEST_F ( DBTest , Snapshot ) {
env_ - > SetMockSleep ( ) ;
anon : : OptionsOverride options_override ;
anon : : OptionsOverride options_override ;
options_override . skip_policy = kSkipNoSnapshot ;
options_override . skip_policy = kSkipNoSnapshot ;
do {
do {
@ -1734,7 +1735,7 @@ TEST_F(DBTest, Snapshot) {
Put ( 0 , " foo " , " 0v2 " ) ;
Put ( 0 , " foo " , " 0v2 " ) ;
Put ( 1 , " foo " , " 1v2 " ) ;
Put ( 1 , " foo " , " 1v2 " ) ;
env_ - > addon_time_ . fetch_add ( 1 ) ;
env_ - > MockSleepForSeconds ( 1 ) ;
const Snapshot * s2 = db_ - > GetSnapshot ( ) ;
const Snapshot * s2 = db_ - > GetSnapshot ( ) ;
ASSERT_EQ ( 2U , GetNumSnapshots ( ) ) ;
ASSERT_EQ ( 2U , GetNumSnapshots ( ) ) ;
@ -3545,13 +3546,14 @@ TEST_F(DBTest, FIFOCompactionWithTTLTest) {
options . arena_block_size = 4096 ;
options . arena_block_size = 4096 ;
options . compression = kNoCompression ;
options . compression = kNoCompression ;
options . create_if_missing = true ;
options . create_if_missing = true ;
env_ - > time_elapse_only_sleep_ = false ;
env_ - > SetMockSleep ( ) ;
options . env = env_ ;
options . env = env_ ;
// Test to make sure that all files with expired ttl are deleted on next
// Test to make sure that all files with expired ttl are deleted on next
// manual compaction.
// manual compaction.
{
{
env_ - > addon_time_ . store ( 0 ) ;
// NOTE: Presumed unnecessary and removed: resetting mock time in env
options . compaction_options_fifo . max_table_files_size = 150 < < 10 ; // 150KB
options . compaction_options_fifo . max_table_files_size = 150 < < 10 ; // 150KB
options . compaction_options_fifo . allow_compaction = false ;
options . compaction_options_fifo . allow_compaction = false ;
options . ttl = 1 * 60 * 60 ; // 1 hour
options . ttl = 1 * 60 * 60 ; // 1 hour
@ -3570,10 +3572,7 @@ TEST_F(DBTest, FIFOCompactionWithTTLTest) {
ASSERT_EQ ( NumTableFilesAtLevel ( 0 ) , 10 ) ;
ASSERT_EQ ( NumTableFilesAtLevel ( 0 ) , 10 ) ;
// Sleep for 2 hours -- which is much greater than TTL.
// Sleep for 2 hours -- which is much greater than TTL.
// Note: Couldn't use SleepForMicroseconds because it takes an int instead
env_ - > MockSleepForSeconds ( 2 * 60 * 60 ) ;
// of uint64_t. Hence used addon_time_ directly.
// env_->SleepForMicroseconds(2 * 60 * 60 * 1000 * 1000);
env_ - > addon_time_ . fetch_add ( 2 * 60 * 60 ) ;
// Since no flushes and compactions have run, the db should still be in
// Since no flushes and compactions have run, the db should still be in
// the same state even after considerable time has passed.
// the same state even after considerable time has passed.
@ -3605,7 +3604,7 @@ TEST_F(DBTest, FIFOCompactionWithTTLTest) {
ASSERT_EQ ( NumTableFilesAtLevel ( 0 ) , 10 ) ;
ASSERT_EQ ( NumTableFilesAtLevel ( 0 ) , 10 ) ;
// Sleep for 2 hours -- which is much greater than TTL.
// Sleep for 2 hours -- which is much greater than TTL.
env_ - > addon_time_ . fetch_add ( 2 * 60 * 60 ) ;
env_ - > MockSleepForSeconds ( 2 * 60 * 60 ) ;
// Just to make sure that we are in the same state even after sleeping.
// Just to make sure that we are in the same state even after sleeping.
ASSERT_OK ( dbfull ( ) - > TEST_WaitForCompact ( ) ) ;
ASSERT_OK ( dbfull ( ) - > TEST_WaitForCompact ( ) ) ;
ASSERT_EQ ( NumTableFilesAtLevel ( 0 ) , 10 ) ;
ASSERT_EQ ( NumTableFilesAtLevel ( 0 ) , 10 ) ;
@ -3647,7 +3646,7 @@ TEST_F(DBTest, FIFOCompactionWithTTLTest) {
ASSERT_EQ ( NumTableFilesAtLevel ( 0 ) , 3 ) ;
ASSERT_EQ ( NumTableFilesAtLevel ( 0 ) , 3 ) ;
// Sleep for 2 hours -- which is much greater than TTL.
// Sleep for 2 hours -- which is much greater than TTL.
env_ - > addon_time_ . fetch_add ( 2 * 60 * 60 ) ;
env_ - > MockSleepForSeconds ( 2 * 60 * 60 ) ;
// Just to make sure that we are in the same state even after sleeping.
// Just to make sure that we are in the same state even after sleeping.
ASSERT_OK ( dbfull ( ) - > TEST_WaitForCompact ( ) ) ;
ASSERT_OK ( dbfull ( ) - > TEST_WaitForCompact ( ) ) ;
ASSERT_EQ ( NumTableFilesAtLevel ( 0 ) , 3 ) ;
ASSERT_EQ ( NumTableFilesAtLevel ( 0 ) , 3 ) ;
@ -3688,7 +3687,7 @@ TEST_F(DBTest, FIFOCompactionWithTTLTest) {
ASSERT_EQ ( NumTableFilesAtLevel ( 0 ) , 5 ) ;
ASSERT_EQ ( NumTableFilesAtLevel ( 0 ) , 5 ) ;
// Sleep for 2 hours -- which is much greater than TTL.
// Sleep for 2 hours -- which is much greater than TTL.
env_ - > addon_time_ . fetch_add ( 2 * 60 * 60 ) ;
env_ - > MockSleepForSeconds ( 2 * 60 * 60 ) ;
// Just to make sure that we are in the same state even after sleeping.
// Just to make sure that we are in the same state even after sleeping.
ASSERT_OK ( dbfull ( ) - > TEST_WaitForCompact ( ) ) ;
ASSERT_OK ( dbfull ( ) - > TEST_WaitForCompact ( ) ) ;
ASSERT_EQ ( NumTableFilesAtLevel ( 0 ) , 5 ) ;
ASSERT_EQ ( NumTableFilesAtLevel ( 0 ) , 5 ) ;
@ -5444,9 +5443,10 @@ class DelayedMergeOperator : public MergeOperator {
public :
public :
explicit DelayedMergeOperator ( DBTest * d ) : db_test_ ( d ) { }
explicit DelayedMergeOperator ( DBTest * d ) : db_test_ ( d ) { }
bool FullMergeV2 ( const MergeOperationInput & /*merge_in*/ ,
bool FullMergeV2 ( const MergeOperationInput & merge_in ,
MergeOperationOutput * merge_out ) const override {
MergeOperationOutput * merge_out ) const override {
db_test_ - > env_ - > addon_time_ . fetch_add ( 1000 ) ;
db_test_ - > env_ - > MockSleepForMicroseconds ( 1000 *
merge_in . operand_list . size ( ) ) ;
merge_out - > new_value = " " ;
merge_out - > new_value = " " ;
return true ;
return true ;
}
}
@ -5454,8 +5454,6 @@ class DelayedMergeOperator : public MergeOperator {
const char * Name ( ) const override { return " DelayedMergeOperator " ; }
const char * Name ( ) const override { return " DelayedMergeOperator " ; }
} ;
} ;
// TODO: hangs in CircleCI's Windows env
# ifndef OS_WIN
TEST_F ( DBTest , MergeTestTime ) {
TEST_F ( DBTest , MergeTestTime ) {
std : : string one , two , three ;
std : : string one , two , three ;
PutFixed64 ( & one , 1 ) ;
PutFixed64 ( & one , 1 ) ;
@ -5464,14 +5462,14 @@ TEST_F(DBTest, MergeTestTime) {
// Enable time profiling
// Enable time profiling
SetPerfLevel ( kEnableTime ) ;
SetPerfLevel ( kEnableTime ) ;
this - > env_ - > addon_time_ . store ( 0 ) ;
this - > env_ - > time_elapse_only_sleep_ = true ;
this - > env_ - > no_slowdown_ = true ;
Options options = CurrentOptions ( ) ;
Options options = CurrentOptions ( ) ;
options . statistics = ROCKSDB_NAMESPACE : : CreateDBStatistics ( ) ;
options . statistics = ROCKSDB_NAMESPACE : : CreateDBStatistics ( ) ;
options . merge_operator . reset ( new DelayedMergeOperator ( this ) ) ;
options . merge_operator . reset ( new DelayedMergeOperator ( this ) ) ;
SetTimeElapseOnlySleepOnReopen ( & options ) ;
DestroyAndReopen ( options ) ;
DestroyAndReopen ( options ) ;
// NOTE: Presumed unnecessary and removed: resetting mock time in env
ASSERT_EQ ( TestGetTickerCount ( options , MERGE_OPERATION_TOTAL_TIME ) , 0 ) ;
ASSERT_EQ ( TestGetTickerCount ( options , MERGE_OPERATION_TOTAL_TIME ) , 0 ) ;
db_ - > Put ( WriteOptions ( ) , " foo " , one ) ;
db_ - > Put ( WriteOptions ( ) , " foo " , one ) ;
ASSERT_OK ( Flush ( ) ) ;
ASSERT_OK ( Flush ( ) ) ;
@ -5486,7 +5484,7 @@ TEST_F(DBTest, MergeTestTime) {
std : : string result ;
std : : string result ;
db_ - > Get ( opt , " foo " , & result ) ;
db_ - > Get ( opt , " foo " , & result ) ;
ASSERT_EQ ( 1 000000, TestGetTickerCount ( options , MERGE_OPERATION_TOTAL_TIME ) ) ;
ASSERT_EQ ( 2 000000, TestGetTickerCount ( options , MERGE_OPERATION_TOTAL_TIME ) ) ;
ReadOptions read_options ;
ReadOptions read_options ;
std : : unique_ptr < Iterator > iter ( db_ - > NewIterator ( read_options ) ) ;
std : : unique_ptr < Iterator > iter ( db_ - > NewIterator ( read_options ) ) ;
@ -5497,13 +5495,11 @@ TEST_F(DBTest, MergeTestTime) {
}
}
ASSERT_EQ ( 1 , count ) ;
ASSERT_EQ ( 1 , count ) ;
ASSERT_EQ ( 2 000000, TestGetTickerCount ( options , MERGE_OPERATION_TOTAL_TIME ) ) ;
ASSERT_EQ ( 4 000000, TestGetTickerCount ( options , MERGE_OPERATION_TOTAL_TIME ) ) ;
# ifdef ROCKSDB_USING_THREAD_STATUS
# ifdef ROCKSDB_USING_THREAD_STATUS
ASSERT_GT ( TestGetTickerCount ( options , FLUSH_WRITE_BYTES ) , 0 ) ;
ASSERT_GT ( TestGetTickerCount ( options , FLUSH_WRITE_BYTES ) , 0 ) ;
# endif // ROCKSDB_USING_THREAD_STATUS
# endif // ROCKSDB_USING_THREAD_STATUS
this - > env_ - > time_elapse_only_sleep_ = false ;
}
}
# endif // OS_WIN
# ifndef ROCKSDB_LITE
# ifndef ROCKSDB_LITE
TEST_P ( DBTestWithParam , MergeCompactionTimeTest ) {
TEST_P ( DBTestWithParam , MergeCompactionTimeTest ) {
@ -5513,18 +5509,24 @@ TEST_P(DBTestWithParam, MergeCompactionTimeTest) {
options . compaction_filter_factory = std : : make_shared < KeepFilterFactory > ( ) ;
options . compaction_filter_factory = std : : make_shared < KeepFilterFactory > ( ) ;
options . statistics = ROCKSDB_NAMESPACE : : CreateDBStatistics ( ) ;
options . statistics = ROCKSDB_NAMESPACE : : CreateDBStatistics ( ) ;
options . merge_operator . reset ( new DelayedMergeOperator ( this ) ) ;
options . merge_operator . reset ( new DelayedMergeOperator ( this ) ) ;
options . compaction_style = kCompactionStyleUniversal ;
options . disable_auto_compactions = true ;
options . max_subcompactions = max_subcompactions_ ;
options . max_subcompactions = max_subcompactions_ ;
SetTimeElapseOnlySleepOnReopen ( & options ) ;
DestroyAndReopen ( options ) ;
DestroyAndReopen ( options ) ;
for ( int i = 0 ; i < 1000 ; i + + ) {
constexpr unsigned n = 1000 ;
for ( unsigned i = 0 ; i < n ; i + + ) {
ASSERT_OK ( db_ - > Merge ( WriteOptions ( ) , " foo " , " TEST " ) ) ;
ASSERT_OK ( db_ - > Merge ( WriteOptions ( ) , " foo " , " TEST " ) ) ;
ASSERT_OK ( Flush ( ) ) ;
ASSERT_OK ( Flush ( ) ) ;
}
}
dbfull ( ) - > TEST_WaitForFlushMemTable ( ) ;
dbfull ( ) - > TEST_WaitForFlushMemTable ( ) ;
dbfull ( ) - > TEST_WaitForCompact ( ) ;
ASSERT_NE ( TestGetTickerCount ( options , MERGE_OPERATION_TOTAL_TIME ) , 0 ) ;
CompactRangeOptions cro ;
cro . exclusive_manual_compaction = exclusive_manual_compaction_ ;
ASSERT_OK ( db_ - > CompactRange ( cro , nullptr , nullptr ) ) ;
ASSERT_EQ ( uint64_t { n } * 1000000U ,
TestGetTickerCount ( options , MERGE_OPERATION_TOTAL_TIME ) ) ;
}
}
TEST_P ( DBTestWithParam , FilterCompactionTimeTest ) {
TEST_P ( DBTestWithParam , FilterCompactionTimeTest ) {
@ -5536,12 +5538,15 @@ TEST_P(DBTestWithParam, FilterCompactionTimeTest) {
options . statistics = ROCKSDB_NAMESPACE : : CreateDBStatistics ( ) ;
options . statistics = ROCKSDB_NAMESPACE : : CreateDBStatistics ( ) ;
options . statistics - > set_stats_level ( kExceptTimeForMutex ) ;
options . statistics - > set_stats_level ( kExceptTimeForMutex ) ;
options . max_subcompactions = max_subcompactions_ ;
options . max_subcompactions = max_subcompactions_ ;
SetTimeElapseOnlySleepOnReopen ( & options ) ;
DestroyAndReopen ( options ) ;
DestroyAndReopen ( options ) ;
unsigned n = 0 ;
// put some data
// put some data
for ( int table = 0 ; table < 4 ; + + table ) {
for ( int table = 0 ; table < 4 ; + + table ) {
for ( int i = 0 ; i < 10 + table ; + + i ) {
for ( int i = 0 ; i < 10 + table ; + + i ) {
Put ( ToString ( table * 100 + i ) , " val " ) ;
Put ( ToString ( table * 100 + i ) , " val " ) ;
+ + n ;
}
}
Flush ( ) ;
Flush ( ) ;
}
}
@ -5555,7 +5560,8 @@ TEST_P(DBTestWithParam, FilterCompactionTimeTest) {
Iterator * itr = db_ - > NewIterator ( ReadOptions ( ) ) ;
Iterator * itr = db_ - > NewIterator ( ReadOptions ( ) ) ;
itr - > SeekToFirst ( ) ;
itr - > SeekToFirst ( ) ;
ASSERT_NE ( TestGetTickerCount ( options , FILTER_OPERATION_TOTAL_TIME ) , 0 ) ;
ASSERT_EQ ( uint64_t { n } * 1000000U ,
TestGetTickerCount ( options , FILTER_OPERATION_TOTAL_TIME ) ) ;
delete itr ;
delete itr ;
}
}
# endif // ROCKSDB_LITE
# endif // ROCKSDB_LITE
@ -6007,7 +6013,6 @@ TEST_F(DBTest, DelayedWriteRate) {
Options options = CurrentOptions ( ) ;
Options options = CurrentOptions ( ) ;
env_ - > SetBackgroundThreads ( 1 , Env : : LOW ) ;
env_ - > SetBackgroundThreads ( 1 , Env : : LOW ) ;
options . env = env_ ;
options . env = env_ ;
env_ - > no_slowdown_ = true ;
options . write_buffer_size = 100000000 ;
options . write_buffer_size = 100000000 ;
options . max_write_buffer_number = 256 ;
options . max_write_buffer_number = 256 ;
options . max_background_compactions = 1 ;
options . max_background_compactions = 1 ;
@ -6018,6 +6023,7 @@ TEST_F(DBTest, DelayedWriteRate) {
options . memtable_factory . reset (
options . memtable_factory . reset (
new SpecialSkipListFactory ( kEntriesPerMemTable ) ) ;
new SpecialSkipListFactory ( kEntriesPerMemTable ) ) ;
SetTimeElapseOnlySleepOnReopen ( & options ) ;
CreateAndReopenWithCF ( { " pikachu " } , options ) ;
CreateAndReopenWithCF ( { " pikachu " } , options ) ;
// Block compactions
// Block compactions
@ -6056,12 +6062,9 @@ TEST_F(DBTest, DelayedWriteRate) {
kIncSlowdownRatio * kIncSlowdownRatio ) ;
kIncSlowdownRatio * kIncSlowdownRatio ) ;
}
}
// Estimate the total sleep time fall into the rough range.
// Estimate the total sleep time fall into the rough range.
ASSERT_GT ( env_ - > addon_time_ . load ( ) ,
ASSERT_GT ( env_ - > NowMicros ( ) , estimated_sleep_time / 2 ) ;
static_cast < int64_t > ( estimated_sleep_time / 2 ) ) ;
ASSERT_LT ( env_ - > NowMicros ( ) , estimated_sleep_time * 2 ) ;
ASSERT_LT ( env_ - > addon_time_ . load ( ) ,
static_cast < int64_t > ( estimated_sleep_time * 2 ) ) ;
env_ - > no_slowdown_ = false ;
ROCKSDB_NAMESPACE : : SyncPoint : : GetInstance ( ) - > DisableProcessing ( ) ;
ROCKSDB_NAMESPACE : : SyncPoint : : GetInstance ( ) - > DisableProcessing ( ) ;
sleeping_task_low . WakeUp ( ) ;
sleeping_task_low . WakeUp ( ) ;
sleeping_task_low . WaitUntilDone ( ) ;
sleeping_task_low . WaitUntilDone ( ) ;
@ -6575,10 +6578,11 @@ TEST_F(DBTest, CreationTimeOfOldestFile) {
Options options = CurrentOptions ( ) ;
Options options = CurrentOptions ( ) ;
options . max_open_files = - 1 ;
options . max_open_files = - 1 ;
env_ - > time_elapse_only_sleep_ = false ;
env_ - > SetMockSleep ( ) ;
options . env = env_ ;
options . env = env_ ;
env_ - > addon_time_ . store ( 0 ) ;
// NOTE: Presumed unnecessary and removed: resetting mock time in env
DestroyAndReopen ( options ) ;
DestroyAndReopen ( options ) ;
bool set_file_creation_time_to_zero = true ;
bool set_file_creation_time_to_zero = true ;
@ -6589,7 +6593,7 @@ TEST_F(DBTest, CreationTimeOfOldestFile) {
const uint64_t uint_time_1 = static_cast < uint64_t > ( time_1 ) ;
const uint64_t uint_time_1 = static_cast < uint64_t > ( time_1 ) ;
// Add 50 hours
// Add 50 hours
env_ - > addon_time_ . fetch_add ( 50 * 60 * 60 ) ;
env_ - > MockSleepForSeconds ( 50 * 60 * 60 ) ;
int64_t time_2 = 0 ;
int64_t time_2 = 0 ;
env_ - > GetCurrentTime ( & time_2 ) ;
env_ - > GetCurrentTime ( & time_2 ) ;
@ -6643,10 +6647,10 @@ TEST_F(DBTest, CreationTimeOfOldestFile) {
set_file_creation_time_to_zero = false ;
set_file_creation_time_to_zero = false ;
options = CurrentOptions ( ) ;
options = CurrentOptions ( ) ;
options . max_open_files = - 1 ;
options . max_open_files = - 1 ;
env_ - > time_elapse_only_sleep_ = false ;
options . env = env_ ;
options . env = env_ ;
env_ - > addon_time_ . store ( 0 ) ;
// NOTE: Presumed unnecessary and removed: resetting mock time in env
DestroyAndReopen ( options ) ;
DestroyAndReopen ( options ) ;
for ( int i = 0 ; i < kNumLevelFiles ; + + i ) {
for ( int i = 0 ; i < kNumLevelFiles ; + + i ) {