Revert "Fix lint errors and coding style of ldb related codes."

This reverts commit bc9f36fd5e.
main
Igor Canadi 10 years ago
parent 45a612f990
commit 8e79ce68ce
  1. 4
      tools/sst_dump.cc
  2. 764
      util/ldb_cmd.cc
  3. 387
      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 {
std::string HexToString(const std::string& str) { string HexToString(const string& str) {
std::string parsed; 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,15 +4,12 @@
// 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 <map> #include <stdio.h>
#include <vector>
#include <utility>
#include "db/version_set.h" #include "db/version_set.h"
#include "rocksdb/env.h" #include "rocksdb/env.h"
@ -26,34 +23,39 @@
#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 std::string ARG_DB; static const string ARG_DB;
static const std::string ARG_HEX; static const string ARG_HEX;
static const std::string ARG_KEY_HEX; static const string ARG_KEY_HEX;
static const std::string ARG_VALUE_HEX; static const string ARG_VALUE_HEX;
static const std::string ARG_TTL; static const string ARG_TTL;
static const std::string ARG_TTL_START; static const string ARG_TTL_START;
static const std::string ARG_TTL_END; static const string ARG_TTL_END;
static const std::string ARG_TIMESTAMP; static const string ARG_TIMESTAMP;
static const std::string ARG_FROM; static const string ARG_FROM;
static const std::string ARG_TO; static const string ARG_TO;
static const std::string ARG_MAX_KEYS; static const string ARG_MAX_KEYS;
static const std::string ARG_BLOOM_BITS; static const string ARG_BLOOM_BITS;
static const std::string ARG_FIX_PREFIX_LEN; static const string ARG_FIX_PREFIX_LEN;
static const std::string ARG_COMPRESSION_TYPE; static const string ARG_COMPRESSION_TYPE;
static const std::string ARG_BLOCK_SIZE; static const string ARG_BLOCK_SIZE;
static const std::string ARG_AUTO_COMPACTION; static const string ARG_AUTO_COMPACTION;
static const std::string ARG_WRITE_BUFFER_SIZE; static const string ARG_WRITE_BUFFER_SIZE;
static const std::string ARG_FILE_SIZE; static const string ARG_FILE_SIZE;
static const std::string ARG_CREATE_IF_MISSING; static const string ARG_CREATE_IF_MISSING;
static LDBCommand* InitFromCmdLineArgs( static LDBCommand* InitFromCmdLineArgs(
const std::vector<std::string>& args, const vector<string>& args,
const Options& options, const Options& options,
const LDBOptions& ldb_options const LDBOptions& ldb_options
); );
@ -121,8 +123,8 @@ class LDBCommand {
exec_state_.Reset(); exec_state_.Reset();
} }
static std::string HexToString(const std::string& str) { static string HexToString(const string& str) {
std::string parsed; 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());
@ -138,8 +140,8 @@ class LDBCommand {
return parsed; return parsed;
} }
static std::string StringToHex(const std::string& str) { static string StringToHex(const string& str) {
std::string result = "0x"; 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]);
@ -153,7 +155,7 @@ class LDBCommand {
protected: protected:
LDBCommandExecuteResult exec_state_; LDBCommandExecuteResult exec_state_;
std::string db_path_; string db_path_;
DB* db_; DB* db_;
DBWithTTL* db_ttl_; DBWithTTL* db_ttl_;
@ -178,24 +180,21 @@ protected:
/** /**
* Map of options passed on the command-line. * Map of options passed on the command-line.
*/ */
const std::map<std::string, std::string> option_map_; const map<string, string> option_map_;
/** /**
* Flags passed on the command-line. * Flags passed on the command-line.
*/ */
const std::vector<std::string> flags_; const vector<string> flags_;
/** List of command-line options valid for this command */ /** List of command-line options valid for this command */
const std::vector<std::string> valid_cmd_line_options_; const vector<string> valid_cmd_line_options_;
bool ParseKeyValue(const std::string& line, bool ParseKeyValue(const string& line, string* key, string* value,
std::string* key, std::string* value,
bool is_key_hex, bool is_value_hex); bool is_key_hex, bool is_value_hex);
LDBCommand(const std::map<std::string, std::string>& options, LDBCommand(const map<string, string>& options, const vector<string>& flags,
const std::vector<std::string>& flags, bool is_read_only, const vector<string>& valid_cmd_line_options) :
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),
@ -206,7 +205,7 @@ protected:
flags_(flags), flags_(flags),
valid_cmd_line_options_(valid_cmd_line_options) { valid_cmd_line_options_(valid_cmd_line_options) {
auto itr = options.find(ARG_DB); map<string, string>::const_iterator itr = options.find(ARG_DB);
if (itr != options.end()) { if (itr != options.end()) {
db_path_ = itr->second; db_path_ = itr->second;
} }
@ -237,7 +236,7 @@ protected:
st = DB::Open(opt, db_path_, &db_); st = DB::Open(opt, db_path_, &db_);
} }
if (!st.ok()) { if (!st.ok()) {
std::string msg = st.ToString(); string msg = st.ToString();
exec_state_ = LDBCommandExecuteResult::FAILED(msg); exec_state_ = LDBCommandExecuteResult::FAILED(msg);
} }
@ -251,33 +250,29 @@ protected:
} }
} }
static std::string PrintKeyValue( static string PrintKeyValue(const string& key, const string& value,
const std::string& key, const std::string& value,
bool is_key_hex, bool is_value_hex) { bool is_key_hex, bool is_value_hex) {
std::string result; 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 std::string PrintKeyValue( static string PrintKeyValue(const string& key, const string& value,
const std::string& key, const std::string& value,
bool is_hex) { 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 * Return true if the specified flag is present in the specified flags vector
* flags vector
*/ */
static bool IsFlagPresent( static bool IsFlagPresent(const vector<string>& flags, const string& flag) {
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 std::string HelpRangeCmdArgs() { static string HelpRangeCmdArgs() {
std::ostringstream str_stream; ostringstream str_stream;
str_stream << " "; str_stream << " ";
str_stream << "[--" << ARG_FROM << "] "; str_stream << "[--" << ARG_FROM << "] ";
str_stream << "[--" << ARG_TO << "] "; str_stream << "[--" << ARG_TO << "] ";
@ -289,10 +284,8 @@ 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.
*/ */
std::vector<std::string> BuildCmdLineOptions( vector<string> BuildCmdLineOptions(vector<string> options) {
std::vector<std::string> options) { vector<string> ret = {ARG_DB, ARG_BLOOM_BITS,
std::vector<std::string> ret = {
ARG_DB, ARG_BLOOM_BITS,
ARG_BLOCK_SIZE, ARG_AUTO_COMPACTION, ARG_BLOCK_SIZE, ARG_AUTO_COMPACTION,
ARG_COMPRESSION_TYPE, ARG_WRITE_BUFFER_SIZE, ARG_COMPRESSION_TYPE, ARG_WRITE_BUFFER_SIZE,
ARG_FILE_SIZE, ARG_FIX_PREFIX_LEN}; ARG_FILE_SIZE, ARG_FIX_PREFIX_LEN};
@ -300,12 +293,11 @@ protected:
return ret; return ret;
} }
bool ParseIntOption(const std::map<std::string, std::string>& options, bool ParseIntOption(const map<string, string>& options, const string& option,
const std::string& option, int& value, LDBCommandExecuteResult& exec_state);
int* value, LDBCommandExecuteResult* exec_state);
bool ParseStringOption(const std::map<std::string, std::string>& options, bool ParseStringOption(const map<string, string>& options,
const std::string& option, std::string* value); const string& option, string* value);
Options options_; Options options_;
LDBOptions ldb_options_; LDBOptions ldb_options_;
@ -316,8 +308,8 @@ protected:
* 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 std::map<std::string, std::string>& options, bool IsKeyHex(const map<string, string>& options,
const std::vector<std::string>& flags) { const vector<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) ||
@ -328,8 +320,8 @@ protected:
* 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 std::map<std::string, std::string>& options, bool IsValueHex(const map<string, string>& options,
const std::vector<std::string>& flags) { const vector<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) ||
@ -342,13 +334,12 @@ protected:
* 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( bool ParseBooleanOption(const map<string, string>& options,
const std::map<std::string, std::string>& options, const string& option, bool default_val) {
const std::string& option, bool default_val) {
auto itr = options.find(option); map<string, string>::const_iterator itr = options.find(option);
if (itr != options.end()) { if (itr != options.end()) {
std::string option_val = itr->second; string option_val = itr->second;
return StringToBool(itr->second); return StringToBool(itr->second);
} }
return default_val; return default_val;
@ -359,7 +350,7 @@ protected:
* 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(std::string val) { bool StringToBool(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;
@ -371,102 +362,101 @@ protected:
} }
static LDBCommand* SelectCommand( static LDBCommand* SelectCommand(
const std::string& cmd, const string& cmd,
const std::vector<std::string>& cmdParams, const vector<string>& cmdParams,
const std::map<std::string, std::string>& option_map, const map<string, string>& option_map,
const std::vector<std::string>& flags const vector<string>& flags
); );
}; };
class CompactorCommand: public LDBCommand { class CompactorCommand: public LDBCommand {
public: public:
static std::string Name() { return "compact"; } static string Name() { return "compact"; }
CompactorCommand(const std::vector<std::string>& params, CompactorCommand(const vector<string>& params,
const std::map<std::string, std::string>& options, const map<string, string>& options, const vector<string>& flags);
const std::vector<std::string>& flags);
static void Help(std::string* ret); static void Help(string& ret);
virtual void DoCommand(); virtual void DoCommand();
private: private:
bool null_from_; bool null_from_;
std::string from_; string from_;
bool null_to_; bool null_to_;
std::string to_; string to_;
}; };
class DBDumperCommand: public LDBCommand { class DBDumperCommand: public LDBCommand {
public: public:
static std::string Name() { return "dump"; } static string Name() { return "dump"; }
DBDumperCommand(const std::vector<std::string>& params, DBDumperCommand(const vector<string>& params,
const std::map<std::string, std::string>& options, const map<string, string>& options, const vector<string>& flags);
const std::vector<std::string>& flags);
static void Help(std::string* ret); static void Help(string& ret);
virtual void DoCommand(); virtual void DoCommand();
private: private:
bool null_from_; bool null_from_;
std::string from_; string from_;
bool null_to_; bool null_to_;
std::string to_; string to_;
uint64_t max_keys_; int max_keys_;
std::string delim_; string delim_;
bool count_only_; bool count_only_;
bool count_delim_; bool count_delim_;
bool print_stats_; bool print_stats_;
static const std::string ARG_COUNT_ONLY; static const string ARG_COUNT_ONLY;
static const std::string ARG_COUNT_DELIM; static const string ARG_COUNT_DELIM;
static const std::string ARG_STATS; static const string ARG_STATS;
static const std::string ARG_TTL_BUCKET; static const string ARG_TTL_BUCKET;
}; };
class InternalDumpCommand: public LDBCommand { class InternalDumpCommand: public LDBCommand {
public: public:
static std::string Name() { return "idump"; } static string Name() { return "idump"; }
InternalDumpCommand(const std::vector<std::string>& params, InternalDumpCommand(const vector<string>& params,
const std::map<std::string, std::string>& options, const map<string, string>& options,
const std::vector<std::string>& flags); const vector<string>& flags);
static void Help(std::string* ret); static void Help(string& ret);
virtual void DoCommand(); virtual void DoCommand();
private: private:
bool has_from_; bool has_from_;
std::string from_; string from_;
bool has_to_; bool has_to_;
std::string to_; string to_;
int max_keys_; int max_keys_;
std::string delim_; 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 std::string ARG_DELIM; static const string ARG_DELIM;
static const std::string ARG_COUNT_ONLY; static const string ARG_COUNT_ONLY;
static const std::string ARG_COUNT_DELIM; static const string ARG_COUNT_DELIM;
static const std::string ARG_STATS; static const string ARG_STATS;
static const std::string ARG_INPUT_KEY_HEX; static const string ARG_INPUT_KEY_HEX;
}; };
class DBLoaderCommand: public LDBCommand { class DBLoaderCommand: public LDBCommand {
public: public:
static std::string Name() { return "load"; } static string Name() { return "load"; }
DBLoaderCommand(string& db_name, vector<string>& args);
DBLoaderCommand(const std::vector<std::string>& params, DBLoaderCommand(const vector<string>& params,
const std::map<std::string, std::string>& options, const map<string, string>& options, const vector<string>& flags);
const std::vector<std::string>& flags);
static void Help(std::string* ret); static void Help(string& ret);
virtual void DoCommand(); virtual void DoCommand();
virtual Options PrepareOptionsForOpenDB(); virtual Options PrepareOptionsForOpenDB();
@ -477,20 +467,19 @@ class DBLoaderCommand: public LDBCommand {
bool bulk_load_; bool bulk_load_;
bool compact_; bool compact_;
static const std::string ARG_DISABLE_WAL; static const string ARG_DISABLE_WAL;
static const std::string ARG_BULK_LOAD; static const string ARG_BULK_LOAD;
static const std::string ARG_COMPACT; static const string ARG_COMPACT;
}; };
class ManifestDumpCommand: public LDBCommand { class ManifestDumpCommand: public LDBCommand {
public: public:
static std::string Name() { return "manifest_dump"; } static string Name() { return "manifest_dump"; }
ManifestDumpCommand(const std::vector<std::string>& params, ManifestDumpCommand(const vector<string>& params,
const std::map<std::string, std::string>& options, const map<string, string>& options, const vector<string>& flags);
const std::vector<std::string>& flags);
static void Help(std::string* ret); static void Help(string& ret);
virtual void DoCommand(); virtual void DoCommand();
virtual bool NoDBOpen() { virtual bool NoDBOpen() {
@ -499,37 +488,35 @@ class ManifestDumpCommand: public LDBCommand {
private: private:
bool verbose_; bool verbose_;
std::string path_; string path_;
static const std::string ARG_VERBOSE; static const string ARG_VERBOSE;
static const std::string ARG_PATH; static const string ARG_PATH;
}; };
class ListColumnFamiliesCommand : public LDBCommand { class ListColumnFamiliesCommand : public LDBCommand {
public: public:
static std::string Name() { return "list_column_families"; } static string Name() { return "list_column_families"; }
ListColumnFamiliesCommand( ListColumnFamiliesCommand(const vector<string>& params,
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(std::string* ret); static void Help(string& ret);
virtual void DoCommand(); virtual void DoCommand();
virtual bool NoDBOpen() { return true; } virtual bool NoDBOpen() { return true; }
private: private:
std::string dbname_; string dbname_;
}; };
class ReduceDBLevelsCommand : public LDBCommand { class ReduceDBLevelsCommand : public LDBCommand {
public: public:
static std::string Name() { return "reduce_levels"; } static string Name() { return "reduce_levels"; }
ReduceDBLevelsCommand(const std::vector<std::string>& params, ReduceDBLevelsCommand(const vector<string>& params,
const std::map<std::string, std::string>& options, const map<string, string>& options, const vector<string>& flags);
const std::vector<std::string>& flags);
virtual Options PrepareOptionsForOpenDB(); virtual Options PrepareOptionsForOpenDB();
@ -539,11 +526,9 @@ class ReduceDBLevelsCommand : public LDBCommand {
return true; return true;
} }
static void Help(std::string* msg); static void Help(string& msg);
static std::vector<std::string> PrepareArgs( static vector<string> PrepareArgs(const string& db_path, int new_levels,
const std::string& db_path,
int new_levels,
bool print_old_level = false); bool print_old_level = false);
private: private:
@ -551,104 +536,99 @@ class ReduceDBLevelsCommand : public LDBCommand {
int new_levels_; int new_levels_;
bool print_old_levels_; bool print_old_levels_;
static const std::string ARG_NEW_LEVELS; static const string ARG_NEW_LEVELS;
static const std::string ARG_PRINT_OLD_LEVELS; static const 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 std::string Name() { return "change_compaction_style"; } static string Name() { return "change_compaction_style"; }
ChangeCompactionStyleCommand(const std::vector<std::string>& params, ChangeCompactionStyleCommand(const vector<string>& params,
const std::map<std::string, std::string>& options, const map<string, string>& options, const vector<string>& flags);
const std::vector<std::string>& flags);
virtual Options PrepareOptionsForOpenDB(); virtual Options PrepareOptionsForOpenDB();
virtual void DoCommand(); virtual void DoCommand();
static void Help(std::string* msg); static void Help(string& msg);
private: private:
int old_compaction_style_; int old_compaction_style_;
int new_compaction_style_; int new_compaction_style_;
static const std::string ARG_OLD_COMPACTION_STYLE; static const string ARG_OLD_COMPACTION_STYLE;
static const std::string ARG_NEW_COMPACTION_STYLE; static const string ARG_NEW_COMPACTION_STYLE;
}; };
class WALDumperCommand : public LDBCommand { class WALDumperCommand : public LDBCommand {
public: public:
static std::string Name() { return "dump_wal"; } static string Name() { return "dump_wal"; }
WALDumperCommand(const std::vector<std::string>& params, WALDumperCommand(const vector<string>& params,
const std::map<std::string, std::string>& options, const map<string, string>& options, const vector<string>& flags);
const std::vector<std::string>& flags);
virtual bool NoDBOpen() { virtual bool NoDBOpen() {
return true; return true;
} }
static void Help(std::string* ret); static void Help(string& ret);
virtual void DoCommand(); virtual void DoCommand();
private: private:
bool print_header_; bool print_header_;
std::string wal_file_; string wal_file_;
bool print_values_; bool print_values_;
static const std::string ARG_WAL_FILE; static const string ARG_WAL_FILE;
static const std::string ARG_PRINT_HEADER; static const string ARG_PRINT_HEADER;
static const std::string ARG_PRINT_VALUE; static const string ARG_PRINT_VALUE;
}; };
class GetCommand : public LDBCommand { class GetCommand : public LDBCommand {
public: public:
static std::string Name() { return "get"; } static string Name() { return "get"; }
GetCommand(const std::vector<std::string>& params, GetCommand(const vector<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);
virtual void DoCommand(); virtual void DoCommand();
static void Help(std::string* ret); static void Help(string& ret);
private: private:
std::string key_; string key_;
}; };
class ApproxSizeCommand : public LDBCommand { class ApproxSizeCommand : public LDBCommand {
public: public:
static std::string Name() { return "approxsize"; } static string Name() { return "approxsize"; }
ApproxSizeCommand(const std::vector<std::string>& params, ApproxSizeCommand(const vector<string>& params,
const std::map<std::string, std::string>& options, const map<string, string>& options, const vector<string>& flags);
const std::vector<std::string>& flags);
virtual void DoCommand(); virtual void DoCommand();
static void Help(std::string* ret); static void Help(string& ret);
private: private:
std::string start_key_; string start_key_;
std::string end_key_; string end_key_;
}; };
class BatchPutCommand : public LDBCommand { class BatchPutCommand : public LDBCommand {
public: public:
static std::string Name() { return "batchput"; } static string Name() { return "batchput"; }
BatchPutCommand(const std::vector<std::string>& params, BatchPutCommand(const vector<string>& params,
const std::map<std::string, std::string>& options, const map<string, string>& options, const vector<string>& flags);
const std::vector<std::string>& flags);
virtual void DoCommand(); virtual void DoCommand();
static void Help(std::string* ret); static void Help(string& ret);
virtual Options PrepareOptionsForOpenDB(); virtual Options PrepareOptionsForOpenDB();
@ -656,24 +636,23 @@ class BatchPutCommand : public LDBCommand {
/** /**
* The key-values to be inserted. * The key-values to be inserted.
*/ */
std::vector<std::pair<std::string, std::string>> key_values_; vector<std::pair<string, string>> key_values_;
}; };
class ScanCommand : public LDBCommand { class ScanCommand : public LDBCommand {
public: public:
static std::string Name() { return "scan"; } static string Name() { return "scan"; }
ScanCommand(const std::vector<std::string>& params, ScanCommand(const vector<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);
virtual void DoCommand(); virtual void DoCommand();
static void Help(std::string* ret); static void Help(string& ret);
private: private:
std::string start_key_; string start_key_;
std::string end_key_; 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_;
@ -681,37 +660,35 @@ class ScanCommand : public LDBCommand {
class DeleteCommand : public LDBCommand { class DeleteCommand : public LDBCommand {
public: public:
static std::string Name() { return "delete"; } static string Name() { return "delete"; }
DeleteCommand(const std::vector<std::string>& params, DeleteCommand(const vector<string>& params,
const std::map<std::string, std::string>& options, const map<string, string>& options, const vector<string>& flags);
const std::vector<std::string>& flags);
virtual void DoCommand(); virtual void DoCommand();
static void Help(std::string* ret); static void Help(string& ret);
private: private:
std::string key_; string key_;
}; };
class PutCommand : public LDBCommand { class PutCommand : public LDBCommand {
public: public:
static std::string Name() { return "put"; } static string Name() { return "put"; }
PutCommand(const std::vector<std::string>& params, PutCommand(const vector<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);
virtual void DoCommand(); virtual void DoCommand();
static void Help(std::string* ret); static void Help(string& ret);
virtual Options PrepareOptionsForOpenDB(); virtual Options PrepareOptionsForOpenDB();
private: private:
std::string key_; string key_;
std::string value_; string value_;
}; };
/** /**
@ -720,13 +697,12 @@ class PutCommand : public LDBCommand {
*/ */
class DBQuerierCommand: public LDBCommand { class DBQuerierCommand: public LDBCommand {
public: public:
static std::string Name() { return "query"; } static string Name() { return "query"; }
DBQuerierCommand(const std::vector<std::string>& params, DBQuerierCommand(const vector<string>& params,
const std::map<std::string, std::string>& options, const map<string, string>& options, const vector<string>& flags);
const std::vector<std::string>& flags);
static void Help(std::string* ret); static void Help(string& ret);
virtual void DoCommand(); virtual void DoCommand();
@ -739,11 +715,10 @@ class DBQuerierCommand: public LDBCommand {
class CheckConsistencyCommand : public LDBCommand { class CheckConsistencyCommand : public LDBCommand {
public: public:
static std::string Name() { return "checkconsistency"; } static string Name() { return "checkconsistency"; }
CheckConsistencyCommand(const std::vector<std::string>& params, CheckConsistencyCommand(const vector<string>& params,
const std::map<std::string, std::string>& options, const map<string, string>& options, const vector<string>& flags);
const std::vector<std::string>& flags);
virtual void DoCommand(); virtual void DoCommand();
@ -751,7 +726,7 @@ class CheckConsistencyCommand : public LDBCommand {
return true; return true;
} }
static void Help(std::string* ret); static void Help(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, const std::string& msg) : LDBCommandExecuteResult(State state, 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(const std::string& msg) { static LDBCommandExecuteResult SUCCEED(std::string msg) {
return LDBCommandExecuteResult(EXEC_SUCCEED, msg); return LDBCommandExecuteResult(EXEC_SUCCEED, msg);
} }
static LDBCommandExecuteResult FAILED(const std::string& msg) { static LDBCommandExecuteResult FAILED(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) {
std::string ret; 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