@ -54,6 +54,8 @@ int main() {
# include "rocksdb/slice.h"
# include "rocksdb/slice.h"
# include "rocksdb/slice_transform.h"
# include "rocksdb/slice_transform.h"
# include "rocksdb/statistics.h"
# include "rocksdb/statistics.h"
# include "rocksdb/utilities/backupable_db.h"
# include "rocksdb/utilities/checkpoint.h"
# include "rocksdb/utilities/db_ttl.h"
# include "rocksdb/utilities/db_ttl.h"
# include "rocksdb/utilities/options_util.h"
# include "rocksdb/utilities/options_util.h"
# include "rocksdb/utilities/transaction.h"
# include "rocksdb/utilities/transaction.h"
@ -382,6 +384,16 @@ DEFINE_bool(use_txn, false,
" Use TransactionDB. Currently the default write policy is "
" Use TransactionDB. Currently the default write policy is "
" TxnDBWritePolicy::WRITE_PREPARED " ) ;
" TxnDBWritePolicy::WRITE_PREPARED " ) ;
DEFINE_int32 ( backup_one_in , 0 ,
" If non-zero, then CreateNewBackup() will be called once for "
" every N operations on average. 0 indicates CreateNewBackup() "
" is disabled. " ) ;
DEFINE_int32 ( checkpoint_one_in , 0 ,
" If non-zero, then CreateCheckpoint() will be called once for "
" every N operations on average. 0 indicates CreateCheckpoint() "
" is disabled. " ) ;
DEFINE_int32 ( compact_files_one_in , 0 ,
DEFINE_int32 ( compact_files_one_in , 0 ,
" If non-zero, then CompactFiles() will be called once for every N "
" If non-zero, then CompactFiles() will be called once for every N "
" operations on average. 0 indicates CompactFiles() is disabled. " ) ;
" operations on average. 0 indicates CompactFiles() is disabled. " ) ;
@ -1756,7 +1768,54 @@ class StressTest {
MaybeClearOneColumnFamily ( thread ) ;
MaybeClearOneColumnFamily ( thread ) ;
# ifndef ROCKSDB_LITE // Lite does not support GetColumnFamilyMetaData
# ifndef ROCKSDB_LITE
if ( FLAGS_checkpoint_one_in > 0 & &
thread - > rand . Uniform ( FLAGS_checkpoint_one_in ) = = 0 ) {
std : : string checkpoint_dir =
FLAGS_db + " /.checkpoint " + ToString ( thread - > tid ) ;
Checkpoint * checkpoint ;
Status s = Checkpoint : : Create ( db_ , & checkpoint ) ;
if ( s . ok ( ) ) {
s = checkpoint - > CreateCheckpoint ( checkpoint_dir ) ;
}
std : : vector < std : : string > files ;
if ( s . ok ( ) ) {
s = FLAGS_env - > GetChildren ( checkpoint_dir , & files ) ;
}
size_t file_idx = 0 ;
while ( s . ok ( ) & & file_idx < files . size ( ) ) {
if ( files [ file_idx ] ! = " . " & & files [ file_idx ] ! = " .. " ) {
s = FLAGS_env - > DeleteFile ( checkpoint_dir + " / " + files [ file_idx ] ) ;
}
+ + file_idx ;
}
if ( s . ok ( ) ) {
s = FLAGS_env - > DeleteDir ( checkpoint_dir ) ;
}
if ( ! s . ok ( ) ) {
printf ( " A checkpoint operation failed with: %s \n " ,
s . ToString ( ) . c_str ( ) ) ;
}
}
if ( FLAGS_backup_one_in > 0 & &
thread - > rand . Uniform ( FLAGS_backup_one_in ) = = 0 ) {
std : : string backup_dir = FLAGS_db + " /.backup " + ToString ( thread - > tid ) ;
BackupableDBOptions backup_opts ( backup_dir ) ;
BackupEngine * backup_engine ;
Status s = BackupEngine : : Open ( FLAGS_env , backup_opts , & backup_engine ) ;
if ( s . ok ( ) ) {
s = backup_engine - > CreateNewBackup ( db_ ) ;
}
if ( s . ok ( ) ) {
s = backup_engine - > PurgeOldBackups ( 0 /* num_backups_to_keep */ ) ;
}
if ( ! s . ok ( ) ) {
printf ( " A BackupEngine operation failed with: %s \n " ,
s . ToString ( ) . c_str ( ) ) ;
}
}
if ( FLAGS_compact_files_one_in > 0 & &
if ( FLAGS_compact_files_one_in > 0 & &
thread - > rand . Uniform ( FLAGS_compact_files_one_in ) = = 0 ) {
thread - > rand . Uniform ( FLAGS_compact_files_one_in ) = = 0 ) {
auto * random_cf =
auto * random_cf =