@ -22,6 +22,7 @@
# include "rocksdb/utilities/backupable_db.h"
# include "rocksdb/utilities/checkpoint.h"
# include "rocksdb/utilities/object_registry.h"
# include "rocksdb/utilities/options_util.h"
# include "rocksdb/write_batch.h"
# include "rocksdb/write_buffer_manager.h"
# include "table/scoped_arena_iterator.h"
@ -55,6 +56,7 @@ const std::string LDBCommand::ARG_TTL = "ttl";
const std : : string LDBCommand : : ARG_TTL_START = " start_time " ;
const std : : string LDBCommand : : ARG_TTL_END = " end_time " ;
const std : : string LDBCommand : : ARG_TIMESTAMP = " timestamp " ;
const std : : string LDBCommand : : ARG_TRY_LOAD_OPTIONS = " try_load_options " ;
const std : : string LDBCommand : : ARG_FROM = " from " ;
const std : : string LDBCommand : : ARG_TO = " to " ;
const std : : string LDBCommand : : ARG_MAX_KEYS = " max_keys " ;
@ -248,6 +250,12 @@ void LDBCommand::Run() {
if ( db_ = = nullptr & & ! NoDBOpen ( ) ) {
OpenDB ( ) ;
if ( exec_state_ . IsFailed ( ) & & try_load_options_ ) {
// We don't always return if there is a failure because a WAL file or
// manifest file can be given to "dump" command so we should continue.
// --try_load_options is not valid in those cases.
return ;
}
}
// We'll intentionally proceed even if the DB can't be opened because users
@ -272,6 +280,8 @@ LDBCommand::LDBCommand(const std::map<std::string, std::string>& options,
is_value_hex_ ( false ) ,
is_db_ttl_ ( false ) ,
timestamp_ ( false ) ,
try_load_options_ ( false ) ,
create_if_missing_ ( false ) ,
option_map_ ( options ) ,
flags_ ( flags ) ,
valid_cmd_line_options_ ( valid_cmd_line_options ) {
@ -291,10 +301,28 @@ LDBCommand::LDBCommand(const std::map<std::string, std::string>& options,
is_value_hex_ = IsValueHex ( options , flags ) ;
is_db_ttl_ = IsFlagPresent ( flags , ARG_TTL ) ;
timestamp_ = IsFlagPresent ( flags , ARG_TIMESTAMP ) ;
try_load_options_ = IsFlagPresent ( flags , ARG_TRY_LOAD_OPTIONS ) ;
}
void LDBCommand : : OpenDB ( ) {
Options opt = PrepareOptionsForOpenDB ( ) ;
Options opt ;
bool opt_set = false ;
if ( ! create_if_missing_ & & try_load_options_ ) {
Status s =
LoadLatestOptions ( db_path_ , Env : : Default ( ) , & opt , & column_families_ ) ;
if ( s . ok ( ) ) {
opt_set = true ;
} else if ( ! s . IsNotFound ( ) ) {
// Option file exists but load option file error.
std : : string msg = s . ToString ( ) ;
exec_state_ = LDBCommandExecuteResult : : Failed ( msg ) ;
db_ = nullptr ;
return ;
}
}
if ( ! opt_set ) {
opt = PrepareOptionsForOpenDB ( ) ;
}
if ( ! exec_state_ . IsNotStarted ( ) ) {
return ;
}
@ -314,7 +342,7 @@ void LDBCommand::OpenDB() {
}
db_ = db_ttl_ ;
} else {
if ( column_families_ . empty ( ) ) {
if ( ! opt_set & & column_families_ . empty ( ) ) {
// Try to figure out column family lists
std : : vector < std : : string > cf_list ;
st = DB : : ListColumnFamilies ( DBOptions ( ) , db_path_ , & cf_list ) ;
@ -408,6 +436,7 @@ std::vector<std::string> LDBCommand::BuildCmdLineOptions(
ARG_WRITE_BUFFER_SIZE ,
ARG_FILE_SIZE ,
ARG_FIX_PREFIX_LEN ,
ARG_TRY_LOAD_OPTIONS ,
ARG_CF_NAME } ;
ret . insert ( ret . end ( ) , options . begin ( ) , options . end ( ) ) ;
return ret ;
@ -807,7 +836,6 @@ DBLoaderCommand::DBLoaderCommand(
BuildCmdLineOptions ( { ARG_HEX , ARG_KEY_HEX , ARG_VALUE_HEX , ARG_FROM ,
ARG_TO , ARG_CREATE_IF_MISSING , ARG_DISABLE_WAL ,
ARG_BULK_LOAD , ARG_COMPACT } ) ) ,
create_if_missing_ ( false ) ,
disable_wal_ ( false ) ,
bulk_load_ ( false ) ,
compact_ ( false ) {
@ -1656,7 +1684,7 @@ void ReduceDBLevelsCommand::DoCommand() {
old_levels_ = old_level_num ;
OpenDB ( ) ;
if ( ! db_ ) {
if ( exec_state_ . IsFailed ( ) ) {
return ;
}
// Compact the whole DB to put all files to the highest level.
@ -2140,6 +2168,7 @@ BatchPutCommand::BatchPutCommand(
is_value_hex_ ? HexToString ( value ) : value ) ) ;
}
}
create_if_missing_ = IsFlagPresent ( flags_ , ARG_CREATE_IF_MISSING ) ;
}
void BatchPutCommand : : Help ( std : : string & ret ) {
@ -2172,7 +2201,7 @@ void BatchPutCommand::DoCommand() {
Options BatchPutCommand : : PrepareOptionsForOpenDB ( ) {
Options opt = LDBCommand : : PrepareOptionsForOpenDB ( ) ;
opt . create_if_missing = IsFlagPresent ( flags_ , ARG_CREATE_IF_MISSING ) ;
opt . create_if_missing = create_if_missing_ ;
return opt ;
}
@ -2424,6 +2453,7 @@ PutCommand::PutCommand(const std::vector<std::string>& params,
if ( is_value_hex_ ) {
value_ = HexToString ( value_ ) ;
}
create_if_missing_ = IsFlagPresent ( flags_ , ARG_CREATE_IF_MISSING ) ;
}
void PutCommand : : Help ( std : : string & ret ) {
@ -2449,7 +2479,7 @@ void PutCommand::DoCommand() {
Options PutCommand : : PrepareOptionsForOpenDB ( ) {
Options opt = LDBCommand : : PrepareOptionsForOpenDB ( ) ;
opt . create_if_missing = IsFlagPresent ( flags_ , ARG_CREATE_IF_MISSING ) ;
opt . create_if_missing = create_if_missing_ ;
return opt ;
}