@ -45,6 +45,7 @@
namespace rocksdb {
namespace rocksdb {
const std : : string LDBCommand : : ARG_ENV_URI = " env_uri " ;
const std : : string LDBCommand : : ARG_DB = " db " ;
const std : : string LDBCommand : : ARG_DB = " db " ;
const std : : string LDBCommand : : ARG_PATH = " path " ;
const std : : string LDBCommand : : ARG_PATH = " path " ;
const std : : string LDBCommand : : ARG_SECONDARY_PATH = " secondary_path " ;
const std : : string LDBCommand : : ARG_SECONDARY_PATH = " secondary_path " ;
@ -274,6 +275,17 @@ void LDBCommand::Run() {
return ;
return ;
}
}
if ( ! options_ . env | | options_ . env = = Env : : Default ( ) ) {
Env * env = Env : : Default ( ) ;
Status s = Env : : LoadEnv ( env_uri_ , & env , & env_guard_ ) ;
if ( ! s . ok ( ) & & ! s . IsNotFound ( ) ) {
fprintf ( stderr , " LoadEnv: %s \n " , s . ToString ( ) . c_str ( ) ) ;
exec_state_ = LDBCommandExecuteResult : : Failed ( s . ToString ( ) ) ;
return ;
}
options_ . env = env ;
}
if ( db_ = = nullptr & & ! NoDBOpen ( ) ) {
if ( db_ = = nullptr & & ! NoDBOpen ( ) ) {
OpenDB ( ) ;
OpenDB ( ) ;
if ( exec_state_ . IsFailed ( ) & & try_load_options_ ) {
if ( exec_state_ . IsFailed ( ) & & try_load_options_ ) {
@ -318,6 +330,11 @@ LDBCommand::LDBCommand(const std::map<std::string, std::string>& options,
db_path_ = itr - > second ;
db_path_ = itr - > second ;
}
}
itr = options . find ( ARG_ENV_URI ) ;
if ( itr ! = options . end ( ) ) {
env_uri_ = itr - > second ;
}
itr = options . find ( ARG_CF_NAME ) ;
itr = options . find ( ARG_CF_NAME ) ;
if ( itr ! = options . end ( ) ) {
if ( itr ! = options . end ( ) ) {
column_family_name_ = itr - > second ;
column_family_name_ = itr - > second ;
@ -341,7 +358,7 @@ LDBCommand::LDBCommand(const std::map<std::string, std::string>& options,
void LDBCommand : : OpenDB ( ) {
void LDBCommand : : OpenDB ( ) {
if ( ! create_if_missing_ & & try_load_options_ ) {
if ( ! create_if_missing_ & & try_load_options_ ) {
Status s = LoadLatestOptions ( db_path_ , Env : : Default ( ) , & options_ ,
Status s = LoadLatestOptions ( db_path_ , options_ . env , & options_ ,
& column_families_ , ignore_unknown_options_ ) ;
& column_families_ , ignore_unknown_options_ ) ;
if ( ! s . ok ( ) & & ! s . IsNotFound ( ) ) {
if ( ! s . ok ( ) & & ! s . IsNotFound ( ) ) {
// Option file exists but load option file error.
// Option file exists but load option file error.
@ -397,7 +414,7 @@ void LDBCommand::OpenDB() {
if ( column_families_ . empty ( ) ) {
if ( column_families_ . empty ( ) ) {
// Try to figure out column family lists
// Try to figure out column family lists
std : : vector < std : : string > cf_list ;
std : : vector < std : : string > cf_list ;
st = DB : : ListColumnFamilies ( DBOptions ( ) , db_path_ , & cf_list ) ;
st = DB : : ListColumnFamilies ( options_ , db_path_ , & cf_list ) ;
// There is possible the DB doesn't exist yet, for "create if not
// There is possible the DB doesn't exist yet, for "create if not
// "existing case". The failure is ignored here. We rely on DB::Open()
// "existing case". The failure is ignored here. We rely on DB::Open()
// to give us the correct error message for problem with opening
// to give us the correct error message for problem with opening
@ -487,7 +504,8 @@ ColumnFamilyHandle* LDBCommand::GetCfHandle() {
std : : vector < std : : string > LDBCommand : : BuildCmdLineOptions (
std : : vector < std : : string > LDBCommand : : BuildCmdLineOptions (
std : : vector < std : : string > options ) {
std : : vector < std : : string > options ) {
std : : vector < std : : string > ret = { ARG_DB ,
std : : vector < std : : string > ret = { ARG_ENV_URI ,
ARG_DB ,
ARG_SECONDARY_PATH ,
ARG_SECONDARY_PATH ,
ARG_BLOOM_BITS ,
ARG_BLOOM_BITS ,
ARG_BLOCK_SIZE ,
ARG_BLOCK_SIZE ,
@ -1095,31 +1113,23 @@ void ManifestDumpCommand::DoCommand() {
void ListColumnFamiliesCommand : : Help ( std : : string & ret ) {
void ListColumnFamiliesCommand : : Help ( std : : string & ret ) {
ret . append ( " " ) ;
ret . append ( " " ) ;
ret . append ( ListColumnFamiliesCommand : : Name ( ) ) ;
ret . append ( ListColumnFamiliesCommand : : Name ( ) ) ;
ret . append ( " full_path_to_db_directory " ) ;
ret . append ( " \n " ) ;
ret . append ( " \n " ) ;
}
}
ListColumnFamiliesCommand : : ListColumnFamiliesCommand (
ListColumnFamiliesCommand : : ListColumnFamiliesCommand (
const std : : vector < std : : string > & params ,
const std : : vector < std : : string > & /*params*/ ,
const std : : map < std : : string , std : : string > & options ,
const std : : map < std : : string , std : : string > & options ,
const std : : vector < std : : string > & flags )
const std : : vector < std : : string > & flags )
: LDBCommand ( options , flags , false , { } ) {
: LDBCommand ( options , flags , false , BuildCmdLineOptions ( { } ) ) { }
if ( params . size ( ) ! = 1 ) {
exec_state_ = LDBCommandExecuteResult : : Failed (
" dbname must be specified for the list_column_families command " ) ;
} else {
dbname_ = params [ 0 ] ;
}
}
void ListColumnFamiliesCommand : : DoCommand ( ) {
void ListColumnFamiliesCommand : : DoCommand ( ) {
std : : vector < std : : string > column_families ;
std : : vector < std : : string > column_families ;
Status s = DB : : ListColumnFamilies ( DBOptions ( ) , dbname _, & column_families ) ;
Status s = DB : : ListColumnFamilies ( options_ , db_path_ , & column_families ) ;
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {
printf ( " Error in processing db %s %s \n " , dbname _ . c_str ( ) ,
printf ( " Error in processing db %s %s \n " , db_path_ . c_str ( ) ,
s . ToString ( ) . c_str ( ) ) ;
s . ToString ( ) . c_str ( ) ) ;
} else {
} else {
printf ( " Column families in %s: \n { " , dbname _ . c_str ( ) ) ;
printf ( " Column families in %s: \n { " , db_path _ . c_str ( ) ) ;
bool first = true ;
bool first = true ;
for ( auto cf : column_families ) {
for ( auto cf : column_families ) {
if ( ! first ) {
if ( ! first ) {
@ -2857,13 +2867,14 @@ void BackupCommand::DoCommand() {
}
}
printf ( " open db OK \n " ) ;
printf ( " open db OK \n " ) ;
Env * custom_env = nullptr ;
Env * custom_env = nullptr ;
Env : : LoadEnv ( backup_env_uri_ , & custom_env ) ;
Env : : LoadEnv ( backup_env_uri_ , & custom_env , & backup_env_guard_ ) ;
assert ( custom_env ! = nullptr ) ;
BackupableDBOptions backup_options =
BackupableDBOptions backup_options =
BackupableDBOptions ( backup_dir_ , custom_env ) ;
BackupableDBOptions ( backup_dir_ , custom_env ) ;
backup_options . info_log = logger_ . get ( ) ;
backup_options . info_log = logger_ . get ( ) ;
backup_options . max_background_operations = num_threads_ ;
backup_options . max_background_operations = num_threads_ ;
status = BackupEngine : : Open ( Env : : Default ( ) , backup_options , & backup_engine ) ;
status = BackupEngine : : Open ( custom_env , backup_options , & backup_engine ) ;
if ( status . ok ( ) ) {
if ( status . ok ( ) ) {
printf ( " open backup engine OK \n " ) ;
printf ( " open backup engine OK \n " ) ;
} else {
} else {
@ -2893,7 +2904,8 @@ void RestoreCommand::Help(std::string& ret) {
void RestoreCommand : : DoCommand ( ) {
void RestoreCommand : : DoCommand ( ) {
Env * custom_env = nullptr ;
Env * custom_env = nullptr ;
Env : : LoadEnv ( backup_env_uri_ , & custom_env ) ;
Env : : LoadEnv ( backup_env_uri_ , & custom_env , & backup_env_guard_ ) ;
assert ( custom_env ! = nullptr ) ;
std : : unique_ptr < BackupEngineReadOnly > restore_engine ;
std : : unique_ptr < BackupEngineReadOnly > restore_engine ;
Status status ;
Status status ;
@ -2902,8 +2914,8 @@ void RestoreCommand::DoCommand() {
opts . info_log = logger_ . get ( ) ;
opts . info_log = logger_ . get ( ) ;
opts . max_background_operations = num_threads_ ;
opts . max_background_operations = num_threads_ ;
BackupEngineReadOnly * raw_restore_engine_ptr ;
BackupEngineReadOnly * raw_restore_engine_ptr ;
status = BackupEngineReadOnly : : Open ( Env : : Default ( ) , opts ,
status =
& raw_restore_engine_ptr ) ;
BackupEngineReadOnly : : Open ( custom_env , opts , & raw_restore_engine_ptr ) ;
if ( status . ok ( ) ) {
if ( status . ok ( ) ) {
restore_engine . reset ( raw_restore_engine_ptr ) ;
restore_engine . reset ( raw_restore_engine_ptr ) ;
}
}