fork of https://github.com/oxigraph/rocksdb and https://github.com/facebook/rocksdb for nextgraph and oxigraph
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
770 lines
19 KiB
770 lines
19 KiB
11 years ago
|
// Copyright (c) 2013, Facebook, Inc. All rights reserved.
|
||
|
// This source code is licensed under the BSD-style license found in the
|
||
|
// LICENSE file in the root directory of this source tree. An additional grant
|
||
|
// of patent rights can be found in the PATENTS file in the same directory.
|
||
|
//
|
||
11 years ago
|
#pragma once
|
||
10 years ago
|
|
||
|
#ifndef ROCKSDB_LITE
|
||
|
|
||
12 years ago
|
#include <string>
|
||
|
#include <iostream>
|
||
|
#include <sstream>
|
||
10 years ago
|
#include <stdlib.h>
|
||
12 years ago
|
#include <algorithm>
|
||
10 years ago
|
#include <stdio.h>
|
||
10 years ago
|
#include <vector>
|
||
|
#include <map>
|
||
12 years ago
|
|
||
12 years ago
|
#include "db/version_set.h"
|
||
12 years ago
|
#include "rocksdb/env.h"
|
||
|
#include "rocksdb/iterator.h"
|
||
11 years ago
|
#include "rocksdb/ldb_tool.h"
|
||
|
#include "rocksdb/options.h"
|
||
12 years ago
|
#include "rocksdb/slice.h"
|
||
11 years ago
|
#include "rocksdb/utilities/db_ttl.h"
|
||
9 years ago
|
#include "tools/ldb_cmd_execute_result.h"
|
||
12 years ago
|
#include "util/logging.h"
|
||
12 years ago
|
#include "util/string_util.h"
|
||
11 years ago
|
#include "utilities/ttl/db_ttl_impl.h"
|
||
12 years ago
|
|
||
10 years ago
|
using std::string;
|
||
|
using std::map;
|
||
|
using std::vector;
|
||
|
using std::ostringstream;
|
||
|
|
||
11 years ago
|
namespace rocksdb {
|
||
12 years ago
|
|
||
|
class LDBCommand {
|
||
10 years ago
|
public:
|
||
12 years ago
|
|
||
12 years ago
|
// Command-line arguments
|
||
10 years ago
|
static const string ARG_DB;
|
||
|
static const string ARG_HEX;
|
||
|
static const string ARG_KEY_HEX;
|
||
|
static const string ARG_VALUE_HEX;
|
||
|
static const string ARG_TTL;
|
||
|
static const string ARG_TTL_START;
|
||
|
static const string ARG_TTL_END;
|
||
|
static const string ARG_TIMESTAMP;
|
||
|
static const string ARG_FROM;
|
||
|
static const string ARG_TO;
|
||
|
static const string ARG_MAX_KEYS;
|
||
|
static const string ARG_BLOOM_BITS;
|
||
|
static const string ARG_FIX_PREFIX_LEN;
|
||
|
static const string ARG_COMPRESSION_TYPE;
|
||
|
static const string ARG_BLOCK_SIZE;
|
||
|
static const string ARG_AUTO_COMPACTION;
|
||
10 years ago
|
static const string ARG_DB_WRITE_BUFFER_SIZE;
|
||
10 years ago
|
static const string ARG_WRITE_BUFFER_SIZE;
|
||
|
static const string ARG_FILE_SIZE;
|
||
|
static const string ARG_CREATE_IF_MISSING;
|
||
12 years ago
|
|
||
12 years ago
|
static LDBCommand* InitFromCmdLineArgs(
|
||
10 years ago
|
const vector<string>& args,
|
||
11 years ago
|
const Options& options,
|
||
|
const LDBOptions& ldb_options
|
||
12 years ago
|
);
|
||
|
|
||
|
static LDBCommand* InitFromCmdLineArgs(
|
||
|
int argc,
|
||
|
char** argv,
|
||
11 years ago
|
const Options& options,
|
||
|
const LDBOptions& ldb_options
|
||
12 years ago
|
);
|
||
|
|
||
12 years ago
|
bool ValidateCmdLineOptions();
|
||
12 years ago
|
|
||
12 years ago
|
virtual Options PrepareOptionsForOpenDB();
|
||
|
|
||
11 years ago
|
virtual void SetDBOptions(Options options) {
|
||
12 years ago
|
options_ = options;
|
||
|
}
|
||
12 years ago
|
|
||
11 years ago
|
void SetLDBOptions(const LDBOptions& ldb_options) {
|
||
|
ldb_options_ = ldb_options;
|
||
|
}
|
||
|
|
||
12 years ago
|
virtual bool NoDBOpen() {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
12 years ago
|
virtual ~LDBCommand() {
|
||
12 years ago
|
if (db_ != nullptr) {
|
||
12 years ago
|
delete db_;
|
||
12 years ago
|
db_ = nullptr;
|
||
12 years ago
|
}
|
||
|
}
|
||
|
|
||
|
/* Run the command, and return the execute result. */
|
||
|
void Run() {
|
||
|
if (!exec_state_.IsNotStarted()) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
12 years ago
|
if (db_ == nullptr && !NoDBOpen()) {
|
||
12 years ago
|
OpenDB();
|
||
12 years ago
|
if (!exec_state_.IsNotStarted()) {
|
||
|
return;
|
||
|
}
|
||
12 years ago
|
}
|
||
12 years ago
|
|
||
12 years ago
|
DoCommand();
|
||
|
if (exec_state_.IsNotStarted()) {
|
||
10 years ago
|
exec_state_ = LDBCommandExecuteResult::Succeed("");
|
||
12 years ago
|
}
|
||
12 years ago
|
|
||
12 years ago
|
if (db_ != nullptr) {
|
||
12 years ago
|
CloseDB ();
|
||
|
}
|
||
12 years ago
|
}
|
||
|
|
||
|
virtual void DoCommand() = 0;
|
||
|
|
||
|
LDBCommandExecuteResult GetExecuteState() {
|
||
|
return exec_state_;
|
||
|
}
|
||
|
|
||
|
void ClearPreviousRunState() {
|
||
|
exec_state_.Reset();
|
||
|
}
|
||
|
|
||
10 years ago
|
static string HexToString(const string& str) {
|
||
9 years ago
|
std::string::size_type len = str.length();
|
||
10 years ago
|
string parsed;
|
||
9 years ago
|
static const char* const hexas = "0123456789ABCDEF";
|
||
|
parsed.reserve(len / 2);
|
||
|
|
||
|
if (len < 2 || str[0] != '0' || str[1] != 'x') {
|
||
12 years ago
|
fprintf(stderr, "Invalid hex input %s. Must start with 0x\n",
|
||
|
str.c_str());
|
||
|
throw "Invalid hex input";
|
||
|
}
|
||
|
|
||
9 years ago
|
for (unsigned int i = 2; i < len; i += 2) {
|
||
|
char a = static_cast<char>(toupper(str[i]));
|
||
|
const char* p = std::lower_bound(hexas, hexas + 16, a);
|
||
|
if (*p != a) {
|
||
|
throw "Invalid hex value";
|
||
|
}
|
||
|
|
||
|
if (i + 1 >= len) {
|
||
|
// if odd number of chars than we just hit end of string
|
||
|
parsed.push_back(p - hexas);
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
char b = static_cast<char>(toupper(str[i + 1]));
|
||
|
const char* q = std::lower_bound(hexas, hexas + 16, b);
|
||
|
if (*q == b) {
|
||
|
// pairwise compute decimal value from hex
|
||
|
parsed.push_back(((p - hexas) << 4) | (q - hexas));
|
||
|
} else {
|
||
|
throw "Invalid hex value";
|
||
|
}
|
||
12 years ago
|
}
|
||
|
return parsed;
|
||
|
}
|
||
|
|
||
10 years ago
|
static string StringToHex(const string& str) {
|
||
|
string result = "0x";
|
||
12 years ago
|
char buf[10];
|
||
|
for (size_t i = 0; i < str.length(); i++) {
|
||
|
snprintf(buf, 10, "%02X", (unsigned char)str[i]);
|
||
|
result += buf;
|
||
|
}
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
static const char* DELIM;
|
||
12 years ago
|
|
||
|
protected:
|
||
|
|
||
|
LDBCommandExecuteResult exec_state_;
|
||
10 years ago
|
string db_path_;
|
||
12 years ago
|
DB* db_;
|
||
11 years ago
|
DBWithTTL* db_ttl_;
|
||
12 years ago
|
|
||
|
/**
|
||
|
* true implies that this command can work if the db is opened in read-only
|
||
|
* mode.
|
||
|
*/
|
||
|
bool is_read_only_;
|
||
|
|
||
|
/** If true, the key is input/output as hex in get/put/scan/delete etc. */
|
||
|
bool is_key_hex_;
|
||
|
|
||
|
/** If true, the value is input/output as hex in get/put/scan/delete etc. */
|
||
|
bool is_value_hex_;
|
||
|
|
||
12 years ago
|
/** If true, the value is treated as timestamp suffixed */
|
||
|
bool is_db_ttl_;
|
||
|
|
||
12 years ago
|
// If true, the kvs are output with their insert/modify timestamp in a ttl db
|
||
|
bool timestamp_;
|
||
|
|
||
12 years ago
|
/**
|
||
|
* Map of options passed on the command-line.
|
||
|
*/
|
||
10 years ago
|
const map<string, string> option_map_;
|
||
12 years ago
|
|
||
|
/**
|
||
|
* Flags passed on the command-line.
|
||
|
*/
|
||
10 years ago
|
const vector<string> flags_;
|
||
12 years ago
|
|
||
|
/** List of command-line options valid for this command */
|
||
10 years ago
|
const vector<string> valid_cmd_line_options_;
|
||
12 years ago
|
|
||
10 years ago
|
bool ParseKeyValue(const string& line, string* key, string* value,
|
||
|
bool is_key_hex, bool is_value_hex);
|
||
12 years ago
|
|
||
10 years ago
|
LDBCommand(const map<string, string>& options, const vector<string>& flags,
|
||
|
bool is_read_only, const vector<string>& valid_cmd_line_options) :
|
||
12 years ago
|
db_(nullptr),
|
||
12 years ago
|
is_read_only_(is_read_only),
|
||
|
is_key_hex_(false),
|
||
|
is_value_hex_(false),
|
||
12 years ago
|
is_db_ttl_(false),
|
||
12 years ago
|
timestamp_(false),
|
||
12 years ago
|
option_map_(options),
|
||
12 years ago
|
flags_(flags),
|
||
|
valid_cmd_line_options_(valid_cmd_line_options) {
|
||
|
|
||
10 years ago
|
map<string, string>::const_iterator itr = options.find(ARG_DB);
|
||
12 years ago
|
if (itr != options.end()) {
|
||
|
db_path_ = itr->second;
|
||
12 years ago
|
}
|
||
|
|
||
12 years ago
|
is_key_hex_ = IsKeyHex(options, flags);
|
||
|
is_value_hex_ = IsValueHex(options, flags);
|
||
12 years ago
|
is_db_ttl_ = IsFlagPresent(flags, ARG_TTL);
|
||
12 years ago
|
timestamp_ = IsFlagPresent(flags, ARG_TIMESTAMP);
|
||
12 years ago
|
}
|
||
|
|
||
12 years ago
|
void OpenDB() {
|
||
12 years ago
|
Options opt = PrepareOptionsForOpenDB();
|
||
12 years ago
|
if (!exec_state_.IsNotStarted()) {
|
||
|
return;
|
||
|
}
|
||
12 years ago
|
// Open the DB.
|
||
12 years ago
|
Status st;
|
||
12 years ago
|
if (is_db_ttl_) {
|
||
|
if (is_read_only_) {
|
||
11 years ago
|
st = DBWithTTL::Open(opt, db_path_, &db_ttl_, 0, true);
|
||
12 years ago
|
} else {
|
||
11 years ago
|
st = DBWithTTL::Open(opt, db_path_, &db_ttl_);
|
||
12 years ago
|
}
|
||
11 years ago
|
db_ = db_ttl_;
|
||
12 years ago
|
} else if (is_read_only_) {
|
||
12 years ago
|
st = DB::OpenForReadOnly(opt, db_path_, &db_);
|
||
12 years ago
|
} else {
|
||
12 years ago
|
st = DB::Open(opt, db_path_, &db_);
|
||
12 years ago
|
}
|
||
12 years ago
|
if (!st.ok()) {
|
||
10 years ago
|
string msg = st.ToString();
|
||
10 years ago
|
exec_state_ = LDBCommandExecuteResult::Failed(msg);
|
||
12 years ago
|
}
|
||
12 years ago
|
|
||
|
options_ = opt;
|
||
12 years ago
|
}
|
||
|
|
||
|
void CloseDB () {
|
||
12 years ago
|
if (db_ != nullptr) {
|
||
12 years ago
|
delete db_;
|
||
12 years ago
|
db_ = nullptr;
|
||
12 years ago
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
static string PrintKeyValue(const string& key, const string& value,
|
||
|
bool is_key_hex, bool is_value_hex) {
|
||
|
string result;
|
||
12 years ago
|
result.append(is_key_hex ? StringToHex(key) : key);
|
||
|
result.append(DELIM);
|
||
|
result.append(is_value_hex ? StringToHex(value) : value);
|
||
|
return result;
|
||
|
}
|
||
|
|
||
10 years ago
|
static string PrintKeyValue(const string& key, const string& value,
|
||
|
bool is_hex) {
|
||
12 years ago
|
return PrintKeyValue(key, value, is_hex, is_hex);
|
||
|
}
|
||
|
|
||
|
/**
|
||
10 years ago
|
* Return true if the specified flag is present in the specified flags vector
|
||
12 years ago
|
*/
|
||
10 years ago
|
static bool IsFlagPresent(const vector<string>& flags, const string& flag) {
|
||
12 years ago
|
return (std::find(flags.begin(), flags.end(), flag) != flags.end());
|
||
|
}
|
||
|
|
||
10 years ago
|
static string HelpRangeCmdArgs() {
|
||
|
ostringstream str_stream;
|
||
12 years ago
|
str_stream << " ";
|
||
|
str_stream << "[--" << ARG_FROM << "] ";
|
||
|
str_stream << "[--" << ARG_TO << "] ";
|
||
|
return str_stream.str();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* A helper function that returns a list of command line options
|
||
|
* used by this command. It includes the common options and the ones
|
||
|
* passed in.
|
||
|
*/
|
||
10 years ago
|
static vector<string> BuildCmdLineOptions(vector<string> options) {
|
||
10 years ago
|
vector<string> ret = {ARG_DB, ARG_BLOOM_BITS,
|
||
|
ARG_BLOCK_SIZE, ARG_AUTO_COMPACTION,
|
||
|
ARG_COMPRESSION_TYPE, ARG_WRITE_BUFFER_SIZE,
|
||
|
ARG_FILE_SIZE, ARG_FIX_PREFIX_LEN};
|
||
12 years ago
|
ret.insert(ret.end(), options.begin(), options.end());
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
10 years ago
|
bool ParseIntOption(const map<string, string>& options, const string& option,
|
||
|
int& value, LDBCommandExecuteResult& exec_state);
|
||
12 years ago
|
|
||
10 years ago
|
bool ParseStringOption(const map<string, string>& options,
|
||
|
const string& option, string* value);
|
||
12 years ago
|
|
||
12 years ago
|
Options options_;
|
||
11 years ago
|
LDBOptions ldb_options_;
|
||
12 years ago
|
|
||
10 years ago
|
private:
|
||
12 years ago
|
|
||
12 years ago
|
/**
|
||
|
* Interpret command line options and flags to determine if the key
|
||
|
* should be input/output in hex.
|
||
|
*/
|
||
10 years ago
|
bool IsKeyHex(const map<string, string>& options,
|
||
|
const vector<string>& flags) {
|
||
12 years ago
|
return (IsFlagPresent(flags, ARG_HEX) ||
|
||
|
IsFlagPresent(flags, ARG_KEY_HEX) ||
|
||
|
ParseBooleanOption(options, ARG_HEX, false) ||
|
||
|
ParseBooleanOption(options, ARG_KEY_HEX, false));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Interpret command line options and flags to determine if the value
|
||
|
* should be input/output in hex.
|
||
|
*/
|
||
10 years ago
|
bool IsValueHex(const map<string, string>& options,
|
||
|
const vector<string>& flags) {
|
||
12 years ago
|
return (IsFlagPresent(flags, ARG_HEX) ||
|
||
|
IsFlagPresent(flags, ARG_VALUE_HEX) ||
|
||
|
ParseBooleanOption(options, ARG_HEX, false) ||
|
||
|
ParseBooleanOption(options, ARG_VALUE_HEX, false));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Returns the value of the specified option as a boolean.
|
||
|
* default_val is used if the option is not found in options.
|
||
|
* Throws an exception if the value of the option is not
|
||
|
* "true" or "false" (case insensitive).
|
||
|
*/
|
||
10 years ago
|
bool ParseBooleanOption(const map<string, string>& options,
|
||
|
const string& option, bool default_val) {
|
||
12 years ago
|
|
||
10 years ago
|
map<string, string>::const_iterator itr = options.find(option);
|
||
12 years ago
|
if (itr != options.end()) {
|
||
10 years ago
|
string option_val = itr->second;
|
||
12 years ago
|
return StringToBool(itr->second);
|
||
|
}
|
||
|
return default_val;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Converts val to a boolean.
|
||
|
* val must be either true or false (case insensitive).
|
||
|
* Otherwise an exception is thrown.
|
||
|
*/
|
||
10 years ago
|
bool StringToBool(string val) {
|
||
10 years ago
|
std::transform(val.begin(), val.end(), val.begin(),
|
||
10 years ago
|
[](char ch) -> char { return ::tolower(ch); });
|
||
|
|
||
12 years ago
|
if (val == "true") {
|
||
|
return true;
|
||
|
} else if (val == "false") {
|
||
|
return false;
|
||
|
} else {
|
||
|
throw "Invalid value for boolean argument";
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
static LDBCommand* SelectCommand(
|
||
10 years ago
|
const string& cmd,
|
||
|
const vector<string>& cmdParams,
|
||
|
const map<string, string>& option_map,
|
||
|
const vector<string>& flags
|
||
12 years ago
|
);
|
||
|
|
||
12 years ago
|
};
|
||
|
|
||
12 years ago
|
class CompactorCommand: public LDBCommand {
|
||
10 years ago
|
public:
|
||
|
static string Name() { return "compact"; }
|
||
12 years ago
|
|
||
10 years ago
|
CompactorCommand(const vector<string>& params,
|
||
|
const map<string, string>& options, const vector<string>& flags);
|
||
12 years ago
|
|
||
10 years ago
|
static void Help(string& ret);
|
||
12 years ago
|
|
||
10 years ago
|
virtual void DoCommand() override;
|
||
12 years ago
|
|
||
10 years ago
|
private:
|
||
12 years ago
|
bool null_from_;
|
||
10 years ago
|
string from_;
|
||
12 years ago
|
bool null_to_;
|
||
10 years ago
|
string to_;
|
||
12 years ago
|
};
|
||
|
|
||
10 years ago
|
class DBFileDumperCommand : public LDBCommand {
|
||
|
public:
|
||
|
static string Name() { return "dump_live_files"; }
|
||
|
|
||
|
DBFileDumperCommand(const vector<string>& params,
|
||
|
const map<string, string>& options,
|
||
|
const vector<string>& flags);
|
||
|
|
||
|
static void Help(string& ret);
|
||
|
|
||
10 years ago
|
virtual void DoCommand() override;
|
||
10 years ago
|
};
|
||
|
|
||
12 years ago
|
class DBDumperCommand: public LDBCommand {
|
||
10 years ago
|
public:
|
||
|
static string Name() { return "dump"; }
|
||
12 years ago
|
|
||
10 years ago
|
DBDumperCommand(const vector<string>& params,
|
||
|
const map<string, string>& options, const vector<string>& flags);
|
||
12 years ago
|
|
||
10 years ago
|
static void Help(string& ret);
|
||
12 years ago
|
|
||
10 years ago
|
virtual void DoCommand() override;
|
||
12 years ago
|
|
||
10 years ago
|
private:
|
||
12 years ago
|
bool null_from_;
|
||
10 years ago
|
string from_;
|
||
12 years ago
|
bool null_to_;
|
||
10 years ago
|
string to_;
|
||
|
int max_keys_;
|
||
|
string delim_;
|
||
12 years ago
|
bool count_only_;
|
||
11 years ago
|
bool count_delim_;
|
||
12 years ago
|
bool print_stats_;
|
||
|
|
||
10 years ago
|
static const string ARG_COUNT_ONLY;
|
||
|
static const string ARG_COUNT_DELIM;
|
||
|
static const string ARG_STATS;
|
||
|
static const string ARG_TTL_BUCKET;
|
||
12 years ago
|
};
|
||
|
|
||
12 years ago
|
class InternalDumpCommand: public LDBCommand {
|
||
10 years ago
|
public:
|
||
|
static string Name() { return "idump"; }
|
||
12 years ago
|
|
||
10 years ago
|
InternalDumpCommand(const vector<string>& params,
|
||
|
const map<string, string>& options,
|
||
|
const vector<string>& flags);
|
||
12 years ago
|
|
||
10 years ago
|
static void Help(string& ret);
|
||
12 years ago
|
|
||
10 years ago
|
virtual void DoCommand() override;
|
||
12 years ago
|
|
||
10 years ago
|
private:
|
||
12 years ago
|
bool has_from_;
|
||
10 years ago
|
string from_;
|
||
12 years ago
|
bool has_to_;
|
||
10 years ago
|
string to_;
|
||
12 years ago
|
int max_keys_;
|
||
10 years ago
|
string delim_;
|
||
12 years ago
|
bool count_only_;
|
||
11 years ago
|
bool count_delim_;
|
||
12 years ago
|
bool print_stats_;
|
||
12 years ago
|
bool is_input_key_hex_;
|
||
12 years ago
|
|
||
10 years ago
|
static const string ARG_DELIM;
|
||
|
static const string ARG_COUNT_ONLY;
|
||
|
static const string ARG_COUNT_DELIM;
|
||
|
static const string ARG_STATS;
|
||
|
static const string ARG_INPUT_KEY_HEX;
|
||
12 years ago
|
};
|
||
|
|
||
12 years ago
|
class DBLoaderCommand: public LDBCommand {
|
||
10 years ago
|
public:
|
||
|
static string Name() { return "load"; }
|
||
12 years ago
|
|
||
10 years ago
|
DBLoaderCommand(string& db_name, vector<string>& args);
|
||
12 years ago
|
|
||
10 years ago
|
DBLoaderCommand(const vector<string>& params,
|
||
|
const map<string, string>& options, const vector<string>& flags);
|
||
|
|
||
|
static void Help(string& ret);
|
||
10 years ago
|
virtual void DoCommand() override;
|
||
12 years ago
|
|
||
10 years ago
|
virtual Options PrepareOptionsForOpenDB() override;
|
||
12 years ago
|
|
||
10 years ago
|
private:
|
||
12 years ago
|
bool create_if_missing_;
|
||
|
bool disable_wal_;
|
||
12 years ago
|
bool bulk_load_;
|
||
|
bool compact_;
|
||
12 years ago
|
|
||
10 years ago
|
static const string ARG_DISABLE_WAL;
|
||
|
static const string ARG_BULK_LOAD;
|
||
|
static const string ARG_COMPACT;
|
||
12 years ago
|
};
|
||
|
|
||
12 years ago
|
class ManifestDumpCommand: public LDBCommand {
|
||
10 years ago
|
public:
|
||
|
static string Name() { return "manifest_dump"; }
|
||
12 years ago
|
|
||
10 years ago
|
ManifestDumpCommand(const vector<string>& params,
|
||
|
const map<string, string>& options, const vector<string>& flags);
|
||
12 years ago
|
|
||
10 years ago
|
static void Help(string& ret);
|
||
10 years ago
|
virtual void DoCommand() override;
|
||
12 years ago
|
|
||
10 years ago
|
virtual bool NoDBOpen() override { return true; }
|
||
12 years ago
|
|
||
10 years ago
|
private:
|
||
12 years ago
|
bool verbose_;
|
||
10 years ago
|
bool json_;
|
||
10 years ago
|
string path_;
|
||
12 years ago
|
|
||
10 years ago
|
static const string ARG_VERBOSE;
|
||
10 years ago
|
static const string ARG_JSON;
|
||
10 years ago
|
static const string ARG_PATH;
|
||
12 years ago
|
};
|
||
|
|
||
11 years ago
|
class ListColumnFamiliesCommand : public LDBCommand {
|
||
|
public:
|
||
10 years ago
|
static string Name() { return "list_column_families"; }
|
||
11 years ago
|
|
||
10 years ago
|
ListColumnFamiliesCommand(const vector<string>& params,
|
||
|
const map<string, string>& options,
|
||
|
const vector<string>& flags);
|
||
11 years ago
|
|
||
10 years ago
|
static void Help(string& ret);
|
||
10 years ago
|
virtual void DoCommand() override;
|
||
11 years ago
|
|
||
10 years ago
|
virtual bool NoDBOpen() override { return true; }
|
||
11 years ago
|
|
||
|
private:
|
||
10 years ago
|
string dbname_;
|
||
11 years ago
|
};
|
||
|
|
||
12 years ago
|
class ReduceDBLevelsCommand : public LDBCommand {
|
||
10 years ago
|
public:
|
||
|
static string Name() { return "reduce_levels"; }
|
||
12 years ago
|
|
||
10 years ago
|
ReduceDBLevelsCommand(const vector<string>& params,
|
||
|
const map<string, string>& options, const vector<string>& flags);
|
||
12 years ago
|
|
||
10 years ago
|
virtual Options PrepareOptionsForOpenDB() override;
|
||
12 years ago
|
|
||
10 years ago
|
virtual void DoCommand() override;
|
||
12 years ago
|
|
||
10 years ago
|
virtual bool NoDBOpen() override { return true; }
|
||
12 years ago
|
|
||
10 years ago
|
static void Help(string& msg);
|
||
12 years ago
|
|
||
10 years ago
|
static vector<string> PrepareArgs(const string& db_path, int new_levels,
|
||
12 years ago
|
bool print_old_level = false);
|
||
|
|
||
10 years ago
|
private:
|
||
12 years ago
|
int old_levels_;
|
||
12 years ago
|
int new_levels_;
|
||
|
bool print_old_levels_;
|
||
|
|
||
10 years ago
|
static const string ARG_NEW_LEVELS;
|
||
|
static const string ARG_PRINT_OLD_LEVELS;
|
||
12 years ago
|
|
||
12 years ago
|
Status GetOldNumOfLevels(Options& opt, int* levels);
|
||
12 years ago
|
};
|
||
|
|
||
11 years ago
|
class ChangeCompactionStyleCommand : public LDBCommand {
|
||
10 years ago
|
public:
|
||
|
static string Name() { return "change_compaction_style"; }
|
||
11 years ago
|
|
||
10 years ago
|
ChangeCompactionStyleCommand(const vector<string>& params,
|
||
|
const map<string, string>& options, const vector<string>& flags);
|
||
11 years ago
|
|
||
10 years ago
|
virtual Options PrepareOptionsForOpenDB() override;
|
||
11 years ago
|
|
||
10 years ago
|
virtual void DoCommand() override;
|
||
11 years ago
|
|
||
10 years ago
|
static void Help(string& msg);
|
||
11 years ago
|
|
||
10 years ago
|
private:
|
||
11 years ago
|
int old_compaction_style_;
|
||
|
int new_compaction_style_;
|
||
|
|
||
10 years ago
|
static const string ARG_OLD_COMPACTION_STYLE;
|
||
|
static const string ARG_NEW_COMPACTION_STYLE;
|
||
11 years ago
|
};
|
||
|
|
||
12 years ago
|
class WALDumperCommand : public LDBCommand {
|
||
10 years ago
|
public:
|
||
|
static string Name() { return "dump_wal"; }
|
||
12 years ago
|
|
||
10 years ago
|
WALDumperCommand(const vector<string>& params,
|
||
|
const map<string, string>& options, const vector<string>& flags);
|
||
12 years ago
|
|
||
10 years ago
|
virtual bool NoDBOpen() override { return true; }
|
||
12 years ago
|
|
||
10 years ago
|
static void Help(string& ret);
|
||
10 years ago
|
virtual void DoCommand() override;
|
||
12 years ago
|
|
||
10 years ago
|
private:
|
||
12 years ago
|
bool print_header_;
|
||
10 years ago
|
string wal_file_;
|
||
12 years ago
|
bool print_values_;
|
||
12 years ago
|
|
||
10 years ago
|
static const string ARG_WAL_FILE;
|
||
|
static const string ARG_PRINT_HEADER;
|
||
|
static const string ARG_PRINT_VALUE;
|
||
12 years ago
|
};
|
||
|
|
||
|
|
||
|
class GetCommand : public LDBCommand {
|
||
10 years ago
|
public:
|
||
|
static string Name() { return "get"; }
|
||
12 years ago
|
|
||
10 years ago
|
GetCommand(const vector<string>& params, const map<string, string>& options,
|
||
|
const vector<string>& flags);
|
||
12 years ago
|
|
||
10 years ago
|
virtual void DoCommand() override;
|
||
12 years ago
|
|
||
10 years ago
|
static void Help(string& ret);
|
||
12 years ago
|
|
||
10 years ago
|
private:
|
||
|
string key_;
|
||
12 years ago
|
};
|
||
|
|
||
|
class ApproxSizeCommand : public LDBCommand {
|
||
10 years ago
|
public:
|
||
|
static string Name() { return "approxsize"; }
|
||
12 years ago
|
|
||
10 years ago
|
ApproxSizeCommand(const vector<string>& params,
|
||
|
const map<string, string>& options, const vector<string>& flags);
|
||
12 years ago
|
|
||
10 years ago
|
virtual void DoCommand() override;
|
||
12 years ago
|
|
||
10 years ago
|
static void Help(string& ret);
|
||
12 years ago
|
|
||
10 years ago
|
private:
|
||
|
string start_key_;
|
||
|
string end_key_;
|
||
12 years ago
|
};
|
||
|
|
||
|
class BatchPutCommand : public LDBCommand {
|
||
10 years ago
|
public:
|
||
|
static string Name() { return "batchput"; }
|
||
12 years ago
|
|
||
10 years ago
|
BatchPutCommand(const vector<string>& params,
|
||
|
const map<string, string>& options, const vector<string>& flags);
|
||
12 years ago
|
|
||
10 years ago
|
virtual void DoCommand() override;
|
||
12 years ago
|
|
||
10 years ago
|
static void Help(string& ret);
|
||
12 years ago
|
|
||
10 years ago
|
virtual Options PrepareOptionsForOpenDB() override;
|
||
12 years ago
|
|
||
10 years ago
|
private:
|
||
12 years ago
|
/**
|
||
|
* The key-values to be inserted.
|
||
|
*/
|
||
10 years ago
|
vector<std::pair<string, string>> key_values_;
|
||
12 years ago
|
};
|
||
|
|
||
|
class ScanCommand : public LDBCommand {
|
||
10 years ago
|
public:
|
||
|
static string Name() { return "scan"; }
|
||
12 years ago
|
|
||
10 years ago
|
ScanCommand(const vector<string>& params, const map<string, string>& options,
|
||
|
const vector<string>& flags);
|
||
12 years ago
|
|
||
10 years ago
|
virtual void DoCommand() override;
|
||
12 years ago
|
|
||
10 years ago
|
static void Help(string& ret);
|
||
12 years ago
|
|
||
10 years ago
|
private:
|
||
|
string start_key_;
|
||
|
string end_key_;
|
||
12 years ago
|
bool start_key_specified_;
|
||
|
bool end_key_specified_;
|
||
|
int max_keys_scanned_;
|
||
12 years ago
|
};
|
||
12 years ago
|
|
||
|
class DeleteCommand : public LDBCommand {
|
||
10 years ago
|
public:
|
||
|
static string Name() { return "delete"; }
|
||
12 years ago
|
|
||
10 years ago
|
DeleteCommand(const vector<string>& params,
|
||
|
const map<string, string>& options, const vector<string>& flags);
|
||
12 years ago
|
|
||
10 years ago
|
virtual void DoCommand() override;
|
||
12 years ago
|
|
||
10 years ago
|
static void Help(string& ret);
|
||
12 years ago
|
|
||
10 years ago
|
private:
|
||
|
string key_;
|
||
12 years ago
|
};
|
||
|
|
||
|
class PutCommand : public LDBCommand {
|
||
10 years ago
|
public:
|
||
|
static string Name() { return "put"; }
|
||
12 years ago
|
|
||
10 years ago
|
PutCommand(const vector<string>& params, const map<string, string>& options,
|
||
|
const vector<string>& flags);
|
||
12 years ago
|
|
||
10 years ago
|
virtual void DoCommand() override;
|
||
12 years ago
|
|
||
10 years ago
|
static void Help(string& ret);
|
||
12 years ago
|
|
||
10 years ago
|
virtual Options PrepareOptionsForOpenDB() override;
|
||
12 years ago
|
|
||
10 years ago
|
private:
|
||
|
string key_;
|
||
|
string value_;
|
||
12 years ago
|
};
|
||
|
|
||
|
/**
|
||
|
* Command that starts up a REPL shell that allows
|
||
|
* get/put/delete.
|
||
|
*/
|
||
|
class DBQuerierCommand: public LDBCommand {
|
||
10 years ago
|
public:
|
||
|
static string Name() { return "query"; }
|
||
12 years ago
|
|
||
10 years ago
|
DBQuerierCommand(const vector<string>& params,
|
||
|
const map<string, string>& options, const vector<string>& flags);
|
||
12 years ago
|
|
||
10 years ago
|
static void Help(string& ret);
|
||
12 years ago
|
|
||
10 years ago
|
virtual void DoCommand() override;
|
||
12 years ago
|
|
||
10 years ago
|
private:
|
||
12 years ago
|
static const char* HELP_CMD;
|
||
|
static const char* GET_CMD;
|
||
|
static const char* PUT_CMD;
|
||
|
static const char* DELETE_CMD;
|
||
|
};
|
||
|
|
||
11 years ago
|
class CheckConsistencyCommand : public LDBCommand {
|
||
10 years ago
|
public:
|
||
|
static string Name() { return "checkconsistency"; }
|
||
11 years ago
|
|
||
10 years ago
|
CheckConsistencyCommand(const vector<string>& params,
|
||
|
const map<string, string>& options, const vector<string>& flags);
|
||
11 years ago
|
|
||
10 years ago
|
virtual void DoCommand() override;
|
||
11 years ago
|
|
||
10 years ago
|
virtual bool NoDBOpen() override { return true; }
|
||
11 years ago
|
|
||
10 years ago
|
static void Help(string& ret);
|
||
11 years ago
|
};
|
||
|
|
||
11 years ago
|
} // namespace rocksdb
|
||
10 years ago
|
|
||
|
#endif // ROCKSDB_LITE
|