@ -32,17 +32,15 @@ StressTest::StressTest()
cmp_db_ ( nullptr ) {
if ( FLAGS_destroy_db_initially ) {
std : : vector < std : : string > files ;
FLAGS _env- > GetChildren ( FLAGS_db , & files ) ;
db_stress _env- > GetChildren ( FLAGS_db , & files ) ;
for ( unsigned int i = 0 ; i < files . size ( ) ; i + + ) {
if ( Slice ( files [ i ] ) . starts_with ( " heap- " ) ) {
FLAGS _env- > DeleteFile ( FLAGS_db + " / " + files [ i ] ) ;
db_stress _env- > DeleteFile ( FLAGS_db + " / " + files [ i ] ) ;
}
}
Options options ;
// Remove files without preserving manfiest files
options . env = FLAGS_env - > target ( ) ;
# ifndef ROCKSDB_LITE
const Status s = ! FLAGS_use_blob_db
? DestroyDB ( FLAGS_db , options )
@ -187,28 +185,28 @@ bool StressTest::BuildOptionsTable() {
}
void StressTest : : InitDb ( ) {
uint64_t now = FLAGS _env- > NowMicros ( ) ;
uint64_t now = db_stress _env- > NowMicros ( ) ;
fprintf ( stdout , " %s Initializing db_stress \n " ,
FLAGS _env- > TimeToString ( now / 1000000 ) . c_str ( ) ) ;
db_stress _env- > TimeToString ( now / 1000000 ) . c_str ( ) ) ;
PrintEnv ( ) ;
Open ( ) ;
BuildOptionsTable ( ) ;
}
void StressTest : : InitReadonlyDb ( SharedState * shared ) {
uint64_t now = FLAGS _env- > NowMicros ( ) ;
uint64_t now = db_stress _env- > NowMicros ( ) ;
fprintf ( stdout , " %s Preloading db with % " PRIu64 " KVs \n " ,
FLAGS _env- > TimeToString ( now / 1000000 ) . c_str ( ) , FLAGS_max_key ) ;
db_stress _env- > TimeToString ( now / 1000000 ) . c_str ( ) , FLAGS_max_key ) ;
PreloadDbAndReopenAsReadOnly ( FLAGS_max_key , shared ) ;
}
bool StressTest : : VerifySecondaries ( ) {
# ifndef ROCKSDB_LITE
if ( FLAGS_test_secondary ) {
uint64_t now = FLAGS _env- > NowMicros ( ) ;
uint64_t now = db_stress _env- > NowMicros ( ) ;
fprintf (
stdout , " %s Start to verify secondaries against primary \n " ,
FLAGS _env- > TimeToString ( static_cast < uint64_t > ( now ) / 1000000 ) . c_str ( ) ) ;
db_stress _env- > TimeToString ( static_cast < uint64_t > ( now ) / 1000000 ) . c_str ( ) ) ;
}
for ( size_t k = 0 ; k ! = secondaries_ . size ( ) ; + + k ) {
Status s = secondaries_ [ k ] - > TryCatchUpWithPrimary ( ) ;
@ -250,10 +248,10 @@ bool StressTest::VerifySecondaries() {
}
}
if ( FLAGS_test_secondary ) {
uint64_t now = FLAGS _env- > NowMicros ( ) ;
uint64_t now = db_stress _env- > NowMicros ( ) ;
fprintf (
stdout , " %s Verification of secondaries succeeded \n " ,
FLAGS _env- > TimeToString ( static_cast < uint64_t > ( now ) / 1000000 ) . c_str ( ) ) ;
db_stress _env- > TimeToString ( static_cast < uint64_t > ( now ) / 1000000 ) . c_str ( ) ) ;
}
# endif // ROCKSDB_LITE
return true ;
@ -410,9 +408,9 @@ void StressTest::PreloadDbAndReopenAsReadOnly(int64_t number_of_keys,
# endif
db_preload_finished_ . store ( true ) ;
auto now = FLAGS _env- > NowMicros ( ) ;
auto now = db_stress _env- > NowMicros ( ) ;
fprintf ( stdout , " %s Reopening database in read-only \n " ,
FLAGS _env- > TimeToString ( now / 1000000 ) . c_str ( ) ) ;
db_stress _env- > TimeToString ( now / 1000000 ) . c_str ( ) ) ;
// Reopen as read-only, can ignore all options related to updates
Open ( ) ;
} else {
@ -1134,14 +1132,14 @@ Status StressTest::TestBackupRestore(
std : : string restore_dir = FLAGS_db + " /.restore " + ToString ( thread - > tid ) ;
BackupableDBOptions backup_opts ( backup_dir ) ;
BackupEngine * backup_engine = nullptr ;
Status s = BackupEngine : : Open ( FLAGS _env, backup_opts , & backup_engine ) ;
Status s = BackupEngine : : Open ( db_stress _env, backup_opts , & backup_engine ) ;
if ( s . ok ( ) ) {
s = backup_engine - > CreateNewBackup ( db_ ) ;
}
if ( s . ok ( ) ) {
delete backup_engine ;
backup_engine = nullptr ;
s = BackupEngine : : Open ( FLAGS _env, backup_opts , & backup_engine ) ;
s = BackupEngine : : Open ( db_stress _env, backup_opts , & backup_engine ) ;
}
if ( s . ok ( ) ) {
s = backup_engine - > RestoreDBFromLatestBackup ( restore_dir /* db_dir */ ,
@ -1218,7 +1216,7 @@ Status StressTest::TestCheckpoint(ThreadState* thread,
FLAGS_db + " /.checkpoint " + ToString ( thread - > tid ) ;
Options tmp_opts ( options_ ) ;
tmp_opts . listeners . clear ( ) ;
tmp_opts . env = FLAGS _env- > target ( ) ;
tmp_opts . env = db_stress _env- > target ( ) ;
DestroyDB ( checkpoint_dir , tmp_opts ) ;
@ -1355,7 +1353,7 @@ Status StressTest::TestPauseBackground(ThreadState* thread) {
// 1 chance in 625 of pausing full 16s.)
int pwr2_micros =
std : : min ( thread - > rand . Uniform ( 25 ) , thread - > rand . Uniform ( 25 ) ) ;
FLAGS _env- > SleepForMicroseconds ( 1 < < pwr2_micros ) ;
db_stress _env- > SleepForMicroseconds ( 1 < < pwr2_micros ) ;
return db_ - > ContinueBackgroundWork ( ) ;
}
@ -1573,9 +1571,13 @@ void StressTest::PrintEnv() const {
fprintf ( stdout , " Do update in place : %d \n " , FLAGS_in_place_update ) ;
fprintf ( stdout , " Num keys per lock : %d \n " ,
1 < < FLAGS_log2_keys_per_lock ) ;
std : : string compression = CompressionTypeToString ( FLAGS_ compression_type_e) ;
std : : string compression = CompressionTypeToString ( compression_type_e ) ;
fprintf ( stdout , " Compression : %s \n " , compression . c_str ( ) ) ;
std : : string checksum = ChecksumTypeToString ( FLAGS_checksum_type_e ) ;
std : : string bottommost_compression =
CompressionTypeToString ( bottommost_compression_type_e ) ;
fprintf ( stdout , " Bottommost Compression : %s \n " ,
bottommost_compression . c_str ( ) ) ;
std : : string checksum = ChecksumTypeToString ( checksum_type_e ) ;
fprintf ( stdout , " Checksum type : %s \n " , checksum . c_str ( ) ) ;
fprintf ( stdout , " Bloom bits / key : %s \n " ,
FormatDoubleParam ( FLAGS_bloom_bits ) . c_str ( ) ) ;
@ -1633,7 +1635,7 @@ void StressTest::Open() {
block_based_options . cache_index_and_filter_blocks =
FLAGS_cache_index_and_filter_blocks ;
block_based_options . block_cache_compressed = compressed_cache_ ;
block_based_options . checksum = FLAGS_ checksum_type_e;
block_based_options . checksum = checksum_type_e ;
block_based_options . block_size = FLAGS_block_size ;
block_based_options . format_version =
static_cast < uint32_t > ( FLAGS_format_version ) ;
@ -1667,7 +1669,7 @@ void StressTest::Open() {
}
options_ . max_open_files = FLAGS_open_files ;
options_ . statistics = dbstats ;
options_ . env = FLAGS _env;
options_ . env = db_stress _env;
options_ . use_fsync = FLAGS_use_fsync ;
options_ . compaction_readahead_size = FLAGS_compaction_readahead_size ;
options_ . allow_mmap_reads = FLAGS_mmap_read ;
@ -1687,7 +1689,8 @@ void StressTest::Open() {
FLAGS_level0_slowdown_writes_trigger ;
options_ . level0_file_num_compaction_trigger =
FLAGS_level0_file_num_compaction_trigger ;
options_ . compression = FLAGS_compression_type_e ;
options_ . compression = compression_type_e ;
options_ . bottommost_compression = bottommost_compression_type_e ;
options_ . compression_opts . max_dict_bytes = FLAGS_compression_max_dict_bytes ;
options_ . compression_opts . zstd_max_train_bytes =
FLAGS_compression_zstd_max_train_bytes ;
@ -1725,9 +1728,9 @@ void StressTest::Open() {
# else
DBOptions db_options ;
std : : vector < ColumnFamilyDescriptor > cf_descriptors ;
Status s = LoadOptionsFromFile ( FLAGS_options_file , FLAGS_env , & db_options ,
& cf_descriptors ) ;
db_options . env = new DbStressEnvWrapper ( FLAGS _env) ;
Status s = LoadOptionsFromFile ( FLAGS_options_file , db_stress_env ,
& db_options , & cf_descriptors ) ;
db_options . env = new DbStressEnvWrapper ( db_stress _env) ;
if ( ! s . ok ( ) ) {
fprintf ( stderr , " Unable to load options file %s --- %s \n " ,
FLAGS_options_file . c_str ( ) , s . ToString ( ) . c_str ( ) ) ;
@ -1912,7 +1915,7 @@ void StressTest::Open() {
// TODO(yanqin) support max_open_files != -1 for secondary instance.
tmp_opts . max_open_files = - 1 ;
tmp_opts . statistics = dbstats_secondaries ;
tmp_opts . env = FLAGS _env;
tmp_opts . env = db_stress _env;
for ( size_t i = 0 ; i ! = static_cast < size_t > ( FLAGS_threads ) ; + + i ) {
const std : : string secondary_path =
FLAGS_secondaries_base + " / " + std : : to_string ( i ) ;
@ -1933,7 +1936,7 @@ void StressTest::Open() {
Options tmp_opts ;
// TODO(yanqin) support max_open_files != -1 for secondary instance.
tmp_opts . max_open_files = - 1 ;
tmp_opts . env = FLAGS _env;
tmp_opts . env = db_stress _env;
std : : string secondary_path = FLAGS_secondaries_base + " /cmp_database " ;
s = DB : : OpenAsSecondary ( tmp_opts , FLAGS_db , secondary_path ,
cf_descriptors , & cmp_cfhs_ , & cmp_db_ ) ;
@ -2020,9 +2023,10 @@ void StressTest::Reopen(ThreadState* thread) {
secondaries_ . clear ( ) ;
num_times_reopened_ + + ;
auto now = FLAGS _env- > NowMicros ( ) ;
auto now = db_stress _env- > NowMicros ( ) ;
fprintf ( stdout , " %s Reopening database for the %dth time \n " ,
FLAGS_env - > TimeToString ( now / 1000000 ) . c_str ( ) , num_times_reopened_ ) ;
db_stress_env - > TimeToString ( now / 1000000 ) . c_str ( ) ,
num_times_reopened_ ) ;
Open ( ) ;
}
} // namespace rocksdb