mirror of https://github.com/facebook/rocksdb.git
Merge pull request #938 from alexander-fenster/master
added --no_value option to ldb scan to dump key only
This commit is contained in:
commit
ee8cc35201
|
@ -61,6 +61,7 @@ const string LDBCommand::ARG_DB_WRITE_BUFFER_SIZE = "db_write_buffer_size";
|
|||
const string LDBCommand::ARG_WRITE_BUFFER_SIZE = "write_buffer_size";
|
||||
const string LDBCommand::ARG_FILE_SIZE = "file_size";
|
||||
const string LDBCommand::ARG_CREATE_IF_MISSING = "create_if_missing";
|
||||
const string LDBCommand::ARG_NO_VALUE = "no_value";
|
||||
|
||||
const char* LDBCommand::DELIM = " ==> ";
|
||||
|
||||
|
@ -1792,14 +1793,17 @@ Options BatchPutCommand::PrepareOptionsForOpenDB() {
|
|||
// ----------------------------------------------------------------------------
|
||||
|
||||
ScanCommand::ScanCommand(const vector<string>& params,
|
||||
const map<string, string>& options, const vector<string>& flags) :
|
||||
LDBCommand(options, flags, true,
|
||||
BuildCmdLineOptions({ARG_TTL, ARG_HEX, ARG_KEY_HEX, ARG_TO,
|
||||
ARG_VALUE_HEX, ARG_FROM, ARG_TIMESTAMP,
|
||||
ARG_MAX_KEYS, ARG_TTL_START, ARG_TTL_END})),
|
||||
start_key_specified_(false),
|
||||
end_key_specified_(false),
|
||||
max_keys_scanned_(-1) {
|
||||
const map<string, string>& options,
|
||||
const vector<string>& flags)
|
||||
: LDBCommand(options, flags, true,
|
||||
BuildCmdLineOptions(
|
||||
{ARG_TTL, ARG_NO_VALUE, ARG_HEX, ARG_KEY_HEX,
|
||||
ARG_TO, ARG_VALUE_HEX, ARG_FROM, ARG_TIMESTAMP,
|
||||
ARG_MAX_KEYS, ARG_TTL_START, ARG_TTL_END})),
|
||||
start_key_specified_(false),
|
||||
end_key_specified_(false),
|
||||
max_keys_scanned_(-1),
|
||||
no_value_(false) {
|
||||
|
||||
map<string, string>::const_iterator itr = options.find(ARG_FROM);
|
||||
if (itr != options.end()) {
|
||||
|
@ -1818,6 +1822,12 @@ ScanCommand::ScanCommand(const vector<string>& params,
|
|||
end_key_specified_ = true;
|
||||
}
|
||||
|
||||
vector<string>::const_iterator vitr =
|
||||
std::find(flags.begin(), flags.end(), ARG_NO_VALUE);
|
||||
if (vitr != flags.end()) {
|
||||
no_value_ = true;
|
||||
}
|
||||
|
||||
itr = options.find(ARG_MAX_KEYS);
|
||||
if (itr != options.end()) {
|
||||
try {
|
||||
|
@ -1845,6 +1855,7 @@ void ScanCommand::Help(string& ret) {
|
|||
ret.append(" [--" + ARG_MAX_KEYS + "=<N>q] ");
|
||||
ret.append(" [--" + ARG_TTL_START + "=<N>:- is inclusive]");
|
||||
ret.append(" [--" + ARG_TTL_END + "=<N>:- is exclusive]");
|
||||
ret.append(" [--" + ARG_NO_VALUE + "]");
|
||||
ret.append("\n");
|
||||
}
|
||||
|
||||
|
@ -1894,7 +1905,6 @@ void ScanCommand::DoCommand() {
|
|||
}
|
||||
|
||||
Slice key_slice = it->key();
|
||||
Slice val_slice = it->value();
|
||||
|
||||
std::string formatted_key;
|
||||
if (is_key_hex_) {
|
||||
|
@ -1905,16 +1915,21 @@ void ScanCommand::DoCommand() {
|
|||
key_slice = formatted_key;
|
||||
}
|
||||
|
||||
std::string formatted_value;
|
||||
if (is_value_hex_) {
|
||||
formatted_value = "0x" + val_slice.ToString(true /* hex */);
|
||||
val_slice = formatted_value;
|
||||
if (no_value_) {
|
||||
fprintf(stdout, "%.*s\n", static_cast<int>(key_slice.size()),
|
||||
key_slice.data());
|
||||
} else {
|
||||
Slice val_slice = it->value();
|
||||
std::string formatted_value;
|
||||
if (is_value_hex_) {
|
||||
formatted_value = "0x" + val_slice.ToString(true /* hex */);
|
||||
val_slice = formatted_value;
|
||||
}
|
||||
fprintf(stdout, "%.*s : %.*s\n", static_cast<int>(key_slice.size()),
|
||||
key_slice.data(), static_cast<int>(val_slice.size()),
|
||||
val_slice.data());
|
||||
}
|
||||
|
||||
fprintf(stdout, "%.*s : %.*s\n",
|
||||
static_cast<int>(key_slice.size()), key_slice.data(),
|
||||
static_cast<int>(val_slice.size()), val_slice.data());
|
||||
|
||||
num_keys_scanned++;
|
||||
if (max_keys_scanned_ >= 0 && num_keys_scanned >= max_keys_scanned_) {
|
||||
break;
|
||||
|
|
|
@ -61,6 +61,7 @@ public:
|
|||
static const string ARG_WRITE_BUFFER_SIZE;
|
||||
static const string ARG_FILE_SIZE;
|
||||
static const string ARG_CREATE_IF_MISSING;
|
||||
static const string ARG_NO_VALUE;
|
||||
|
||||
static LDBCommand* InitFromCmdLineArgs(
|
||||
const vector<string>& args, const Options& options,
|
||||
|
@ -461,7 +462,7 @@ private:
|
|||
*/
|
||||
bool StringToBool(string val) {
|
||||
std::transform(val.begin(), val.end(), val.begin(),
|
||||
[](char ch) -> char { return ::tolower(ch); });
|
||||
[](char ch)->char { return (char)::tolower(ch); });
|
||||
|
||||
if (val == "true") {
|
||||
return true;
|
||||
|
@ -810,6 +811,7 @@ private:
|
|||
bool start_key_specified_;
|
||||
bool end_key_specified_;
|
||||
int max_keys_scanned_;
|
||||
bool no_value_;
|
||||
};
|
||||
|
||||
class DeleteCommand : public LDBCommand {
|
||||
|
|
Loading…
Reference in New Issue