@ -45,6 +45,7 @@
namespace rocksdb {
const std : : string LDBCommand : : ARG_ENV_URI = " env_uri " ;
const std : : string LDBCommand : : ARG_DB = " db " ;
const std : : string LDBCommand : : ARG_PATH = " path " ;
const std : : string LDBCommand : : ARG_SECONDARY_PATH = " secondary_path " ;
@ -274,6 +275,17 @@ void LDBCommand::Run() {
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 ( ) ) {
OpenDB ( ) ;
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 ;
}
itr = options . find ( ARG_ENV_URI ) ;
if ( itr ! = options . end ( ) ) {
env_uri_ = itr - > second ;
}
itr = options . find ( ARG_CF_NAME ) ;
if ( itr ! = options . end ( ) ) {
column_family_name_ = itr - > second ;
@ -341,7 +358,7 @@ LDBCommand::LDBCommand(const std::map<std::string, std::string>& options,
void LDBCommand : : OpenDB ( ) {
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_ ) ;
if ( ! s . ok ( ) & & ! s . IsNotFound ( ) ) {
// Option file exists but load option file error.
@ -397,7 +414,7 @@ void LDBCommand::OpenDB() {
if ( column_families_ . empty ( ) ) {
// Try to figure out column family lists
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
// "existing case". The failure is ignored here. We rely on DB::Open()
// 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 > options ) {
std : : vector < std : : string > ret = { ARG_DB ,
std : : vector < std : : string > ret = { ARG_ENV_URI ,
ARG_DB ,
ARG_SECONDARY_PATH ,
ARG_BLOOM_BITS ,
ARG_BLOCK_SIZE ,
@ -1095,31 +1113,23 @@ void ManifestDumpCommand::DoCommand() {
void ListColumnFamiliesCommand : : Help ( std : : string & ret ) {
ret . append ( " " ) ;
ret . append ( ListColumnFamiliesCommand : : Name ( ) ) ;
ret . append ( " full_path_to_db_directory " ) ;
ret . append ( " \n " ) ;
}
ListColumnFamiliesCommand : : ListColumnFamiliesCommand (
const std : : vector < std : : string > & params ,
const std : : vector < std : : string > & /*params*/ ,
const std : : map < std : : string , std : : string > & options ,
const std : : vector < std : : string > & flags )
: LDBCommand ( options , flags , false , { } ) {
if ( params . size ( ) ! = 1 ) {
exec_state_ = LDBCommandExecuteResult : : Failed (
" dbname must be specified for the list_column_families command " ) ;
} else {
dbname_ = params [ 0 ] ;
}
}
: LDBCommand ( options , flags , false , BuildCmdLineOptions ( { } ) ) { }
void ListColumnFamiliesCommand : : DoCommand ( ) {
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 ( ) ) {
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 ( ) ) ;
} else {
printf ( " Column families in %s: \n { " , dbname _ . c_str ( ) ) ;
printf ( " Column families in %s: \n { " , db_path _ . c_str ( ) ) ;
bool first = true ;
for ( auto cf : column_families ) {
if ( ! first ) {
@ -2857,13 +2867,14 @@ void BackupCommand::DoCommand() {
}
printf ( " open db OK \n " ) ;
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_dir_ , custom_env ) ;
backup_options . info_log = logger_ . get ( ) ;
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 ( ) ) {
printf ( " open backup engine OK \n " ) ;
} else {
@ -2893,7 +2904,8 @@ void RestoreCommand::Help(std::string& ret) {
void RestoreCommand : : DoCommand ( ) {
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 ;
Status status ;
@ -2902,8 +2914,8 @@ void RestoreCommand::DoCommand() {
opts . info_log = logger_ . get ( ) ;
opts . max_background_operations = num_threads_ ;
BackupEngineReadOnly * raw_restore_engine_ptr ;
status = BackupEngineReadOnly : : Open ( Env : : Default ( ) , opts ,
& raw_restore_engine_ptr ) ;
status =
BackupEngineReadOnly : : Open ( custom_env , opts , & raw_restore_engine_ptr ) ;
if ( status . ok ( ) ) {
restore_engine . reset ( raw_restore_engine_ptr ) ;
}