Fix lint errors and coding style of ldb related codes.

Summary: Fix lint errors and coding style of ldb related codes.

Test Plan: ./ldb

Reviewers: ljin, sdong, igor

Reviewed By: igor

Subscribers: dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D28125
main
Yueh-Hsuan Chiang 10 years ago
parent c645250ee0
commit bc9f36fd5e
  1. 4
      tools/sst_dump.cc
  2. 904
      util/ldb_cmd.cc
  3. 465
      util/ldb_cmd.h
  4. 6
      util/ldb_cmd_execute_result.h
  5. 36
      util/ldb_tool.cc

@ -275,8 +275,8 @@ static void print_help() {
} }
namespace { namespace {
string HexToString(const string& str) { std::string HexToString(const std::string& str) {
string parsed; std::string parsed;
if (str[0] != '0' || str[1] != 'x') { if (str[0] != '0' || str[1] != 'x') {
fprintf(stderr, "Invalid hex input %s. Must start with 0x\n", fprintf(stderr, "Invalid hex input %s. Must start with 0x\n",
str.c_str()); str.c_str());

File diff suppressed because it is too large Load Diff

@ -4,12 +4,15 @@
// of patent rights can be found in the PATENTS file in the same directory. // of patent rights can be found in the PATENTS file in the same directory.
// //
#pragma once #pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <stdlib.h>
#include <algorithm> #include <algorithm>
#include <stdio.h> #include <map>
#include <vector>
#include <utility>
#include "db/version_set.h" #include "db/version_set.h"
#include "rocksdb/env.h" #include "rocksdb/env.h"
@ -23,39 +26,34 @@
#include "util/string_util.h" #include "util/string_util.h"
#include "utilities/ttl/db_ttl_impl.h" #include "utilities/ttl/db_ttl_impl.h"
using std::string;
using std::map;
using std::vector;
using std::ostringstream;
namespace rocksdb { namespace rocksdb {
class LDBCommand { class LDBCommand {
public: public:
// Command-line arguments // Command-line arguments
static const string ARG_DB; static const std::string ARG_DB;
static const string ARG_HEX; static const std::string ARG_HEX;
static const string ARG_KEY_HEX; static const std::string ARG_KEY_HEX;
static const string ARG_VALUE_HEX; static const std::string ARG_VALUE_HEX;
static const string ARG_TTL; static const std::string ARG_TTL;
static const string ARG_TTL_START; static const std::string ARG_TTL_START;
static const string ARG_TTL_END; static const std::string ARG_TTL_END;
static const string ARG_TIMESTAMP; static const std::string ARG_TIMESTAMP;
static const string ARG_FROM; static const std::string ARG_FROM;
static const string ARG_TO; static const std::string ARG_TO;
static const string ARG_MAX_KEYS; static const std::string ARG_MAX_KEYS;
static const string ARG_BLOOM_BITS; static const std::string ARG_BLOOM_BITS;
static const string ARG_FIX_PREFIX_LEN; static const std::string ARG_FIX_PREFIX_LEN;
static const string ARG_COMPRESSION_TYPE; static const std::string ARG_COMPRESSION_TYPE;
static const string ARG_BLOCK_SIZE; static const std::string ARG_BLOCK_SIZE;
static const string ARG_AUTO_COMPACTION; static const std::string ARG_AUTO_COMPACTION;
static const string ARG_WRITE_BUFFER_SIZE; static const std::string ARG_WRITE_BUFFER_SIZE;
static const string ARG_FILE_SIZE; static const std::string ARG_FILE_SIZE;
static const string ARG_CREATE_IF_MISSING; static const std::string ARG_CREATE_IF_MISSING;
static LDBCommand* InitFromCmdLineArgs( static LDBCommand* InitFromCmdLineArgs(
const vector<string>& args, const std::vector<std::string>& args,
const Options& options, const Options& options,
const LDBOptions& ldb_options const LDBOptions& ldb_options
); );
@ -123,8 +121,8 @@ public:
exec_state_.Reset(); exec_state_.Reset();
} }
static string HexToString(const string& str) { static std::string HexToString(const std::string& str) {
string parsed; std::string parsed;
if (str[0] != '0' || str[1] != 'x') { if (str[0] != '0' || str[1] != 'x') {
fprintf(stderr, "Invalid hex input %s. Must start with 0x\n", fprintf(stderr, "Invalid hex input %s. Must start with 0x\n",
str.c_str()); str.c_str());
@ -140,8 +138,8 @@ public:
return parsed; return parsed;
} }
static string StringToHex(const string& str) { static std::string StringToHex(const std::string& str) {
string result = "0x"; std::string result = "0x";
char buf[10]; char buf[10];
for (size_t i = 0; i < str.length(); i++) { for (size_t i = 0; i < str.length(); i++) {
snprintf(buf, 10, "%02X", (unsigned char)str[i]); snprintf(buf, 10, "%02X", (unsigned char)str[i]);
@ -155,7 +153,7 @@ public:
protected: protected:
LDBCommandExecuteResult exec_state_; LDBCommandExecuteResult exec_state_;
string db_path_; std::string db_path_;
DB* db_; DB* db_;
DBWithTTL* db_ttl_; DBWithTTL* db_ttl_;
@ -180,21 +178,24 @@ protected:
/** /**
* Map of options passed on the command-line. * Map of options passed on the command-line.
*/ */
const map<string, string> option_map_; const std::map<std::string, std::string> option_map_;
/** /**
* Flags passed on the command-line. * Flags passed on the command-line.
*/ */
const vector<string> flags_; const std::vector<std::string> flags_;
/** List of command-line options valid for this command */ /** List of command-line options valid for this command */
const vector<string> valid_cmd_line_options_; const std::vector<std::string> valid_cmd_line_options_;
bool ParseKeyValue(const string& line, string* key, string* value, bool ParseKeyValue(const std::string& line,
bool is_key_hex, bool is_value_hex); std::string* key, std::string* value,
bool is_key_hex, bool is_value_hex);
LDBCommand(const map<string, string>& options, const vector<string>& flags, LDBCommand(const std::map<std::string, std::string>& options,
bool is_read_only, const vector<string>& valid_cmd_line_options) : const std::vector<std::string>& flags,
bool is_read_only,
const std::vector<std::string>& valid_cmd_line_options) :
db_(nullptr), db_(nullptr),
is_read_only_(is_read_only), is_read_only_(is_read_only),
is_key_hex_(false), is_key_hex_(false),
@ -205,7 +206,7 @@ protected:
flags_(flags), flags_(flags),
valid_cmd_line_options_(valid_cmd_line_options) { valid_cmd_line_options_(valid_cmd_line_options) {
map<string, string>::const_iterator itr = options.find(ARG_DB); auto itr = options.find(ARG_DB);
if (itr != options.end()) { if (itr != options.end()) {
db_path_ = itr->second; db_path_ = itr->second;
} }
@ -236,7 +237,7 @@ protected:
st = DB::Open(opt, db_path_, &db_); st = DB::Open(opt, db_path_, &db_);
} }
if (!st.ok()) { if (!st.ok()) {
string msg = st.ToString(); std::string msg = st.ToString();
exec_state_ = LDBCommandExecuteResult::FAILED(msg); exec_state_ = LDBCommandExecuteResult::FAILED(msg);
} }
@ -250,29 +251,33 @@ protected:
} }
} }
static string PrintKeyValue(const string& key, const string& value, static std::string PrintKeyValue(
bool is_key_hex, bool is_value_hex) { const std::string& key, const std::string& value,
string result; bool is_key_hex, bool is_value_hex) {
std::string result;
result.append(is_key_hex ? StringToHex(key) : key); result.append(is_key_hex ? StringToHex(key) : key);
result.append(DELIM); result.append(DELIM);
result.append(is_value_hex ? StringToHex(value) : value); result.append(is_value_hex ? StringToHex(value) : value);
return result; return result;
} }
static string PrintKeyValue(const string& key, const string& value, static std::string PrintKeyValue(
bool is_hex) { const std::string& key, const std::string& value,
bool is_hex) {
return PrintKeyValue(key, value, is_hex, is_hex); return PrintKeyValue(key, value, is_hex, is_hex);
} }
/** /**
* Return true if the specified flag is present in the specified flags vector * Return true if the specified flag is present in the specified
* flags vector
*/ */
static bool IsFlagPresent(const vector<string>& flags, const string& flag) { static bool IsFlagPresent(
const std::vector<std::string>& flags, const std::string& flag) {
return (std::find(flags.begin(), flags.end(), flag) != flags.end()); return (std::find(flags.begin(), flags.end(), flag) != flags.end());
} }
static string HelpRangeCmdArgs() { static std::string HelpRangeCmdArgs() {
ostringstream str_stream; std::ostringstream str_stream;
str_stream << " "; str_stream << " ";
str_stream << "[--" << ARG_FROM << "] "; str_stream << "[--" << ARG_FROM << "] ";
str_stream << "[--" << ARG_TO << "] "; str_stream << "[--" << ARG_TO << "] ";
@ -284,32 +289,35 @@ protected:
* used by this command. It includes the common options and the ones * used by this command. It includes the common options and the ones
* passed in. * passed in.
*/ */
vector<string> BuildCmdLineOptions(vector<string> options) { std::vector<std::string> BuildCmdLineOptions(
vector<string> ret = {ARG_DB, ARG_BLOOM_BITS, std::vector<std::string> options) {
ARG_BLOCK_SIZE, ARG_AUTO_COMPACTION, std::vector<std::string> ret = {
ARG_COMPRESSION_TYPE, ARG_WRITE_BUFFER_SIZE, ARG_DB, ARG_BLOOM_BITS,
ARG_FILE_SIZE, ARG_FIX_PREFIX_LEN}; ARG_BLOCK_SIZE, ARG_AUTO_COMPACTION,
ARG_COMPRESSION_TYPE, ARG_WRITE_BUFFER_SIZE,
ARG_FILE_SIZE, ARG_FIX_PREFIX_LEN};
ret.insert(ret.end(), options.begin(), options.end()); ret.insert(ret.end(), options.begin(), options.end());
return ret; return ret;
} }
bool ParseIntOption(const map<string, string>& options, const string& option, bool ParseIntOption(const std::map<std::string, std::string>& options,
int& value, LDBCommandExecuteResult& exec_state); const std::string& option,
int* value, LDBCommandExecuteResult* exec_state);
bool ParseStringOption(const map<string, string>& options, bool ParseStringOption(const std::map<std::string, std::string>& options,
const string& option, string* value); const std::string& option, std::string* value);
Options options_; Options options_;
LDBOptions ldb_options_; LDBOptions ldb_options_;
private: private:
/** /**
* Interpret command line options and flags to determine if the key * Interpret command line options and flags to determine if the key
* should be input/output in hex. * should be input/output in hex.
*/ */
bool IsKeyHex(const map<string, string>& options, bool IsKeyHex(const std::map<std::string, std::string>& options,
const vector<string>& flags) { const std::vector<std::string>& flags) {
return (IsFlagPresent(flags, ARG_HEX) || return (IsFlagPresent(flags, ARG_HEX) ||
IsFlagPresent(flags, ARG_KEY_HEX) || IsFlagPresent(flags, ARG_KEY_HEX) ||
ParseBooleanOption(options, ARG_HEX, false) || ParseBooleanOption(options, ARG_HEX, false) ||
@ -320,8 +328,8 @@ private:
* Interpret command line options and flags to determine if the value * Interpret command line options and flags to determine if the value
* should be input/output in hex. * should be input/output in hex.
*/ */
bool IsValueHex(const map<string, string>& options, bool IsValueHex(const std::map<std::string, std::string>& options,
const vector<string>& flags) { const std::vector<std::string>& flags) {
return (IsFlagPresent(flags, ARG_HEX) || return (IsFlagPresent(flags, ARG_HEX) ||
IsFlagPresent(flags, ARG_VALUE_HEX) || IsFlagPresent(flags, ARG_VALUE_HEX) ||
ParseBooleanOption(options, ARG_HEX, false) || ParseBooleanOption(options, ARG_HEX, false) ||
@ -334,12 +342,13 @@ private:
* Throws an exception if the value of the option is not * Throws an exception if the value of the option is not
* "true" or "false" (case insensitive). * "true" or "false" (case insensitive).
*/ */
bool ParseBooleanOption(const map<string, string>& options, bool ParseBooleanOption(
const string& option, bool default_val) { const std::map<std::string, std::string>& options,
const std::string& option, bool default_val) {
map<string, string>::const_iterator itr = options.find(option); auto itr = options.find(option);
if (itr != options.end()) { if (itr != options.end()) {
string option_val = itr->second; std::string option_val = itr->second;
return StringToBool(itr->second); return StringToBool(itr->second);
} }
return default_val; return default_val;
@ -350,7 +359,7 @@ private:
* val must be either true or false (case insensitive). * val must be either true or false (case insensitive).
* Otherwise an exception is thrown. * Otherwise an exception is thrown.
*/ */
bool StringToBool(string val) { bool StringToBool(std::string val) {
std::transform(val.begin(), val.end(), val.begin(), ::tolower); std::transform(val.begin(), val.end(), val.begin(), ::tolower);
if (val == "true") { if (val == "true") {
return true; return true;
@ -362,161 +371,165 @@ private:
} }
static LDBCommand* SelectCommand( static LDBCommand* SelectCommand(
const string& cmd, const std::string& cmd,
const vector<string>& cmdParams, const std::vector<std::string>& cmdParams,
const map<string, string>& option_map, const std::map<std::string, std::string>& option_map,
const vector<string>& flags const std::vector<std::string>& flags
); );
}; };
class CompactorCommand: public LDBCommand { class CompactorCommand: public LDBCommand {
public: public:
static string Name() { return "compact"; } static std::string Name() { return "compact"; }
CompactorCommand(const vector<string>& params, CompactorCommand(const std::vector<std::string>& params,
const map<string, string>& options, const vector<string>& flags); const std::map<std::string, std::string>& options,
const std::vector<std::string>& flags);
static void Help(string& ret); static void Help(std::string* ret);
virtual void DoCommand(); virtual void DoCommand();
private: private:
bool null_from_; bool null_from_;
string from_; std::string from_;
bool null_to_; bool null_to_;
string to_; std::string to_;
}; };
class DBDumperCommand: public LDBCommand { class DBDumperCommand: public LDBCommand {
public: public:
static string Name() { return "dump"; } static std::string Name() { return "dump"; }
DBDumperCommand(const vector<string>& params, DBDumperCommand(const std::vector<std::string>& params,
const map<string, string>& options, const vector<string>& flags); const std::map<std::string, std::string>& options,
const std::vector<std::string>& flags);
static void Help(string& ret); static void Help(std::string* ret);
virtual void DoCommand(); virtual void DoCommand();
private: private:
bool null_from_; bool null_from_;
string from_; std::string from_;
bool null_to_; bool null_to_;
string to_; std::string to_;
int max_keys_; uint64_t max_keys_;
string delim_; std::string delim_;
bool count_only_; bool count_only_;
bool count_delim_; bool count_delim_;
bool print_stats_; bool print_stats_;
static const string ARG_COUNT_ONLY; static const std::string ARG_COUNT_ONLY;
static const string ARG_COUNT_DELIM; static const std::string ARG_COUNT_DELIM;
static const string ARG_STATS; static const std::string ARG_STATS;
static const string ARG_TTL_BUCKET; static const std::string ARG_TTL_BUCKET;
}; };
class InternalDumpCommand: public LDBCommand { class InternalDumpCommand: public LDBCommand {
public: public:
static string Name() { return "idump"; } static std::string Name() { return "idump"; }
InternalDumpCommand(const vector<string>& params, InternalDumpCommand(const std::vector<std::string>& params,
const map<string, string>& options, const std::map<std::string, std::string>& options,
const vector<string>& flags); const std::vector<std::string>& flags);
static void Help(string& ret); static void Help(std::string* ret);
virtual void DoCommand(); virtual void DoCommand();
private: private:
bool has_from_; bool has_from_;
string from_; std::string from_;
bool has_to_; bool has_to_;
string to_; std::string to_;
int max_keys_; int max_keys_;
string delim_; std::string delim_;
bool count_only_; bool count_only_;
bool count_delim_; bool count_delim_;
bool print_stats_; bool print_stats_;
bool is_input_key_hex_; bool is_input_key_hex_;
static const string ARG_DELIM; static const std::string ARG_DELIM;
static const string ARG_COUNT_ONLY; static const std::string ARG_COUNT_ONLY;
static const string ARG_COUNT_DELIM; static const std::string ARG_COUNT_DELIM;
static const string ARG_STATS; static const std::string ARG_STATS;
static const string ARG_INPUT_KEY_HEX; static const std::string ARG_INPUT_KEY_HEX;
}; };
class DBLoaderCommand: public LDBCommand { class DBLoaderCommand: public LDBCommand {
public: public:
static string Name() { return "load"; } static std::string Name() { return "load"; }
DBLoaderCommand(string& db_name, vector<string>& args);
DBLoaderCommand(const vector<string>& params, DBLoaderCommand(const std::vector<std::string>& params,
const map<string, string>& options, const vector<string>& flags); const std::map<std::string, std::string>& options,
const std::vector<std::string>& flags);
static void Help(string& ret); static void Help(std::string* ret);
virtual void DoCommand(); virtual void DoCommand();
virtual Options PrepareOptionsForOpenDB(); virtual Options PrepareOptionsForOpenDB();
private: private:
bool create_if_missing_; bool create_if_missing_;
bool disable_wal_; bool disable_wal_;
bool bulk_load_; bool bulk_load_;
bool compact_; bool compact_;
static const string ARG_DISABLE_WAL; static const std::string ARG_DISABLE_WAL;
static const string ARG_BULK_LOAD; static const std::string ARG_BULK_LOAD;
static const string ARG_COMPACT; static const std::string ARG_COMPACT;
}; };
class ManifestDumpCommand: public LDBCommand { class ManifestDumpCommand: public LDBCommand {
public: public:
static string Name() { return "manifest_dump"; } static std::string Name() { return "manifest_dump"; }
ManifestDumpCommand(const vector<string>& params, ManifestDumpCommand(const std::vector<std::string>& params,
const map<string, string>& options, const vector<string>& flags); const std::map<std::string, std::string>& options,
const std::vector<std::string>& flags);
static void Help(string& ret); static void Help(std::string* ret);
virtual void DoCommand(); virtual void DoCommand();
virtual bool NoDBOpen() { virtual bool NoDBOpen() {
return true; return true;
} }
private: private:
bool verbose_; bool verbose_;
string path_; std::string path_;
static const string ARG_VERBOSE; static const std::string ARG_VERBOSE;
static const string ARG_PATH; static const std::string ARG_PATH;
}; };
class ListColumnFamiliesCommand : public LDBCommand { class ListColumnFamiliesCommand : public LDBCommand {
public: public:
static string Name() { return "list_column_families"; } static std::string Name() { return "list_column_families"; }
ListColumnFamiliesCommand(const vector<string>& params, ListColumnFamiliesCommand(
const map<string, string>& options, const std::vector<std::string>& params,
const vector<string>& flags); const std::map<std::string, std::string>& options,
const std::vector<std::string>& flags);
static void Help(string& ret); static void Help(std::string* ret);
virtual void DoCommand(); virtual void DoCommand();
virtual bool NoDBOpen() { return true; } virtual bool NoDBOpen() { return true; }
private: private:
string dbname_; std::string dbname_;
}; };
class ReduceDBLevelsCommand : public LDBCommand { class ReduceDBLevelsCommand : public LDBCommand {
public: public:
static string Name() { return "reduce_levels"; } static std::string Name() { return "reduce_levels"; }
ReduceDBLevelsCommand(const vector<string>& params, ReduceDBLevelsCommand(const std::vector<std::string>& params,
const map<string, string>& options, const vector<string>& flags); const std::map<std::string, std::string>& options,
const std::vector<std::string>& flags);
virtual Options PrepareOptionsForOpenDB(); virtual Options PrepareOptionsForOpenDB();
@ -526,169 +539,179 @@ public:
return true; return true;
} }
static void Help(string& msg); static void Help(std::string* msg);
static vector<string> PrepareArgs(const string& db_path, int new_levels, static std::vector<std::string> PrepareArgs(
const std::string& db_path,
int new_levels,
bool print_old_level = false); bool print_old_level = false);
private: private:
int old_levels_; int old_levels_;
int new_levels_; int new_levels_;
bool print_old_levels_; bool print_old_levels_;
static const string ARG_NEW_LEVELS; static const std::string ARG_NEW_LEVELS;
static const string ARG_PRINT_OLD_LEVELS; static const std::string ARG_PRINT_OLD_LEVELS;
Status GetOldNumOfLevels(Options& opt, int* levels); Status GetOldNumOfLevels(Options& opt, int* levels);
}; };
class ChangeCompactionStyleCommand : public LDBCommand { class ChangeCompactionStyleCommand : public LDBCommand {
public: public:
static string Name() { return "change_compaction_style"; } static std::string Name() { return "change_compaction_style"; }
ChangeCompactionStyleCommand(const vector<string>& params, ChangeCompactionStyleCommand(const std::vector<std::string>& params,
const map<string, string>& options, const vector<string>& flags); const std::map<std::string, std::string>& options,
const std::vector<std::string>& flags);
virtual Options PrepareOptionsForOpenDB(); virtual Options PrepareOptionsForOpenDB();
virtual void DoCommand(); virtual void DoCommand();
static void Help(string& msg); static void Help(std::string* msg);
private: private:
int old_compaction_style_; int old_compaction_style_;
int new_compaction_style_; int new_compaction_style_;
static const string ARG_OLD_COMPACTION_STYLE; static const std::string ARG_OLD_COMPACTION_STYLE;
static const string ARG_NEW_COMPACTION_STYLE; static const std::string ARG_NEW_COMPACTION_STYLE;
}; };
class WALDumperCommand : public LDBCommand { class WALDumperCommand : public LDBCommand {
public: public:
static string Name() { return "dump_wal"; } static std::string Name() { return "dump_wal"; }
WALDumperCommand(const vector<string>& params, WALDumperCommand(const std::vector<std::string>& params,
const map<string, string>& options, const vector<string>& flags); const std::map<std::string, std::string>& options,
const std::vector<std::string>& flags);
virtual bool NoDBOpen() { virtual bool NoDBOpen() {
return true; return true;
} }
static void Help(string& ret); static void Help(std::string* ret);
virtual void DoCommand(); virtual void DoCommand();
private: private:
bool print_header_; bool print_header_;
string wal_file_; std::string wal_file_;
bool print_values_; bool print_values_;
static const string ARG_WAL_FILE; static const std::string ARG_WAL_FILE;
static const string ARG_PRINT_HEADER; static const std::string ARG_PRINT_HEADER;
static const string ARG_PRINT_VALUE; static const std::string ARG_PRINT_VALUE;
}; };
class GetCommand : public LDBCommand { class GetCommand : public LDBCommand {
public: public:
static string Name() { return "get"; } static std::string Name() { return "get"; }
GetCommand(const vector<string>& params, const map<string, string>& options, GetCommand(const std::vector<std::string>& params,
const vector<string>& flags); const std::map<std::string, std::string>& options,
const std::vector<std::string>& flags);
virtual void DoCommand(); virtual void DoCommand();
static void Help(string& ret); static void Help(std::string* ret);
private: private:
string key_; std::string key_;
}; };
class ApproxSizeCommand : public LDBCommand { class ApproxSizeCommand : public LDBCommand {
public: public:
static string Name() { return "approxsize"; } static std::string Name() { return "approxsize"; }
ApproxSizeCommand(const vector<string>& params, ApproxSizeCommand(const std::vector<std::string>& params,
const map<string, string>& options, const vector<string>& flags); const std::map<std::string, std::string>& options,
const std::vector<std::string>& flags);
virtual void DoCommand(); virtual void DoCommand();
static void Help(string& ret); static void Help(std::string* ret);
private: private:
string start_key_; std::string start_key_;
string end_key_; std::string end_key_;
}; };
class BatchPutCommand : public LDBCommand { class BatchPutCommand : public LDBCommand {
public: public:
static string Name() { return "batchput"; } static std::string Name() { return "batchput"; }
BatchPutCommand(const vector<string>& params, BatchPutCommand(const std::vector<std::string>& params,
const map<string, string>& options, const vector<string>& flags); const std::map<std::string, std::string>& options,
const std::vector<std::string>& flags);
virtual void DoCommand(); virtual void DoCommand();
static void Help(string& ret); static void Help(std::string* ret);
virtual Options PrepareOptionsForOpenDB(); virtual Options PrepareOptionsForOpenDB();
private: private:
/** /**
* The key-values to be inserted. * The key-values to be inserted.
*/ */
vector<std::pair<string, string>> key_values_; std::vector<std::pair<std::string, std::string>> key_values_;
}; };
class ScanCommand : public LDBCommand { class ScanCommand : public LDBCommand {
public: public:
static string Name() { return "scan"; } static std::string Name() { return "scan"; }
ScanCommand(const vector<string>& params, const map<string, string>& options, ScanCommand(const std::vector<std::string>& params,
const vector<string>& flags); const std::map<std::string, std::string>& options,
const std::vector<std::string>& flags);
virtual void DoCommand(); virtual void DoCommand();
static void Help(string& ret); static void Help(std::string* ret);
private: private:
string start_key_; std::string start_key_;
string end_key_; std::string end_key_;
bool start_key_specified_; bool start_key_specified_;
bool end_key_specified_; bool end_key_specified_;
int max_keys_scanned_; int max_keys_scanned_;
}; };
class DeleteCommand : public LDBCommand { class DeleteCommand : public LDBCommand {
public: public:
static string Name() { return "delete"; } static std::string Name() { return "delete"; }
DeleteCommand(const vector<string>& params, DeleteCommand(const std::vector<std::string>& params,
const map<string, string>& options, const vector<string>& flags); const std::map<std::string, std::string>& options,
const std::vector<std::string>& flags);
virtual void DoCommand(); virtual void DoCommand();
static void Help(string& ret); static void Help(std::string* ret);
private: private:
string key_; std::string key_;
}; };
class PutCommand : public LDBCommand { class PutCommand : public LDBCommand {
public: public:
static string Name() { return "put"; } static std::string Name() { return "put"; }
PutCommand(const vector<string>& params, const map<string, string>& options, PutCommand(const std::vector<std::string>& params,
const vector<string>& flags); const std::map<std::string, std::string>& options,
const std::vector<std::string>& flags);
virtual void DoCommand(); virtual void DoCommand();
static void Help(string& ret); static void Help(std::string* ret);
virtual Options PrepareOptionsForOpenDB(); virtual Options PrepareOptionsForOpenDB();
private: private:
string key_; std::string key_;
string value_; std::string value_;
}; };
/** /**
@ -696,17 +719,18 @@ private:
* get/put/delete. * get/put/delete.
*/ */
class DBQuerierCommand: public LDBCommand { class DBQuerierCommand: public LDBCommand {
public: public:
static string Name() { return "query"; } static std::string Name() { return "query"; }
DBQuerierCommand(const vector<string>& params, DBQuerierCommand(const std::vector<std::string>& params,
const map<string, string>& options, const vector<string>& flags); const std::map<std::string, std::string>& options,
const std::vector<std::string>& flags);
static void Help(string& ret); static void Help(std::string* ret);
virtual void DoCommand(); virtual void DoCommand();
private: private:
static const char* HELP_CMD; static const char* HELP_CMD;
static const char* GET_CMD; static const char* GET_CMD;
static const char* PUT_CMD; static const char* PUT_CMD;
@ -714,11 +738,12 @@ private:
}; };
class CheckConsistencyCommand : public LDBCommand { class CheckConsistencyCommand : public LDBCommand {
public: public:
static string Name() { return "checkconsistency"; } static std::string Name() { return "checkconsistency"; }
CheckConsistencyCommand(const vector<string>& params, CheckConsistencyCommand(const std::vector<std::string>& params,
const map<string, string>& options, const vector<string>& flags); const std::map<std::string, std::string>& options,
const std::vector<std::string>& flags);
virtual void DoCommand(); virtual void DoCommand();
@ -726,7 +751,7 @@ public:
return true; return true;
} }
static void Help(string& ret); static void Help(std::string* ret);
}; };
} // namespace rocksdb } // namespace rocksdb

@ -15,7 +15,7 @@ public:
LDBCommandExecuteResult() : state_(EXEC_NOT_STARTED), message_("") {} LDBCommandExecuteResult() : state_(EXEC_NOT_STARTED), message_("") {}
LDBCommandExecuteResult(State state, std::string& msg) : LDBCommandExecuteResult(State state, const std::string& msg) :
state_(state), message_(msg) {} state_(state), message_(msg) {}
std::string ToString() { std::string ToString() {
@ -52,11 +52,11 @@ public:
return state_ == EXEC_FAILED; return state_ == EXEC_FAILED;
} }
static LDBCommandExecuteResult SUCCEED(std::string msg) { static LDBCommandExecuteResult SUCCEED(const std::string& msg) {
return LDBCommandExecuteResult(EXEC_SUCCEED, msg); return LDBCommandExecuteResult(EXEC_SUCCEED, msg);
} }
static LDBCommandExecuteResult FAILED(std::string msg) { static LDBCommandExecuteResult FAILED(const std::string& msg) {
return LDBCommandExecuteResult(EXEC_FAILED, msg); return LDBCommandExecuteResult(EXEC_FAILED, msg);
} }

@ -24,7 +24,7 @@ class LDBCommandRunner {
public: public:
static void PrintHelp(const char* exec_name) { static void PrintHelp(const char* exec_name) {
string ret; std::string ret;
ret.append("ldb - LevelDB Tool"); ret.append("ldb - LevelDB Tool");
ret.append("\n\n"); ret.append("\n\n");
@ -59,26 +59,26 @@ public:
ret.append("\n\n"); ret.append("\n\n");
ret.append("Data Access Commands:\n"); ret.append("Data Access Commands:\n");
PutCommand::Help(ret); PutCommand::Help(&ret);
GetCommand::Help(ret); GetCommand::Help(&ret);
BatchPutCommand::Help(ret); BatchPutCommand::Help(&ret);
ScanCommand::Help(ret); ScanCommand::Help(&ret);
DeleteCommand::Help(ret); DeleteCommand::Help(&ret);
DBQuerierCommand::Help(ret); DBQuerierCommand::Help(&ret);
ApproxSizeCommand::Help(ret); ApproxSizeCommand::Help(&ret);
CheckConsistencyCommand::Help(ret); CheckConsistencyCommand::Help(&ret);
ret.append("\n\n"); ret.append("\n\n");
ret.append("Admin Commands:\n"); ret.append("Admin Commands:\n");
WALDumperCommand::Help(ret); WALDumperCommand::Help(&ret);
CompactorCommand::Help(ret); CompactorCommand::Help(&ret);
ReduceDBLevelsCommand::Help(ret); ReduceDBLevelsCommand::Help(&ret);
ChangeCompactionStyleCommand::Help(ret); ChangeCompactionStyleCommand::Help(&ret);
DBDumperCommand::Help(ret); DBDumperCommand::Help(&ret);
DBLoaderCommand::Help(ret); DBLoaderCommand::Help(&ret);
ManifestDumpCommand::Help(ret); ManifestDumpCommand::Help(&ret);
ListColumnFamiliesCommand::Help(ret); ListColumnFamiliesCommand::Help(&ret);
InternalDumpCommand::Help(ret); InternalDumpCommand::Help(&ret);
fprintf(stderr, "%s\n", ret.c_str()); fprintf(stderr, "%s\n", ret.c_str());
} }

Loading…
Cancel
Save