2012-10-31 19:47:18 +01:00
|
|
|
// Copyright (c) 2012 Facebook. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2013-04-12 05:21:49 +02:00
|
|
|
#ifndef STORAGE_LEVELDB_UTIL_LDB_CMD_H_
|
|
|
|
#define STORAGE_LEVELDB_UTIL_LDB_CMD_H_
|
2012-10-31 19:47:18 +01:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2013-05-14 04:11:56 +02:00
|
|
|
#include "db/version_set.h"
|
LDB can read WAL.
Summary:
Add option to read WAL and print a summary for each record.
facebook task => #1885013
E.G. Output :
./ldb dump_wal --walfile=/tmp/leveldbtest-5907/dbbench/026122.log --header
Sequence,Count,ByteSize
49981,1,100033
49981,1,100033
49982,1,100033
49981,1,100033
49982,1,100033
49983,1,100033
49981,1,100033
49982,1,100033
49983,1,100033
49984,1,100033
49981,1,100033
49982,1,100033
Test Plan:
Works run
./ldb read_wal --wal-file=/tmp/leveldbtest-5907/dbbench/000078.log --header
Reviewers: dhruba, heyongqiang
Reviewed By: dhruba
CC: emayanke, leveldb, zshao
Differential Revision: https://reviews.facebook.net/D6675
2012-11-13 01:45:45 +01:00
|
|
|
#include "leveldb/env.h"
|
2012-10-31 19:47:18 +01:00
|
|
|
#include "leveldb/options.h"
|
|
|
|
#include "leveldb/iterator.h"
|
|
|
|
#include "leveldb/slice.h"
|
|
|
|
#include "util/logging.h"
|
2013-01-11 20:09:23 +01:00
|
|
|
#include "util/ldb_cmd_execute_result.h"
|
2013-05-21 20:37:06 +02:00
|
|
|
#include "util/string_util.h"
|
2013-05-14 04:11:56 +02:00
|
|
|
#include "utilities/utility_db.h"
|
2013-06-19 04:57:54 +02:00
|
|
|
#include "utilities/ttl/db_ttl.h"
|
2012-10-31 19:47:18 +01:00
|
|
|
|
2013-01-11 20:09:23 +01:00
|
|
|
using std::string;
|
|
|
|
using std::map;
|
|
|
|
using std::vector;
|
|
|
|
using std::ostringstream;
|
2012-10-31 19:47:18 +01:00
|
|
|
|
2013-01-11 20:09:23 +01:00
|
|
|
namespace leveldb {
|
2012-10-31 19:47:18 +01:00
|
|
|
|
|
|
|
class LDBCommand {
|
|
|
|
public:
|
|
|
|
|
2013-01-11 20:09:23 +01:00
|
|
|
// Command-line arguments
|
|
|
|
static const string ARG_DB;
|
|
|
|
static const string ARG_HEX;
|
|
|
|
static const string ARG_KEY_HEX;
|
|
|
|
static const string ARG_VALUE_HEX;
|
2013-05-14 04:11:56 +02:00
|
|
|
static const string ARG_TTL;
|
2013-06-19 04:57:54 +02:00
|
|
|
static const string ARG_TTL_START;
|
|
|
|
static const string ARG_TTL_END;
|
|
|
|
static const string ARG_TIMESTAMP;
|
2013-01-11 20:09:23 +01:00
|
|
|
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_COMPRESSION_TYPE;
|
|
|
|
static const string ARG_BLOCK_SIZE;
|
|
|
|
static const string ARG_AUTO_COMPACTION;
|
|
|
|
static const string ARG_WRITE_BUFFER_SIZE;
|
|
|
|
static const string ARG_FILE_SIZE;
|
|
|
|
static const string ARG_CREATE_IF_MISSING;
|
|
|
|
|
2013-04-12 05:21:49 +02:00
|
|
|
static LDBCommand* InitFromCmdLineArgs(
|
|
|
|
const vector<string>& args,
|
2013-06-21 01:02:36 +02:00
|
|
|
const Options& options = Options()
|
2013-04-12 05:21:49 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
static LDBCommand* InitFromCmdLineArgs(
|
|
|
|
int argc,
|
|
|
|
char** argv,
|
2013-06-21 01:02:36 +02:00
|
|
|
const Options& options = Options()
|
2013-04-12 05:21:49 +02:00
|
|
|
);
|
|
|
|
|
2013-01-11 20:09:23 +01:00
|
|
|
bool ValidateCmdLineOptions();
|
LDB can read WAL.
Summary:
Add option to read WAL and print a summary for each record.
facebook task => #1885013
E.G. Output :
./ldb dump_wal --walfile=/tmp/leveldbtest-5907/dbbench/026122.log --header
Sequence,Count,ByteSize
49981,1,100033
49981,1,100033
49982,1,100033
49981,1,100033
49982,1,100033
49983,1,100033
49981,1,100033
49982,1,100033
49983,1,100033
49984,1,100033
49981,1,100033
49982,1,100033
Test Plan:
Works run
./ldb read_wal --wal-file=/tmp/leveldbtest-5907/dbbench/000078.log --header
Reviewers: dhruba, heyongqiang
Reviewed By: dhruba
CC: emayanke, leveldb, zshao
Differential Revision: https://reviews.facebook.net/D6675
2012-11-13 01:45:45 +01:00
|
|
|
|
2013-04-12 05:21:49 +02:00
|
|
|
virtual Options PrepareOptionsForOpenDB();
|
|
|
|
|
|
|
|
virtual void SetOptions(Options options) {
|
|
|
|
options_ = options;
|
|
|
|
}
|
2012-10-31 19:47:18 +01:00
|
|
|
|
2012-11-09 03:45:19 +01:00
|
|
|
virtual bool NoDBOpen() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-31 19:47:18 +01:00
|
|
|
virtual ~LDBCommand() {
|
2013-02-16 00:28:24 +01:00
|
|
|
if (db_ != nullptr) {
|
2012-10-31 19:47:18 +01:00
|
|
|
delete db_;
|
2013-02-16 00:28:24 +01:00
|
|
|
db_ = nullptr;
|
2012-10-31 19:47:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Run the command, and return the execute result. */
|
|
|
|
void Run() {
|
|
|
|
if (!exec_state_.IsNotStarted()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-16 00:28:24 +01:00
|
|
|
if (db_ == nullptr && !NoDBOpen()) {
|
2012-10-31 19:47:18 +01:00
|
|
|
OpenDB();
|
2012-12-06 00:37:03 +01:00
|
|
|
if (!exec_state_.IsNotStarted()) {
|
|
|
|
return;
|
|
|
|
}
|
2012-10-31 19:47:18 +01:00
|
|
|
}
|
2013-01-11 20:09:23 +01:00
|
|
|
|
2012-10-31 19:47:18 +01:00
|
|
|
DoCommand();
|
|
|
|
if (exec_state_.IsNotStarted()) {
|
|
|
|
exec_state_ = LDBCommandExecuteResult::SUCCEED("");
|
|
|
|
}
|
2012-11-09 03:45:19 +01:00
|
|
|
|
2013-02-16 00:28:24 +01:00
|
|
|
if (db_ != nullptr) {
|
2012-11-09 03:45:19 +01:00
|
|
|
CloseDB ();
|
|
|
|
}
|
2012-10-31 19:47:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void DoCommand() = 0;
|
|
|
|
|
|
|
|
LDBCommandExecuteResult GetExecuteState() {
|
|
|
|
return exec_state_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearPreviousRunState() {
|
|
|
|
exec_state_.Reset();
|
|
|
|
}
|
|
|
|
|
2013-01-11 20:09:23 +01:00
|
|
|
static string HexToString(const string& str) {
|
|
|
|
string parsed;
|
2013-03-15 18:57:08 +01:00
|
|
|
if (str[0] != '0' || str[1] != 'x') {
|
2013-01-11 20:09:23 +01:00
|
|
|
fprintf(stderr, "Invalid hex input %s. Must start with 0x\n",
|
|
|
|
str.c_str());
|
|
|
|
throw "Invalid hex input";
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned int i = 2; i < str.length();) {
|
2012-10-31 19:47:18 +01:00
|
|
|
int c;
|
|
|
|
sscanf(str.c_str() + i, "%2X", &c);
|
|
|
|
parsed.push_back(c);
|
|
|
|
i += 2;
|
|
|
|
}
|
|
|
|
return parsed;
|
|
|
|
}
|
|
|
|
|
2013-01-11 20:09:23 +01:00
|
|
|
static string StringToHex(const string& str) {
|
|
|
|
string result = "0x";
|
2012-12-27 00:15:54 +01:00
|
|
|
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;
|
2013-01-11 20:09:23 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
LDBCommandExecuteResult exec_state_;
|
2013-04-12 05:21:49 +02:00
|
|
|
string db_path_;
|
|
|
|
DB* db_;
|
2013-01-11 20:09:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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_;
|
|
|
|
|
2013-05-14 04:11:56 +02:00
|
|
|
/** If true, the value is treated as timestamp suffixed */
|
|
|
|
bool is_db_ttl_;
|
|
|
|
|
2013-06-19 04:57:54 +02:00
|
|
|
// If true, the kvs are output with their insert/modify timestamp in a ttl db
|
|
|
|
bool timestamp_;
|
|
|
|
|
2013-01-11 20:09:23 +01:00
|
|
|
/**
|
|
|
|
* Map of options passed on the command-line.
|
|
|
|
*/
|
2013-04-12 05:21:49 +02:00
|
|
|
const map<string, string> option_map_;
|
2013-01-11 20:09:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Flags passed on the command-line.
|
|
|
|
*/
|
|
|
|
const vector<string> flags_;
|
|
|
|
|
|
|
|
/** List of command-line options valid for this command */
|
|
|
|
const vector<string> valid_cmd_line_options_;
|
|
|
|
|
|
|
|
bool ParseKeyValue(const string& line, string* key, string* value,
|
|
|
|
bool is_key_hex, bool is_value_hex);
|
|
|
|
|
|
|
|
LDBCommand(const map<string, string>& options, const vector<string>& flags,
|
|
|
|
bool is_read_only, const vector<string>& valid_cmd_line_options) :
|
2013-02-16 00:28:24 +01:00
|
|
|
db_(nullptr),
|
2013-01-11 20:09:23 +01:00
|
|
|
is_read_only_(is_read_only),
|
|
|
|
is_key_hex_(false),
|
|
|
|
is_value_hex_(false),
|
2013-05-14 04:11:56 +02:00
|
|
|
is_db_ttl_(false),
|
2013-06-19 04:57:54 +02:00
|
|
|
timestamp_(false),
|
2013-04-12 05:21:49 +02:00
|
|
|
option_map_(options),
|
2013-01-11 20:09:23 +01:00
|
|
|
flags_(flags),
|
|
|
|
valid_cmd_line_options_(valid_cmd_line_options) {
|
|
|
|
|
|
|
|
map<string, string>::const_iterator itr = options.find(ARG_DB);
|
|
|
|
if (itr != options.end()) {
|
|
|
|
db_path_ = itr->second;
|
2012-12-27 00:15:54 +01:00
|
|
|
}
|
|
|
|
|
2013-01-11 20:09:23 +01:00
|
|
|
is_key_hex_ = IsKeyHex(options, flags);
|
|
|
|
is_value_hex_ = IsValueHex(options, flags);
|
2013-05-14 04:11:56 +02:00
|
|
|
is_db_ttl_ = IsFlagPresent(flags, ARG_TTL);
|
2013-06-19 04:57:54 +02:00
|
|
|
timestamp_ = IsFlagPresent(flags, ARG_TIMESTAMP);
|
2012-12-27 00:15:54 +01:00
|
|
|
}
|
|
|
|
|
2012-10-31 19:47:18 +01:00
|
|
|
void OpenDB() {
|
2013-04-12 05:21:49 +02:00
|
|
|
Options opt = PrepareOptionsForOpenDB();
|
2012-12-06 00:37:03 +01:00
|
|
|
if (!exec_state_.IsNotStarted()) {
|
|
|
|
return;
|
|
|
|
}
|
2012-10-31 19:47:18 +01:00
|
|
|
// Open the DB.
|
2013-04-12 05:21:49 +02:00
|
|
|
Status st;
|
2013-05-14 04:11:56 +02:00
|
|
|
if (is_db_ttl_) {
|
|
|
|
if (is_read_only_) {
|
|
|
|
st = UtilityDB::OpenTtlDB(opt, db_path_, &db_, 0, true);
|
|
|
|
} else {
|
|
|
|
st = UtilityDB::OpenTtlDB(opt, db_path_, &db_);
|
|
|
|
}
|
|
|
|
} else if (is_read_only_) {
|
2013-04-12 05:21:49 +02:00
|
|
|
st = DB::OpenForReadOnly(opt, db_path_, &db_);
|
2013-01-11 20:09:23 +01:00
|
|
|
} else {
|
2013-04-12 05:21:49 +02:00
|
|
|
st = DB::Open(opt, db_path_, &db_);
|
2013-01-11 20:09:23 +01:00
|
|
|
}
|
2012-10-31 19:47:18 +01:00
|
|
|
if (!st.ok()) {
|
2013-04-12 05:21:49 +02:00
|
|
|
string msg = st.ToString();
|
2012-10-31 19:47:18 +01:00
|
|
|
exec_state_ = LDBCommandExecuteResult::FAILED(msg);
|
|
|
|
}
|
2013-06-21 01:02:36 +02:00
|
|
|
|
|
|
|
options_ = opt;
|
2012-10-31 19:47:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CloseDB () {
|
2013-02-16 00:28:24 +01:00
|
|
|
if (db_ != nullptr) {
|
2012-10-31 19:47:18 +01:00
|
|
|
delete db_;
|
2013-02-16 00:28:24 +01:00
|
|
|
db_ = nullptr;
|
2012-10-31 19:47:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-11 20:09:23 +01:00
|
|
|
static string PrintKeyValue(const string& key, const string& value,
|
|
|
|
bool is_key_hex, bool is_value_hex) {
|
|
|
|
string result;
|
|
|
|
result.append(is_key_hex ? StringToHex(key) : key);
|
|
|
|
result.append(DELIM);
|
|
|
|
result.append(is_value_hex ? StringToHex(value) : value);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static string PrintKeyValue(const string& key, const string& value,
|
|
|
|
bool is_hex) {
|
|
|
|
return PrintKeyValue(key, value, is_hex, is_hex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if the specified flag is present in the specified flags vector
|
|
|
|
*/
|
|
|
|
static bool IsFlagPresent(const vector<string>& flags, const string& flag) {
|
|
|
|
return (std::find(flags.begin(), flags.end(), flag) != flags.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
static string HelpRangeCmdArgs() {
|
|
|
|
ostringstream str_stream;
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
vector<string> BuildCmdLineOptions(vector<string> options) {
|
|
|
|
vector<string> ret = {ARG_DB, ARG_BLOOM_BITS, ARG_BLOCK_SIZE,
|
|
|
|
ARG_AUTO_COMPACTION, ARG_COMPRESSION_TYPE,
|
|
|
|
ARG_WRITE_BUFFER_SIZE, ARG_FILE_SIZE};
|
|
|
|
ret.insert(ret.end(), options.begin(), options.end());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-06-21 01:02:36 +02:00
|
|
|
bool ParseIntOption(const map<string, string>& options, const string& option,
|
|
|
|
int& value, LDBCommandExecuteResult& exec_state);
|
2012-12-06 00:37:03 +01:00
|
|
|
|
2013-06-21 01:02:36 +02:00
|
|
|
bool ParseStringOption(const map<string, string>& options,
|
|
|
|
const string& option, string* value);
|
2012-12-06 00:37:03 +01:00
|
|
|
|
2013-04-12 05:21:49 +02:00
|
|
|
Options options_;
|
|
|
|
|
2013-06-21 01:02:36 +02:00
|
|
|
private:
|
|
|
|
|
2013-01-11 20:09:23 +01:00
|
|
|
/**
|
|
|
|
* Interpret command line options and flags to determine if the key
|
|
|
|
* should be input/output in hex.
|
|
|
|
*/
|
|
|
|
bool IsKeyHex(const map<string, string>& options,
|
|
|
|
const vector<string>& flags) {
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
bool IsValueHex(const map<string, string>& options,
|
|
|
|
const vector<string>& flags) {
|
|
|
|
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).
|
|
|
|
*/
|
|
|
|
bool ParseBooleanOption(const map<string, string>& options,
|
|
|
|
const string& option, bool default_val) {
|
|
|
|
|
|
|
|
map<string, string>::const_iterator itr = options.find(option);
|
|
|
|
if (itr != options.end()) {
|
|
|
|
string option_val = itr->second;
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
bool StringToBool(string val) {
|
2013-03-15 01:56:38 +01:00
|
|
|
std::transform(val.begin(), val.end(), val.begin(), ::tolower);
|
2013-01-11 20:09:23 +01:00
|
|
|
if (val == "true") {
|
|
|
|
return true;
|
|
|
|
} else if (val == "false") {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
throw "Invalid value for boolean argument";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-12 05:21:49 +02:00
|
|
|
static LDBCommand* SelectCommand(
|
|
|
|
const string& cmd,
|
2013-06-21 01:02:36 +02:00
|
|
|
const vector<string>& cmdParams,
|
|
|
|
const map<string, string>& option_map,
|
|
|
|
const vector<string>& flags
|
2013-04-12 05:21:49 +02:00
|
|
|
);
|
|
|
|
|
2012-10-31 19:47:18 +01:00
|
|
|
};
|
|
|
|
|
2013-01-11 20:09:23 +01:00
|
|
|
class CompactorCommand: public LDBCommand {
|
2012-10-31 19:47:18 +01:00
|
|
|
public:
|
2013-01-11 20:09:23 +01:00
|
|
|
static string Name() { return "compact"; }
|
2012-10-31 19:47:18 +01:00
|
|
|
|
2013-01-11 20:09:23 +01:00
|
|
|
CompactorCommand(const vector<string>& params,
|
|
|
|
const map<string, string>& options, const vector<string>& flags);
|
2012-10-31 19:47:18 +01:00
|
|
|
|
2013-01-11 20:09:23 +01:00
|
|
|
static void Help(string& ret);
|
2012-10-31 19:47:18 +01:00
|
|
|
|
|
|
|
virtual void DoCommand();
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool null_from_;
|
2013-01-11 20:09:23 +01:00
|
|
|
string from_;
|
2012-10-31 19:47:18 +01:00
|
|
|
bool null_to_;
|
2013-01-11 20:09:23 +01:00
|
|
|
string to_;
|
2012-10-31 19:47:18 +01:00
|
|
|
};
|
|
|
|
|
2013-01-11 20:09:23 +01:00
|
|
|
class DBDumperCommand: public LDBCommand {
|
2012-10-31 19:47:18 +01:00
|
|
|
public:
|
2013-01-11 20:09:23 +01:00
|
|
|
static string Name() { return "dump"; }
|
|
|
|
|
|
|
|
DBDumperCommand(const vector<string>& params,
|
|
|
|
const map<string, string>& options, const vector<string>& flags);
|
|
|
|
|
|
|
|
static void Help(string& ret);
|
|
|
|
|
2012-10-31 19:47:18 +01:00
|
|
|
virtual void DoCommand();
|
2013-01-11 20:09:23 +01:00
|
|
|
|
2012-10-31 19:47:18 +01:00
|
|
|
private:
|
|
|
|
bool null_from_;
|
2013-01-11 20:09:23 +01:00
|
|
|
string from_;
|
2012-10-31 19:47:18 +01:00
|
|
|
bool null_to_;
|
2013-01-11 20:09:23 +01:00
|
|
|
string to_;
|
2012-10-31 19:47:18 +01:00
|
|
|
int max_keys_;
|
|
|
|
bool count_only_;
|
|
|
|
bool print_stats_;
|
|
|
|
|
2013-01-11 20:09:23 +01:00
|
|
|
static const string ARG_COUNT_ONLY;
|
|
|
|
static const string ARG_STATS;
|
2013-06-19 04:57:54 +02:00
|
|
|
static const string ARG_TTL_BUCKET;
|
2012-10-31 19:47:18 +01:00
|
|
|
};
|
|
|
|
|
2013-06-21 01:02:36 +02:00
|
|
|
class InternalDumpCommand: public LDBCommand {
|
|
|
|
public:
|
|
|
|
static string Name() { return "idump"; }
|
|
|
|
|
|
|
|
InternalDumpCommand(const vector<string>& params,
|
|
|
|
const map<string, string>& options,
|
|
|
|
const vector<string>& flags);
|
|
|
|
|
|
|
|
static void Help(string& ret);
|
|
|
|
|
|
|
|
virtual void DoCommand();
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool has_from_;
|
|
|
|
string from_;
|
|
|
|
bool has_to_;
|
|
|
|
string to_;
|
|
|
|
int max_keys_;
|
|
|
|
bool count_only_;
|
|
|
|
bool print_stats_;
|
|
|
|
|
|
|
|
static const string ARG_COUNT_ONLY;
|
|
|
|
static const string ARG_STATS;
|
|
|
|
};
|
|
|
|
|
2013-01-11 20:09:23 +01:00
|
|
|
class DBLoaderCommand: public LDBCommand {
|
2012-12-17 02:06:51 +01:00
|
|
|
public:
|
2013-01-11 20:09:23 +01:00
|
|
|
static string Name() { return "load"; }
|
|
|
|
|
|
|
|
DBLoaderCommand(string& db_name, vector<string>& args);
|
|
|
|
|
|
|
|
DBLoaderCommand(const vector<string>& params,
|
|
|
|
const map<string, string>& options, const vector<string>& flags);
|
|
|
|
|
|
|
|
static void Help(string& ret);
|
2012-12-17 02:06:51 +01:00
|
|
|
virtual void DoCommand();
|
|
|
|
|
2013-04-12 05:21:49 +02:00
|
|
|
virtual Options PrepareOptionsForOpenDB();
|
2012-12-17 02:06:51 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool create_if_missing_;
|
|
|
|
bool disable_wal_;
|
2013-02-26 07:57:37 +01:00
|
|
|
bool bulk_load_;
|
|
|
|
bool compact_;
|
2012-12-17 02:06:51 +01:00
|
|
|
|
2013-01-11 20:09:23 +01:00
|
|
|
static const string ARG_DISABLE_WAL;
|
2013-02-26 07:57:37 +01:00
|
|
|
static const string ARG_BULK_LOAD;
|
|
|
|
static const string ARG_COMPACT;
|
2012-12-17 02:06:51 +01:00
|
|
|
};
|
|
|
|
|
2013-03-22 17:17:30 +01:00
|
|
|
class ManifestDumpCommand: public LDBCommand {
|
|
|
|
public:
|
|
|
|
static string Name() { return "manifest_dump"; }
|
|
|
|
|
|
|
|
ManifestDumpCommand(const vector<string>& params,
|
|
|
|
const map<string, string>& options, const vector<string>& flags);
|
|
|
|
|
|
|
|
static void Help(string& ret);
|
|
|
|
virtual void DoCommand();
|
|
|
|
|
|
|
|
virtual bool NoDBOpen() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool verbose_;
|
|
|
|
string path_;
|
|
|
|
|
|
|
|
static const string ARG_VERBOSE;
|
|
|
|
static const string ARG_PATH;
|
|
|
|
};
|
|
|
|
|
2013-01-11 20:09:23 +01:00
|
|
|
class ReduceDBLevelsCommand : public LDBCommand {
|
2012-12-27 00:15:54 +01:00
|
|
|
public:
|
2013-01-11 20:09:23 +01:00
|
|
|
static string Name() { return "reduce_levels"; }
|
2012-12-27 00:15:54 +01:00
|
|
|
|
2013-01-11 20:09:23 +01:00
|
|
|
ReduceDBLevelsCommand(const vector<string>& params,
|
|
|
|
const map<string, string>& options, const vector<string>& flags);
|
2012-10-31 19:47:18 +01:00
|
|
|
|
2013-04-12 05:21:49 +02:00
|
|
|
virtual Options PrepareOptionsForOpenDB();
|
2012-10-31 19:47:18 +01:00
|
|
|
|
|
|
|
virtual void DoCommand();
|
|
|
|
|
2012-11-09 03:45:19 +01:00
|
|
|
virtual bool NoDBOpen() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-11 20:09:23 +01:00
|
|
|
static void Help(string& msg);
|
|
|
|
|
|
|
|
static vector<string> PrepareArgs(const string& db_path, int new_levels,
|
2012-10-31 19:47:18 +01:00
|
|
|
bool print_old_level = false);
|
|
|
|
|
|
|
|
private:
|
2012-11-09 03:45:19 +01:00
|
|
|
int old_levels_;
|
2012-10-31 19:47:18 +01:00
|
|
|
int new_levels_;
|
|
|
|
bool print_old_levels_;
|
|
|
|
|
2013-01-11 20:09:23 +01:00
|
|
|
static const string ARG_NEW_LEVELS;
|
|
|
|
static const string ARG_PRINT_OLD_LEVELS;
|
2012-11-09 03:45:19 +01:00
|
|
|
|
2013-04-12 05:21:49 +02:00
|
|
|
Status GetOldNumOfLevels(Options& opt, int* levels);
|
2012-10-31 19:47:18 +01:00
|
|
|
};
|
|
|
|
|
2013-01-11 20:09:23 +01:00
|
|
|
class WALDumperCommand : public LDBCommand {
|
LDB can read WAL.
Summary:
Add option to read WAL and print a summary for each record.
facebook task => #1885013
E.G. Output :
./ldb dump_wal --walfile=/tmp/leveldbtest-5907/dbbench/026122.log --header
Sequence,Count,ByteSize
49981,1,100033
49981,1,100033
49982,1,100033
49981,1,100033
49982,1,100033
49983,1,100033
49981,1,100033
49982,1,100033
49983,1,100033
49984,1,100033
49981,1,100033
49982,1,100033
Test Plan:
Works run
./ldb read_wal --wal-file=/tmp/leveldbtest-5907/dbbench/000078.log --header
Reviewers: dhruba, heyongqiang
Reviewed By: dhruba
CC: emayanke, leveldb, zshao
Differential Revision: https://reviews.facebook.net/D6675
2012-11-13 01:45:45 +01:00
|
|
|
public:
|
2013-01-11 20:09:23 +01:00
|
|
|
static string Name() { return "dump_wal"; }
|
LDB can read WAL.
Summary:
Add option to read WAL and print a summary for each record.
facebook task => #1885013
E.G. Output :
./ldb dump_wal --walfile=/tmp/leveldbtest-5907/dbbench/026122.log --header
Sequence,Count,ByteSize
49981,1,100033
49981,1,100033
49982,1,100033
49981,1,100033
49982,1,100033
49983,1,100033
49981,1,100033
49982,1,100033
49983,1,100033
49984,1,100033
49981,1,100033
49982,1,100033
Test Plan:
Works run
./ldb read_wal --wal-file=/tmp/leveldbtest-5907/dbbench/000078.log --header
Reviewers: dhruba, heyongqiang
Reviewed By: dhruba
CC: emayanke, leveldb, zshao
Differential Revision: https://reviews.facebook.net/D6675
2012-11-13 01:45:45 +01:00
|
|
|
|
2013-01-11 20:09:23 +01:00
|
|
|
WALDumperCommand(const vector<string>& params,
|
|
|
|
const map<string, string>& options, const vector<string>& flags);
|
LDB can read WAL.
Summary:
Add option to read WAL and print a summary for each record.
facebook task => #1885013
E.G. Output :
./ldb dump_wal --walfile=/tmp/leveldbtest-5907/dbbench/026122.log --header
Sequence,Count,ByteSize
49981,1,100033
49981,1,100033
49982,1,100033
49981,1,100033
49982,1,100033
49983,1,100033
49981,1,100033
49982,1,100033
49983,1,100033
49984,1,100033
49981,1,100033
49982,1,100033
Test Plan:
Works run
./ldb read_wal --wal-file=/tmp/leveldbtest-5907/dbbench/000078.log --header
Reviewers: dhruba, heyongqiang
Reviewed By: dhruba
CC: emayanke, leveldb, zshao
Differential Revision: https://reviews.facebook.net/D6675
2012-11-13 01:45:45 +01:00
|
|
|
|
|
|
|
virtual bool NoDBOpen() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-11 20:09:23 +01:00
|
|
|
static void Help(string& ret);
|
LDB can read WAL.
Summary:
Add option to read WAL and print a summary for each record.
facebook task => #1885013
E.G. Output :
./ldb dump_wal --walfile=/tmp/leveldbtest-5907/dbbench/026122.log --header
Sequence,Count,ByteSize
49981,1,100033
49981,1,100033
49982,1,100033
49981,1,100033
49982,1,100033
49983,1,100033
49981,1,100033
49982,1,100033
49983,1,100033
49984,1,100033
49981,1,100033
49982,1,100033
Test Plan:
Works run
./ldb read_wal --wal-file=/tmp/leveldbtest-5907/dbbench/000078.log --header
Reviewers: dhruba, heyongqiang
Reviewed By: dhruba
CC: emayanke, leveldb, zshao
Differential Revision: https://reviews.facebook.net/D6675
2012-11-13 01:45:45 +01:00
|
|
|
virtual void DoCommand();
|
2013-01-11 20:09:23 +01:00
|
|
|
|
LDB can read WAL.
Summary:
Add option to read WAL and print a summary for each record.
facebook task => #1885013
E.G. Output :
./ldb dump_wal --walfile=/tmp/leveldbtest-5907/dbbench/026122.log --header
Sequence,Count,ByteSize
49981,1,100033
49981,1,100033
49982,1,100033
49981,1,100033
49982,1,100033
49983,1,100033
49981,1,100033
49982,1,100033
49983,1,100033
49984,1,100033
49981,1,100033
49982,1,100033
Test Plan:
Works run
./ldb read_wal --wal-file=/tmp/leveldbtest-5907/dbbench/000078.log --header
Reviewers: dhruba, heyongqiang
Reviewed By: dhruba
CC: emayanke, leveldb, zshao
Differential Revision: https://reviews.facebook.net/D6675
2012-11-13 01:45:45 +01:00
|
|
|
private:
|
|
|
|
bool print_header_;
|
2013-01-11 20:09:23 +01:00
|
|
|
string wal_file_;
|
2013-02-20 03:12:20 +01:00
|
|
|
bool print_values_;
|
2013-01-11 20:09:23 +01:00
|
|
|
|
|
|
|
static const string ARG_WAL_FILE;
|
|
|
|
static const string ARG_PRINT_HEADER;
|
2013-02-20 03:12:20 +01:00
|
|
|
static const string ARG_PRINT_VALUE;
|
2013-01-11 20:09:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class GetCommand : public LDBCommand {
|
|
|
|
public:
|
|
|
|
static string Name() { return "get"; }
|
|
|
|
|
|
|
|
GetCommand(const vector<string>& params, const map<string, string>& options,
|
|
|
|
const vector<string>& flags);
|
|
|
|
|
|
|
|
virtual void DoCommand();
|
|
|
|
|
|
|
|
static void Help(string& ret);
|
|
|
|
|
|
|
|
private:
|
|
|
|
string key_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ApproxSizeCommand : public LDBCommand {
|
|
|
|
public:
|
|
|
|
static string Name() { return "approxsize"; }
|
|
|
|
|
|
|
|
ApproxSizeCommand(const vector<string>& params,
|
|
|
|
const map<string, string>& options, const vector<string>& flags);
|
|
|
|
|
|
|
|
virtual void DoCommand();
|
|
|
|
|
|
|
|
static void Help(string& ret);
|
|
|
|
|
|
|
|
private:
|
|
|
|
string start_key_;
|
|
|
|
string end_key_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class BatchPutCommand : public LDBCommand {
|
|
|
|
public:
|
|
|
|
static string Name() { return "batchput"; }
|
|
|
|
|
|
|
|
BatchPutCommand(const vector<string>& params,
|
|
|
|
const map<string, string>& options, const vector<string>& flags);
|
|
|
|
|
|
|
|
virtual void DoCommand();
|
|
|
|
|
|
|
|
static void Help(string& ret);
|
|
|
|
|
2013-04-12 05:21:49 +02:00
|
|
|
virtual Options PrepareOptionsForOpenDB();
|
2013-01-11 20:09:23 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* The key-values to be inserted.
|
|
|
|
*/
|
|
|
|
vector<std::pair<string, string>> key_values_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ScanCommand : public LDBCommand {
|
|
|
|
public:
|
|
|
|
static string Name() { return "scan"; }
|
2012-10-31 19:47:18 +01:00
|
|
|
|
2013-01-11 20:09:23 +01:00
|
|
|
ScanCommand(const vector<string>& params, const map<string, string>& options,
|
|
|
|
const vector<string>& flags);
|
|
|
|
|
|
|
|
virtual void DoCommand();
|
|
|
|
|
|
|
|
static void Help(string& ret);
|
|
|
|
|
|
|
|
private:
|
|
|
|
string start_key_;
|
|
|
|
string end_key_;
|
|
|
|
bool start_key_specified_;
|
|
|
|
bool end_key_specified_;
|
|
|
|
int max_keys_scanned_;
|
LDB can read WAL.
Summary:
Add option to read WAL and print a summary for each record.
facebook task => #1885013
E.G. Output :
./ldb dump_wal --walfile=/tmp/leveldbtest-5907/dbbench/026122.log --header
Sequence,Count,ByteSize
49981,1,100033
49981,1,100033
49982,1,100033
49981,1,100033
49982,1,100033
49983,1,100033
49981,1,100033
49982,1,100033
49983,1,100033
49984,1,100033
49981,1,100033
49982,1,100033
Test Plan:
Works run
./ldb read_wal --wal-file=/tmp/leveldbtest-5907/dbbench/000078.log --header
Reviewers: dhruba, heyongqiang
Reviewed By: dhruba
CC: emayanke, leveldb, zshao
Differential Revision: https://reviews.facebook.net/D6675
2012-11-13 01:45:45 +01:00
|
|
|
};
|
2013-01-11 20:09:23 +01:00
|
|
|
|
|
|
|
class DeleteCommand : public LDBCommand {
|
|
|
|
public:
|
|
|
|
static string Name() { return "delete"; }
|
|
|
|
|
|
|
|
DeleteCommand(const vector<string>& params,
|
|
|
|
const map<string, string>& options, const vector<string>& flags);
|
|
|
|
|
|
|
|
virtual void DoCommand();
|
|
|
|
|
|
|
|
static void Help(string& ret);
|
|
|
|
|
|
|
|
private:
|
|
|
|
string key_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PutCommand : public LDBCommand {
|
|
|
|
public:
|
|
|
|
static string Name() { return "put"; }
|
|
|
|
|
|
|
|
PutCommand(const vector<string>& params, const map<string, string>& options,
|
|
|
|
const vector<string>& flags);
|
|
|
|
|
|
|
|
virtual void DoCommand();
|
|
|
|
|
|
|
|
static void Help(string& ret);
|
|
|
|
|
2013-04-12 05:21:49 +02:00
|
|
|
virtual Options PrepareOptionsForOpenDB();
|
2013-01-11 20:09:23 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
string key_;
|
|
|
|
string value_;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Command that starts up a REPL shell that allows
|
|
|
|
* get/put/delete.
|
|
|
|
*/
|
|
|
|
class DBQuerierCommand: public LDBCommand {
|
|
|
|
public:
|
|
|
|
static string Name() { return "query"; }
|
|
|
|
|
|
|
|
DBQuerierCommand(const vector<string>& params,
|
|
|
|
const map<string, string>& options, const vector<string>& flags);
|
|
|
|
|
|
|
|
static void Help(string& ret);
|
|
|
|
|
|
|
|
virtual void DoCommand();
|
|
|
|
|
|
|
|
private:
|
|
|
|
static const char* HELP_CMD;
|
|
|
|
static const char* GET_CMD;
|
|
|
|
static const char* PUT_CMD;
|
|
|
|
static const char* DELETE_CMD;
|
|
|
|
};
|
|
|
|
|
2013-04-12 05:21:49 +02:00
|
|
|
} // namespace leveldb
|
|
|
|
#endif // STORAGE_LEVELDB_UTIL_LDB_CMD_H_
|