@ -195,11 +195,11 @@ bool LDBCommand::ParseIntOption(const map<string, string>& options,
value = stoi ( itr - > second ) ;
value = stoi ( itr - > second ) ;
return true ;
return true ;
} catch ( const invalid_argument & ) {
} catch ( const invalid_argument & ) {
exec_state = LDBCommandExecuteResult : : Failed ( option +
exec_state =
" has an invalid value. " ) ;
LDBCommandExecuteResult : : Failed ( option + " has an invalid value. " ) ;
} catch ( const out_of_range & ) {
} catch ( const out_of_range & ) {
exec_state = LDBCommandExecuteResult : : Failed ( option +
exec_state = LDBCommandExecuteResult : : Failed (
" has a value out-of-range. " ) ;
option + " has a value out-of-range. " ) ;
}
}
}
}
return false ;
return false ;
@ -235,8 +235,8 @@ Options LDBCommand::PrepareOptionsForOpenDB() {
use_table_options = true ;
use_table_options = true ;
table_options . filter_policy . reset ( NewBloomFilterPolicy ( bits ) ) ;
table_options . filter_policy . reset ( NewBloomFilterPolicy ( bits ) ) ;
} else {
} else {
exec_state_ = LDBCommandExecuteResult : : Failed ( ARG_BLOOM_BITS +
exec_state_ =
" must be > 0. " ) ;
LDBCommandExecuteResult : : Failed ( ARG_BLOOM_BITS + " must be > 0. " ) ;
}
}
}
}
@ -246,8 +246,8 @@ Options LDBCommand::PrepareOptionsForOpenDB() {
use_table_options = true ;
use_table_options = true ;
table_options . block_size = block_size ;
table_options . block_size = block_size ;
} else {
} else {
exec_state_ = LDBCommandExecuteResult : : Failed ( ARG_BLOCK_SIZE +
exec_state_ =
" must be > 0. " ) ;
LDBCommandExecuteResult : : Failed ( ARG_BLOCK_SIZE + " must be > 0. " ) ;
}
}
}
}
@ -277,8 +277,8 @@ Options LDBCommand::PrepareOptionsForOpenDB() {
opt . compression = kLZ4HCCompression ;
opt . compression = kLZ4HCCompression ;
} else {
} else {
// Unknown compression.
// Unknown compression.
exec_state_ = LDBCommandExecuteResult : : Failed (
exec_state_ =
" Unknown compression level: " + comp ) ;
LDBCommandExecuteResult : : Failed ( " Unknown compression level: " + comp ) ;
}
}
}
}
@ -289,7 +289,7 @@ Options LDBCommand::PrepareOptionsForOpenDB() {
opt . db_write_buffer_size = db_write_buffer_size ;
opt . db_write_buffer_size = db_write_buffer_size ;
} else {
} else {
exec_state_ = LDBCommandExecuteResult : : Failed ( ARG_DB_WRITE_BUFFER_SIZE +
exec_state_ = LDBCommandExecuteResult : : Failed ( ARG_DB_WRITE_BUFFER_SIZE +
" must be >= 0. " ) ;
" must be >= 0. " ) ;
}
}
}
}
@ -300,7 +300,7 @@ Options LDBCommand::PrepareOptionsForOpenDB() {
opt . write_buffer_size = write_buffer_size ;
opt . write_buffer_size = write_buffer_size ;
} else {
} else {
exec_state_ = LDBCommandExecuteResult : : Failed ( ARG_WRITE_BUFFER_SIZE +
exec_state_ = LDBCommandExecuteResult : : Failed ( ARG_WRITE_BUFFER_SIZE +
" must be > 0. " ) ;
" must be > 0. " ) ;
}
}
}
}
@ -309,8 +309,8 @@ Options LDBCommand::PrepareOptionsForOpenDB() {
if ( file_size > 0 ) {
if ( file_size > 0 ) {
opt . target_file_size_base = file_size ;
opt . target_file_size_base = file_size ;
} else {
} else {
exec_state_ = LDBCommandExecuteResult : : Failed ( ARG_FILE_SIZE +
exec_state_ =
" must be > 0. " ) ;
LDBCommandExecuteResult : : Failed ( ARG_FILE_SIZE + " must be > 0. " ) ;
}
}
}
}
@ -585,8 +585,8 @@ void ManifestDumpCommand::DoCommand() {
// containing the db for files of the form MANIFEST_[0-9]+
// containing the db for files of the form MANIFEST_[0-9]+
DIR * d = opendir ( db_path_ . c_str ( ) ) ;
DIR * d = opendir ( db_path_ . c_str ( ) ) ;
if ( d = = nullptr ) {
if ( d = = nullptr ) {
exec_state_ = LDBCommandExecuteResult : : Failed (
exec_state_ =
db_path_ + " is not a directory " ) ;
LDBCommandExecuteResult : : Failed ( db_path_ + " is not a directory " ) ;
return ;
return ;
}
}
struct dirent * entry ;
struct dirent * entry ;
@ -603,7 +603,7 @@ void ManifestDumpCommand::DoCommand() {
found = true ;
found = true ;
} else {
} else {
exec_state_ = LDBCommandExecuteResult : : Failed (
exec_state_ = LDBCommandExecuteResult : : Failed (
" Multiple MANIFEST files found; use --path to select one " ) ;
" Multiple MANIFEST files found; use --path to select one " ) ;
closedir ( d ) ;
closedir ( d ) ;
return ;
return ;
}
}
@ -792,8 +792,8 @@ void InternalDumpCommand::DoCommand() {
ScopedArenaIterator iter ( idb - > TEST_NewInternalIterator ( & arena ) ) ;
ScopedArenaIterator iter ( idb - > TEST_NewInternalIterator ( & arena ) ) ;
Status st = iter - > status ( ) ;
Status st = iter - > status ( ) ;
if ( ! st . ok ( ) ) {
if ( ! st . ok ( ) ) {
exec_state_ = LDBCommandExecuteResult : : Failed ( " Iterator error: "
exec_state_ =
+ st . ToString ( ) ) ;
LDBCommandExecuteResult : : Failed ( " Iterator error: " + st . ToString ( ) ) ;
}
}
if ( has_from_ ) {
if ( has_from_ ) {
@ -900,10 +900,10 @@ DBDumperCommand::DBDumperCommand(const vector<string>& params,
max_keys_ = stoi ( itr - > second ) ;
max_keys_ = stoi ( itr - > second ) ;
} catch ( const invalid_argument & ) {
} catch ( const invalid_argument & ) {
exec_state_ = LDBCommandExecuteResult : : Failed ( ARG_MAX_KEYS +
exec_state_ = LDBCommandExecuteResult : : Failed ( ARG_MAX_KEYS +
" has an invalid value " ) ;
" has an invalid value " ) ;
} catch ( const out_of_range & ) {
} catch ( const out_of_range & ) {
exec_state_ = LDBCommandExecuteResult : : Failed ( ARG_MAX_KEYS +
exec_state_ = LDBCommandExecuteResult : : Failed (
" has a value out-of-range " ) ;
ARG_MAX_KEYS + " has a value out-of-range " ) ;
}
}
}
}
itr = options . find ( ARG_COUNT_DELIM ) ;
itr = options . find ( ARG_COUNT_DELIM ) ;
@ -961,8 +961,8 @@ void DBDumperCommand::DoCommand() {
Iterator * iter = db_ - > NewIterator ( ReadOptions ( ) ) ;
Iterator * iter = db_ - > NewIterator ( ReadOptions ( ) ) ;
Status st = iter - > status ( ) ;
Status st = iter - > status ( ) ;
if ( ! st . ok ( ) ) {
if ( ! st . ok ( ) ) {
exec_state_ = LDBCommandExecuteResult : : Failed ( " Iterator error. "
exec_state_ =
+ st . ToString ( ) ) ;
LDBCommandExecuteResult : : Failed ( " Iterator error. " + st . ToString ( ) ) ;
}
}
if ( ! null_from_ ) {
if ( ! null_from_ ) {
@ -1095,7 +1095,7 @@ ReduceDBLevelsCommand::ReduceDBLevelsCommand(const vector<string>& params,
if ( new_levels_ < = 0 ) {
if ( new_levels_ < = 0 ) {
exec_state_ = LDBCommandExecuteResult : : Failed (
exec_state_ = LDBCommandExecuteResult : : Failed (
" Use -- " + ARG_NEW_LEVELS + " to specify a new level number \n " ) ;
" Use -- " + ARG_NEW_LEVELS + " to specify a new level number \n " ) ;
}
}
}
}
@ -1165,8 +1165,8 @@ Status ReduceDBLevelsCommand::GetOldNumOfLevels(Options& opt,
void ReduceDBLevelsCommand : : DoCommand ( ) {
void ReduceDBLevelsCommand : : DoCommand ( ) {
if ( new_levels_ < = 1 ) {
if ( new_levels_ < = 1 ) {
exec_state_ = LDBCommandExecuteResult : : Failed (
exec_state_ =
" Invalid number of levels. \n " ) ;
LDBCommandExecuteResult : : Failed ( " Invalid number of levels. \n " ) ;
return ;
return ;
}
}
@ -1225,8 +1225,8 @@ ChangeCompactionStyleCommand::ChangeCompactionStyleCommand(
if ( old_compaction_style_ ! = kCompactionStyleLevel & &
if ( old_compaction_style_ ! = kCompactionStyleLevel & &
old_compaction_style_ ! = kCompactionStyleUniversal ) {
old_compaction_style_ ! = kCompactionStyleUniversal ) {
exec_state_ = LDBCommandExecuteResult : : Failed (
exec_state_ = LDBCommandExecuteResult : : Failed (
" Use -- " + ARG_OLD_COMPACTION_STYLE + " to specify old compaction " +
" Use -- " + ARG_OLD_COMPACTION_STYLE + " to specify old compaction " +
" style. Check ldb help for proper compaction style value. \n " ) ;
" style. Check ldb help for proper compaction style value. \n " ) ;
return ;
return ;
}
}
@ -1235,23 +1235,23 @@ ChangeCompactionStyleCommand::ChangeCompactionStyleCommand(
if ( new_compaction_style_ ! = kCompactionStyleLevel & &
if ( new_compaction_style_ ! = kCompactionStyleLevel & &
new_compaction_style_ ! = kCompactionStyleUniversal ) {
new_compaction_style_ ! = kCompactionStyleUniversal ) {
exec_state_ = LDBCommandExecuteResult : : Failed (
exec_state_ = LDBCommandExecuteResult : : Failed (
" Use -- " + ARG_NEW_COMPACTION_STYLE + " to specify new compaction " +
" Use -- " + ARG_NEW_COMPACTION_STYLE + " to specify new compaction " +
" style. Check ldb help for proper compaction style value. \n " ) ;
" style. Check ldb help for proper compaction style value. \n " ) ;
return ;
return ;
}
}
if ( new_compaction_style_ = = old_compaction_style_ ) {
if ( new_compaction_style_ = = old_compaction_style_ ) {
exec_state_ = LDBCommandExecuteResult : : Failed (
exec_state_ = LDBCommandExecuteResult : : Failed (
" Old compaction style is the same as new compaction style. "
" Old compaction style is the same as new compaction style. "
" Nothing to do. \n " ) ;
" Nothing to do. \n " ) ;
return ;
return ;
}
}
if ( old_compaction_style_ = = kCompactionStyleUniversal & &
if ( old_compaction_style_ = = kCompactionStyleUniversal & &
new_compaction_style_ = = kCompactionStyleLevel ) {
new_compaction_style_ = = kCompactionStyleLevel ) {
exec_state_ = LDBCommandExecuteResult : : Failed (
exec_state_ = LDBCommandExecuteResult : : Failed (
" Convert from universal compaction to level compaction. "
" Convert from universal compaction to level compaction. "
" Nothing to do. \n " ) ;
" Nothing to do. \n " ) ;
return ;
return ;
}
}
}
}
@ -1320,16 +1320,19 @@ void ChangeCompactionStyleCommand::DoCommand() {
// level 0 should have only 1 file
// level 0 should have only 1 file
if ( i = = 0 & & num_files ! = 1 ) {
if ( i = = 0 & & num_files ! = 1 ) {
exec_state_ = LDBCommandExecuteResult : : Failed ( " Number of db files at "
exec_state_ = LDBCommandExecuteResult : : Failed (
" level 0 after compaction is " + ToString ( num_files ) +
" Number of db files at "
" , not 1. \n " ) ;
" level 0 after compaction is " +
ToString ( num_files ) + " , not 1. \n " ) ;
return ;
return ;
}
}
// other levels should have no file
// other levels should have no file
if ( i > 0 & & num_files ! = 0 ) {
if ( i > 0 & & num_files ! = 0 ) {
exec_state_ = LDBCommandExecuteResult : : Failed ( " Number of db files at "
exec_state_ = LDBCommandExecuteResult : : Failed (
" level " + ToString ( i ) + " after compaction is " +
" Number of db files at "
ToString ( num_files ) + " , not 0. \n " ) ;
" level " +
ToString ( i ) + " after compaction is " + ToString ( num_files ) +
" , not 0. \n " ) ;
return ;
return ;
}
}
}
}
@ -1459,8 +1462,8 @@ WALDumperCommand::WALDumperCommand(const vector<string>& params,
print_header_ = IsFlagPresent ( flags , ARG_PRINT_HEADER ) ;
print_header_ = IsFlagPresent ( flags , ARG_PRINT_HEADER ) ;
print_values_ = IsFlagPresent ( flags , ARG_PRINT_VALUE ) ;
print_values_ = IsFlagPresent ( flags , ARG_PRINT_VALUE ) ;
if ( wal_file_ . empty ( ) ) {
if ( wal_file_ . empty ( ) ) {
exec_state_ = LDBCommandExecuteResult : : Failed (
exec_state_ = LDBCommandExecuteResult : : Failed ( " Argument " + ARG_WAL_FILE +
" Argument " + ARG_WAL_FILE + " must be specified. " ) ;
" must be specified. " ) ;
}
}
}
}
@ -1487,7 +1490,7 @@ GetCommand::GetCommand(const vector<string>& params,
if ( params . size ( ) ! = 1 ) {
if ( params . size ( ) ! = 1 ) {
exec_state_ = LDBCommandExecuteResult : : Failed (
exec_state_ = LDBCommandExecuteResult : : Failed (
" <key> must be specified for the get command " ) ;
" <key> must be specified for the get command " ) ;
} else {
} else {
key_ = params . at ( 0 ) ;
key_ = params . at ( 0 ) ;
}
}
@ -1527,16 +1530,16 @@ ApproxSizeCommand::ApproxSizeCommand(const vector<string>& params,
if ( options . find ( ARG_FROM ) ! = options . end ( ) ) {
if ( options . find ( ARG_FROM ) ! = options . end ( ) ) {
start_key_ = options . find ( ARG_FROM ) - > second ;
start_key_ = options . find ( ARG_FROM ) - > second ;
} else {
} else {
exec_state_ = LDBCommandExecuteResult : : Failed ( ARG_FROM +
exec_state_ = LDBCommandExecuteResult : : Failed (
" must be specified for approxsize command " ) ;
ARG_FROM + " must be specified for approxsize command " ) ;
return ;
return ;
}
}
if ( options . find ( ARG_TO ) ! = options . end ( ) ) {
if ( options . find ( ARG_TO ) ! = options . end ( ) ) {
end_key_ = options . find ( ARG_TO ) - > second ;
end_key_ = options . find ( ARG_TO ) - > second ;
} else {
} else {
exec_state_ = LDBCommandExecuteResult : : Failed ( ARG_TO +
exec_state_ = LDBCommandExecuteResult : : Failed (
" must be specified for approxsize command " ) ;
ARG_TO + " must be specified for approxsize command " ) ;
return ;
return ;
}
}
@ -1657,10 +1660,10 @@ ScanCommand::ScanCommand(const vector<string>& params,
max_keys_scanned_ = stoi ( itr - > second ) ;
max_keys_scanned_ = stoi ( itr - > second ) ;
} catch ( const invalid_argument & ) {
} catch ( const invalid_argument & ) {
exec_state_ = LDBCommandExecuteResult : : Failed ( ARG_MAX_KEYS +
exec_state_ = LDBCommandExecuteResult : : Failed ( ARG_MAX_KEYS +
" has an invalid value " ) ;
" has an invalid value " ) ;
} catch ( const out_of_range & ) {
} catch ( const out_of_range & ) {
exec_state_ = LDBCommandExecuteResult : : Failed ( ARG_MAX_KEYS +
exec_state_ = LDBCommandExecuteResult : : Failed (
" has a value out-of-range " ) ;
ARG_MAX_KEYS + " has a value out-of-range " ) ;
}
}
}
}
}
}
@ -1743,7 +1746,7 @@ DeleteCommand::DeleteCommand(const vector<string>& params,
if ( params . size ( ) ! = 1 ) {
if ( params . size ( ) ! = 1 ) {
exec_state_ = LDBCommandExecuteResult : : Failed (
exec_state_ = LDBCommandExecuteResult : : Failed (
" KEY must be specified for the delete command " ) ;
" KEY must be specified for the delete command " ) ;
} else {
} else {
key_ = params . at ( 0 ) ;
key_ = params . at ( 0 ) ;
if ( is_key_hex_ ) {
if ( is_key_hex_ ) {
@ -1776,7 +1779,7 @@ PutCommand::PutCommand(const vector<string>& params,
if ( params . size ( ) ! = 2 ) {
if ( params . size ( ) ! = 2 ) {
exec_state_ = LDBCommandExecuteResult : : Failed (
exec_state_ = LDBCommandExecuteResult : : Failed (
" <key> and <value> must be specified for the put command " ) ;
" <key> and <value> must be specified for the put command " ) ;
} else {
} else {
key_ = params . at ( 0 ) ;
key_ = params . at ( 0 ) ;
value_ = params . at ( 1 ) ;
value_ = params . at ( 1 ) ;