added --no_value option to ldb scan to dump key only
This commit is contained in:
parent
b1a3b4c0d0
commit
b73fbbaf64
@ -60,6 +60,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_WRITE_BUFFER_SIZE = "write_buffer_size";
|
||||||
const string LDBCommand::ARG_FILE_SIZE = "file_size";
|
const string LDBCommand::ARG_FILE_SIZE = "file_size";
|
||||||
const string LDBCommand::ARG_CREATE_IF_MISSING = "create_if_missing";
|
const string LDBCommand::ARG_CREATE_IF_MISSING = "create_if_missing";
|
||||||
|
const string LDBCommand::ARG_NO_VALUE = "no_value";
|
||||||
|
|
||||||
const char* LDBCommand::DELIM = " ==> ";
|
const char* LDBCommand::DELIM = " ==> ";
|
||||||
|
|
||||||
@ -1743,12 +1744,13 @@ Options BatchPutCommand::PrepareOptionsForOpenDB() {
|
|||||||
ScanCommand::ScanCommand(const vector<string>& params,
|
ScanCommand::ScanCommand(const vector<string>& params,
|
||||||
const map<string, string>& options, const vector<string>& flags) :
|
const map<string, string>& options, const vector<string>& flags) :
|
||||||
LDBCommand(options, flags, true,
|
LDBCommand(options, flags, true,
|
||||||
BuildCmdLineOptions({ARG_TTL, ARG_HEX, ARG_KEY_HEX, ARG_TO,
|
BuildCmdLineOptions({ARG_TTL, ARG_NO_VALUE, ARG_HEX, ARG_KEY_HEX, ARG_TO,
|
||||||
ARG_VALUE_HEX, ARG_FROM, ARG_TIMESTAMP,
|
ARG_VALUE_HEX, ARG_FROM, ARG_TIMESTAMP,
|
||||||
ARG_MAX_KEYS, ARG_TTL_START, ARG_TTL_END})),
|
ARG_MAX_KEYS, ARG_TTL_START, ARG_TTL_END})),
|
||||||
start_key_specified_(false),
|
start_key_specified_(false),
|
||||||
end_key_specified_(false),
|
end_key_specified_(false),
|
||||||
max_keys_scanned_(-1) {
|
max_keys_scanned_(-1),
|
||||||
|
no_value_(false) {
|
||||||
|
|
||||||
map<string, string>::const_iterator itr = options.find(ARG_FROM);
|
map<string, string>::const_iterator itr = options.find(ARG_FROM);
|
||||||
if (itr != options.end()) {
|
if (itr != options.end()) {
|
||||||
@ -1767,6 +1769,11 @@ ScanCommand::ScanCommand(const vector<string>& params,
|
|||||||
end_key_specified_ = true;
|
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);
|
itr = options.find(ARG_MAX_KEYS);
|
||||||
if (itr != options.end()) {
|
if (itr != options.end()) {
|
||||||
try {
|
try {
|
||||||
@ -1794,6 +1801,7 @@ void ScanCommand::Help(string& ret) {
|
|||||||
ret.append(" [--" + ARG_MAX_KEYS + "=<N>q] ");
|
ret.append(" [--" + ARG_MAX_KEYS + "=<N>q] ");
|
||||||
ret.append(" [--" + ARG_TTL_START + "=<N>:- is inclusive]");
|
ret.append(" [--" + ARG_TTL_START + "=<N>:- is inclusive]");
|
||||||
ret.append(" [--" + ARG_TTL_END + "=<N>:- is exclusive]");
|
ret.append(" [--" + ARG_TTL_END + "=<N>:- is exclusive]");
|
||||||
|
ret.append(" [--" + ARG_NO_VALUE + "]");
|
||||||
ret.append("\n");
|
ret.append("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1850,15 +1858,20 @@ void ScanCommand::DoCommand() {
|
|||||||
key_slice = formatted_key;
|
key_slice = formatted_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
std::string formatted_value;
|
||||||
if (is_value_hex_) {
|
if (is_value_hex_) {
|
||||||
formatted_value = "0x" + val_slice.ToString(true /* hex */);
|
formatted_value = "0x" + val_slice.ToString(true /* hex */);
|
||||||
val_slice = formatted_value;
|
val_slice = formatted_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stdout, "%.*s : %.*s\n",
|
fprintf(stdout, "%.*s : %.*s\n",
|
||||||
static_cast<int>(key_slice.size()), key_slice.data(),
|
static_cast<int>(key_slice.size()), key_slice.data(),
|
||||||
static_cast<int>(val_slice.size()), val_slice.data());
|
static_cast<int>(val_slice.size()), val_slice.data());
|
||||||
|
}
|
||||||
|
|
||||||
num_keys_scanned++;
|
num_keys_scanned++;
|
||||||
if (max_keys_scanned_ >= 0 && num_keys_scanned >= max_keys_scanned_) {
|
if (max_keys_scanned_ >= 0 && num_keys_scanned >= max_keys_scanned_) {
|
||||||
|
@ -60,6 +60,7 @@ public:
|
|||||||
static const string ARG_WRITE_BUFFER_SIZE;
|
static const string ARG_WRITE_BUFFER_SIZE;
|
||||||
static const string ARG_FILE_SIZE;
|
static const string ARG_FILE_SIZE;
|
||||||
static const string ARG_CREATE_IF_MISSING;
|
static const string ARG_CREATE_IF_MISSING;
|
||||||
|
static const string ARG_NO_VALUE;
|
||||||
|
|
||||||
static LDBCommand* InitFromCmdLineArgs(
|
static LDBCommand* InitFromCmdLineArgs(
|
||||||
const vector<string>& args,
|
const vector<string>& args,
|
||||||
@ -377,7 +378,7 @@ private:
|
|||||||
*/
|
*/
|
||||||
bool StringToBool(string val) {
|
bool StringToBool(string val) {
|
||||||
std::transform(val.begin(), val.end(), val.begin(),
|
std::transform(val.begin(), val.end(), val.begin(),
|
||||||
[](char ch) -> char { return ::tolower(ch); });
|
[](char ch) -> char { return (char)::tolower(ch); });
|
||||||
|
|
||||||
if (val == "true") {
|
if (val == "true") {
|
||||||
return true;
|
return true;
|
||||||
@ -709,6 +710,7 @@ private:
|
|||||||
bool start_key_specified_;
|
bool start_key_specified_;
|
||||||
bool end_key_specified_;
|
bool end_key_specified_;
|
||||||
int max_keys_scanned_;
|
int max_keys_scanned_;
|
||||||
|
bool no_value_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DeleteCommand : public LDBCommand {
|
class DeleteCommand : public LDBCommand {
|
||||||
|
Loading…
Reference in New Issue
Block a user