2016-02-09 23:12:00 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2013-10-16 21:59:46 +00:00
|
|
|
// 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.
|
|
|
|
//
|
2013-10-05 05:32:05 +00:00
|
|
|
#pragma once
|
2014-11-13 19:39:30 +00:00
|
|
|
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
|
2012-10-31 18:47:18 +00:00
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
2014-11-01 02:22:49 +00:00
|
|
|
#include <stdlib.h>
|
2012-10-31 18:47:18 +00:00
|
|
|
#include <algorithm>
|
2014-11-01 02:22:49 +00:00
|
|
|
#include <stdio.h>
|
2014-11-24 18:04:16 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
2012-10-31 18:47:18 +00:00
|
|
|
|
2013-05-14 02:11:56 +00:00
|
|
|
#include "db/version_set.h"
|
2013-08-23 15:38:13 +00:00
|
|
|
#include "rocksdb/env.h"
|
|
|
|
#include "rocksdb/iterator.h"
|
2014-06-20 06:54:13 +00:00
|
|
|
#include "rocksdb/ldb_tool.h"
|
|
|
|
#include "rocksdb/options.h"
|
2013-08-23 15:38:13 +00:00
|
|
|
#include "rocksdb/slice.h"
|
2014-07-23 14:21:38 +00:00
|
|
|
#include "rocksdb/utilities/db_ttl.h"
|
2015-10-15 00:08:28 +00:00
|
|
|
#include "tools/ldb_cmd_execute_result.h"
|
2012-10-31 18:47:18 +00:00
|
|
|
#include "util/logging.h"
|
2013-05-21 18:37:06 +00:00
|
|
|
#include "util/string_util.h"
|
2014-04-29 03:34:20 +00:00
|
|
|
#include "utilities/ttl/db_ttl_impl.h"
|
2012-10-31 18:47:18 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
using std::string;
|
|
|
|
using std::map;
|
|
|
|
using std::vector;
|
|
|
|
using std::ostringstream;
|
|
|
|
|
2013-10-04 04:49:15 +00:00
|
|
|
namespace rocksdb {
|
2012-10-31 18:47:18 +00:00
|
|
|
|
|
|
|
class LDBCommand {
|
2014-11-01 02:22:49 +00:00
|
|
|
public:
|
2012-10-31 18:47:18 +00:00
|
|
|
|
2013-01-11 19:09:23 +00:00
|
|
|
// Command-line arguments
|
2014-11-01 02:22:49 +00:00
|
|
|
static const string ARG_DB;
|
2016-01-06 22:19:08 +00:00
|
|
|
static const string ARG_PATH;
|
2014-11-01 02:22:49 +00:00
|
|
|
static const string ARG_HEX;
|
|
|
|
static const string ARG_KEY_HEX;
|
|
|
|
static const string ARG_VALUE_HEX;
|
2016-01-22 23:46:32 +00:00
|
|
|
static const string ARG_CF_NAME;
|
2014-11-01 02:22:49 +00:00
|
|
|
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;
|
2014-12-02 20:09:20 +00:00
|
|
|
static const string ARG_DB_WRITE_BUFFER_SIZE;
|
2014-11-01 02:22:49 +00:00
|
|
|
static const string ARG_WRITE_BUFFER_SIZE;
|
|
|
|
static const string ARG_FILE_SIZE;
|
|
|
|
static const string ARG_CREATE_IF_MISSING;
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2013-04-12 03:21:49 +00:00
|
|
|
static LDBCommand* InitFromCmdLineArgs(
|
2016-01-22 23:46:32 +00:00
|
|
|
const vector<string>& args, const Options& options,
|
|
|
|
const LDBOptions& ldb_options,
|
|
|
|
const std::vector<ColumnFamilyDescriptor>* column_families);
|
2013-04-12 03:21:49 +00:00
|
|
|
|
|
|
|
static LDBCommand* InitFromCmdLineArgs(
|
2016-01-22 23:46:32 +00:00
|
|
|
int argc, char** argv, const Options& options,
|
|
|
|
const LDBOptions& ldb_options,
|
|
|
|
const std::vector<ColumnFamilyDescriptor>* column_families);
|
2013-04-12 03:21:49 +00:00
|
|
|
|
2013-01-11 19:09:23 +00: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 00:45:45 +00:00
|
|
|
|
2013-04-12 03:21:49 +00:00
|
|
|
virtual Options PrepareOptionsForOpenDB();
|
|
|
|
|
2014-06-20 06:54:13 +00:00
|
|
|
virtual void SetDBOptions(Options options) {
|
2013-04-12 03:21:49 +00:00
|
|
|
options_ = options;
|
|
|
|
}
|
2012-10-31 18:47:18 +00:00
|
|
|
|
2016-01-22 23:46:32 +00:00
|
|
|
virtual void SetColumnFamilies(
|
|
|
|
const std::vector<ColumnFamilyDescriptor>* column_families) {
|
|
|
|
if (column_families != nullptr) {
|
|
|
|
column_families_ = *column_families;
|
|
|
|
} else {
|
|
|
|
column_families_.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-20 06:54:13 +00:00
|
|
|
void SetLDBOptions(const LDBOptions& ldb_options) {
|
|
|
|
ldb_options_ = ldb_options;
|
|
|
|
}
|
|
|
|
|
2012-11-09 02:45:19 +00:00
|
|
|
virtual bool NoDBOpen() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-22 23:46:32 +00:00
|
|
|
virtual ~LDBCommand() { CloseDB(); }
|
2012-10-31 18:47:18 +00:00
|
|
|
|
|
|
|
/* Run the command, and return the execute result. */
|
|
|
|
void Run() {
|
|
|
|
if (!exec_state_.IsNotStarted()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-15 23:28:24 +00:00
|
|
|
if (db_ == nullptr && !NoDBOpen()) {
|
2012-10-31 18:47:18 +00:00
|
|
|
OpenDB();
|
|
|
|
}
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2016-01-06 22:19:08 +00:00
|
|
|
// We'll intentionally proceed even if the DB can't be opened because users
|
|
|
|
// can also specify a filename, not just a directory.
|
2012-10-31 18:47:18 +00:00
|
|
|
DoCommand();
|
2016-01-06 22:19:08 +00:00
|
|
|
|
2012-10-31 18:47:18 +00:00
|
|
|
if (exec_state_.IsNotStarted()) {
|
2015-03-17 01:08:59 +00:00
|
|
|
exec_state_ = LDBCommandExecuteResult::Succeed("");
|
2012-10-31 18:47:18 +00:00
|
|
|
}
|
2012-11-09 02:45:19 +00:00
|
|
|
|
2013-02-15 23:28:24 +00:00
|
|
|
if (db_ != nullptr) {
|
2012-11-09 02:45:19 +00:00
|
|
|
CloseDB ();
|
|
|
|
}
|
2012-10-31 18:47:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void DoCommand() = 0;
|
|
|
|
|
|
|
|
LDBCommandExecuteResult GetExecuteState() {
|
|
|
|
return exec_state_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearPreviousRunState() {
|
|
|
|
exec_state_.Reset();
|
|
|
|
}
|
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
static string HexToString(const string& str) {
|
Remove ldb HexToString method's usage of sscanf
Summary:
Fix hex2String performance issues by removing sscanf dependency.
Also fixed some edge case handling (odd length, bad input).
Test Plan: Created a test file which called old and new implementation, and validated results are the same. I'll paste results in the phabricator diff.
Reviewers: igor, rven, anthony, IslamAbdelRahman, kradhakrishnan, yhchiang, sdong
Reviewed By: sdong
Subscribers: thatsafunnyname, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D46785
2015-09-23 21:25:46 +00:00
|
|
|
std::string::size_type len = str.length();
|
2014-11-01 02:22:49 +00:00
|
|
|
string parsed;
|
Remove ldb HexToString method's usage of sscanf
Summary:
Fix hex2String performance issues by removing sscanf dependency.
Also fixed some edge case handling (odd length, bad input).
Test Plan: Created a test file which called old and new implementation, and validated results are the same. I'll paste results in the phabricator diff.
Reviewers: igor, rven, anthony, IslamAbdelRahman, kradhakrishnan, yhchiang, sdong
Reviewed By: sdong
Subscribers: thatsafunnyname, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D46785
2015-09-23 21:25:46 +00:00
|
|
|
static const char* const hexas = "0123456789ABCDEF";
|
|
|
|
parsed.reserve(len / 2);
|
|
|
|
|
|
|
|
if (len < 2 || str[0] != '0' || str[1] != 'x') {
|
2013-01-11 19:09:23 +00:00
|
|
|
fprintf(stderr, "Invalid hex input %s. Must start with 0x\n",
|
|
|
|
str.c_str());
|
|
|
|
throw "Invalid hex input";
|
|
|
|
}
|
|
|
|
|
Remove ldb HexToString method's usage of sscanf
Summary:
Fix hex2String performance issues by removing sscanf dependency.
Also fixed some edge case handling (odd length, bad input).
Test Plan: Created a test file which called old and new implementation, and validated results are the same. I'll paste results in the phabricator diff.
Reviewers: igor, rven, anthony, IslamAbdelRahman, kradhakrishnan, yhchiang, sdong
Reviewed By: sdong
Subscribers: thatsafunnyname, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D46785
2015-09-23 21:25:46 +00:00
|
|
|
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
|
2015-11-19 19:47:12 +00:00
|
|
|
parsed.push_back(static_cast<char>(p - hexas));
|
Remove ldb HexToString method's usage of sscanf
Summary:
Fix hex2String performance issues by removing sscanf dependency.
Also fixed some edge case handling (odd length, bad input).
Test Plan: Created a test file which called old and new implementation, and validated results are the same. I'll paste results in the phabricator diff.
Reviewers: igor, rven, anthony, IslamAbdelRahman, kradhakrishnan, yhchiang, sdong
Reviewed By: sdong
Subscribers: thatsafunnyname, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D46785
2015-09-23 21:25:46 +00:00
|
|
|
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
|
2015-11-19 19:47:12 +00:00
|
|
|
parsed.push_back(static_cast<char>(((p - hexas) << 4) | (q - hexas)));
|
Remove ldb HexToString method's usage of sscanf
Summary:
Fix hex2String performance issues by removing sscanf dependency.
Also fixed some edge case handling (odd length, bad input).
Test Plan: Created a test file which called old and new implementation, and validated results are the same. I'll paste results in the phabricator diff.
Reviewers: igor, rven, anthony, IslamAbdelRahman, kradhakrishnan, yhchiang, sdong
Reviewed By: sdong
Subscribers: thatsafunnyname, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D46785
2015-09-23 21:25:46 +00:00
|
|
|
} else {
|
|
|
|
throw "Invalid hex value";
|
|
|
|
}
|
2012-10-31 18:47:18 +00:00
|
|
|
}
|
|
|
|
return parsed;
|
|
|
|
}
|
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
static string StringToHex(const string& str) {
|
|
|
|
string result = "0x";
|
2012-12-26 23:15:54 +00: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 19:09:23 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
LDBCommandExecuteResult exec_state_;
|
2014-11-01 02:22:49 +00:00
|
|
|
string db_path_;
|
2016-01-22 23:46:32 +00:00
|
|
|
string column_family_name_;
|
2013-04-12 03:21:49 +00:00
|
|
|
DB* db_;
|
2014-04-29 03:34:20 +00:00
|
|
|
DBWithTTL* db_ttl_;
|
2016-01-22 23:46:32 +00:00
|
|
|
std::map<std::string, ColumnFamilyHandle*> cf_handles_;
|
2013-01-11 19:09:23 +00: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 02:11:56 +00:00
|
|
|
/** If true, the value is treated as timestamp suffixed */
|
|
|
|
bool is_db_ttl_;
|
|
|
|
|
2013-06-19 02:57:54 +00:00
|
|
|
// If true, the kvs are output with their insert/modify timestamp in a ttl db
|
|
|
|
bool timestamp_;
|
|
|
|
|
2013-01-11 19:09:23 +00:00
|
|
|
/**
|
|
|
|
* Map of options passed on the command-line.
|
|
|
|
*/
|
2014-11-01 02:22:49 +00:00
|
|
|
const map<string, string> option_map_;
|
2013-01-11 19:09:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Flags passed on the command-line.
|
|
|
|
*/
|
2014-11-01 02:22:49 +00:00
|
|
|
const vector<string> flags_;
|
2013-01-11 19:09:23 +00:00
|
|
|
|
|
|
|
/** List of command-line options valid for this command */
|
2014-11-01 02:22:49 +00:00
|
|
|
const vector<string> valid_cmd_line_options_;
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
bool ParseKeyValue(const string& line, string* key, string* value,
|
|
|
|
bool is_key_hex, bool is_value_hex);
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
LDBCommand(const map<string, string>& options, const vector<string>& flags,
|
|
|
|
bool is_read_only, const vector<string>& valid_cmd_line_options) :
|
2013-02-15 23:28:24 +00:00
|
|
|
db_(nullptr),
|
2013-01-11 19:09:23 +00:00
|
|
|
is_read_only_(is_read_only),
|
|
|
|
is_key_hex_(false),
|
|
|
|
is_value_hex_(false),
|
2013-05-14 02:11:56 +00:00
|
|
|
is_db_ttl_(false),
|
2013-06-19 02:57:54 +00:00
|
|
|
timestamp_(false),
|
2013-04-12 03:21:49 +00:00
|
|
|
option_map_(options),
|
2013-01-11 19:09:23 +00:00
|
|
|
flags_(flags),
|
|
|
|
valid_cmd_line_options_(valid_cmd_line_options) {
|
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
map<string, string>::const_iterator itr = options.find(ARG_DB);
|
2013-01-11 19:09:23 +00:00
|
|
|
if (itr != options.end()) {
|
|
|
|
db_path_ = itr->second;
|
2012-12-26 23:15:54 +00:00
|
|
|
}
|
|
|
|
|
2016-01-22 23:46:32 +00:00
|
|
|
itr = options.find(ARG_CF_NAME);
|
|
|
|
if (itr != options.end()) {
|
|
|
|
column_family_name_ = itr->second;
|
|
|
|
} else {
|
|
|
|
column_family_name_ = kDefaultColumnFamilyName;
|
|
|
|
}
|
|
|
|
|
2013-01-11 19:09:23 +00:00
|
|
|
is_key_hex_ = IsKeyHex(options, flags);
|
|
|
|
is_value_hex_ = IsValueHex(options, flags);
|
2013-05-14 02:11:56 +00:00
|
|
|
is_db_ttl_ = IsFlagPresent(flags, ARG_TTL);
|
2013-06-19 02:57:54 +00:00
|
|
|
timestamp_ = IsFlagPresent(flags, ARG_TIMESTAMP);
|
2012-12-26 23:15:54 +00:00
|
|
|
}
|
|
|
|
|
2012-10-31 18:47:18 +00:00
|
|
|
void OpenDB() {
|
2013-04-12 03:21:49 +00:00
|
|
|
Options opt = PrepareOptionsForOpenDB();
|
2012-12-05 23:37:03 +00:00
|
|
|
if (!exec_state_.IsNotStarted()) {
|
|
|
|
return;
|
|
|
|
}
|
2012-10-31 18:47:18 +00:00
|
|
|
// Open the DB.
|
2013-04-12 03:21:49 +00:00
|
|
|
Status st;
|
2016-01-22 23:46:32 +00:00
|
|
|
std::vector<ColumnFamilyHandle*> handles_opened;
|
2013-05-14 02:11:56 +00:00
|
|
|
if (is_db_ttl_) {
|
2016-01-22 23:46:32 +00:00
|
|
|
// ldb doesn't yet support TTL DB with multiple column families
|
|
|
|
if (!column_family_name_.empty() || !column_families_.empty()) {
|
|
|
|
exec_state_ = LDBCommandExecuteResult::Failed(
|
|
|
|
"ldb doesn't support TTL DB with multiple column families");
|
|
|
|
}
|
2013-05-14 02:11:56 +00:00
|
|
|
if (is_read_only_) {
|
2014-04-29 03:34:20 +00:00
|
|
|
st = DBWithTTL::Open(opt, db_path_, &db_ttl_, 0, true);
|
2013-05-14 02:11:56 +00:00
|
|
|
} else {
|
2014-04-29 03:34:20 +00:00
|
|
|
st = DBWithTTL::Open(opt, db_path_, &db_ttl_);
|
2013-05-14 02:11:56 +00:00
|
|
|
}
|
2014-04-29 03:34:20 +00:00
|
|
|
db_ = db_ttl_;
|
2013-01-11 19:09:23 +00:00
|
|
|
} else {
|
2016-01-22 23:46:32 +00:00
|
|
|
if (column_families_.empty()) {
|
|
|
|
// Try to figure out column family lists
|
|
|
|
std::vector<std::string> cf_list;
|
|
|
|
st = DB::ListColumnFamilies(DBOptions(), db_path_, &cf_list);
|
|
|
|
// There is possible the DB doesn't exist yet, for "create if not
|
|
|
|
// "existing case". The failure is ignored here. We rely on DB::Open()
|
|
|
|
// to give us the correct error message for problem with opening
|
|
|
|
// existing DB.
|
|
|
|
if (st.ok() && cf_list.size() > 1) {
|
|
|
|
// Ignore single column family DB.
|
|
|
|
for (auto cf_name : cf_list) {
|
|
|
|
column_families_.emplace_back(cf_name, opt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (is_read_only_) {
|
|
|
|
if (column_families_.empty()) {
|
|
|
|
st = DB::OpenForReadOnly(opt, db_path_, &db_);
|
|
|
|
} else {
|
|
|
|
st = DB::OpenForReadOnly(opt, db_path_, column_families_,
|
|
|
|
&handles_opened, &db_);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (column_families_.empty()) {
|
|
|
|
st = DB::Open(opt, db_path_, &db_);
|
|
|
|
} else {
|
|
|
|
st = DB::Open(opt, db_path_, column_families_, &handles_opened, &db_);
|
|
|
|
}
|
|
|
|
}
|
2013-01-11 19:09:23 +00:00
|
|
|
}
|
2012-10-31 18:47:18 +00:00
|
|
|
if (!st.ok()) {
|
2014-11-01 02:22:49 +00:00
|
|
|
string msg = st.ToString();
|
2015-03-17 01:08:59 +00:00
|
|
|
exec_state_ = LDBCommandExecuteResult::Failed(msg);
|
2016-01-22 23:46:32 +00:00
|
|
|
} else if (!handles_opened.empty()) {
|
|
|
|
assert(handles_opened.size() == column_families_.size());
|
|
|
|
bool found_cf_name = false;
|
|
|
|
for (size_t i = 0; i < handles_opened.size(); i++) {
|
|
|
|
cf_handles_[column_families_[i].name] = handles_opened[i];
|
|
|
|
if (column_family_name_ == column_families_[i].name) {
|
|
|
|
found_cf_name = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found_cf_name) {
|
|
|
|
exec_state_ = LDBCommandExecuteResult::Failed(
|
|
|
|
"Non-existing column family " + column_family_name_);
|
|
|
|
CloseDB();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// We successfully opened DB in single column family mode.
|
|
|
|
assert(column_families_.empty());
|
|
|
|
if (column_family_name_ != kDefaultColumnFamilyName) {
|
|
|
|
exec_state_ = LDBCommandExecuteResult::Failed(
|
|
|
|
"Non-existing column family " + column_family_name_);
|
|
|
|
CloseDB();
|
|
|
|
}
|
2012-10-31 18:47:18 +00:00
|
|
|
}
|
2013-06-20 23:02:36 +00:00
|
|
|
|
|
|
|
options_ = opt;
|
2012-10-31 18:47:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CloseDB () {
|
2013-02-15 23:28:24 +00:00
|
|
|
if (db_ != nullptr) {
|
2016-01-22 23:46:32 +00:00
|
|
|
for (auto& pair : cf_handles_) {
|
|
|
|
delete pair.second;
|
|
|
|
}
|
2012-10-31 18:47:18 +00:00
|
|
|
delete db_;
|
2013-02-15 23:28:24 +00:00
|
|
|
db_ = nullptr;
|
2012-10-31 18:47:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-22 23:46:32 +00:00
|
|
|
ColumnFamilyHandle* GetCfHandle() {
|
|
|
|
if (!cf_handles_.empty()) {
|
|
|
|
auto it = cf_handles_.find(column_family_name_);
|
|
|
|
if (it == cf_handles_.end()) {
|
|
|
|
exec_state_ = LDBCommandExecuteResult::Failed(
|
|
|
|
"Cannot find column family " + column_family_name_);
|
|
|
|
} else {
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return db_->DefaultColumnFamily();
|
|
|
|
}
|
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
static string PrintKeyValue(const string& key, const string& value,
|
|
|
|
bool is_key_hex, bool is_value_hex) {
|
|
|
|
string result;
|
2013-01-11 19:09:23 +00:00
|
|
|
result.append(is_key_hex ? StringToHex(key) : key);
|
|
|
|
result.append(DELIM);
|
|
|
|
result.append(is_value_hex ? StringToHex(value) : value);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
static string PrintKeyValue(const string& key, const string& value,
|
|
|
|
bool is_hex) {
|
2013-01-11 19:09:23 +00:00
|
|
|
return PrintKeyValue(key, value, is_hex, is_hex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-11-01 02:22:49 +00:00
|
|
|
* Return true if the specified flag is present in the specified flags vector
|
2013-01-11 19:09:23 +00:00
|
|
|
*/
|
2014-11-01 02:22:49 +00:00
|
|
|
static bool IsFlagPresent(const vector<string>& flags, const string& flag) {
|
2013-01-11 19:09:23 +00:00
|
|
|
return (std::find(flags.begin(), flags.end(), flag) != flags.end());
|
|
|
|
}
|
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
static string HelpRangeCmdArgs() {
|
|
|
|
ostringstream str_stream;
|
2013-01-11 19:09:23 +00:00
|
|
|
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.
|
|
|
|
*/
|
rocksdb: Fix uninitialized use error
Summary:
When using latest clang (3.6 or 3.7/trunck) rocksdb is failing with many errors. Some errors are uninitialized use errors.
```
...
CC db/log_test.o
util/ldb_cmd.cc:394:16: error: base class 'rocksdb::LDBCommand' is uninitialized when used here to access 'rocksdb::LDBCommand::BuildCmdLineOptions' [-Werror,-Wuninitialized]
BuildCmdLineOptions({ARG_FROM, ARG_TO, ARG_HEX, ARG_KEY_HEX,
^
...
```
```lang=c++
CompactorCommand::CompactorCommand(const vector<string>& params,
const map<string, string>& options, const vector<string>& flags) :
LDBCommand(options, flags, false,
BuildCmdLineOptions({ARG_FROM, ARG_TO, ARG_HEX, ARG_KEY_HEX,
ARG_VALUE_HEX, ARG_TTL})),
null_from_(true), null_to_(true) {
. . .
}
```
For the fourth parameter of the base constructor (`LDBCommand`) we call `BuildCmdLineOptions`, which is a private non-static method of `LDBCommand` base class.
This diff adds missing `static` keyword for `LDBCommand::BuildCmdLineOptions` method.
Test Plan:
Build with trunk clang and make sure all tests are passing.
```lang=bash
% # Have trunk clang present in path.
% ROCKSDB_NO_FBCODE=1 CC=clang CXX=clang++ make check
``
Reviewers: meyering, sdong, rven, igor
Reviewed By: igor
Subscribers: dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D34083
2015-02-26 22:19:51 +00:00
|
|
|
static vector<string> BuildCmdLineOptions(vector<string> options) {
|
2016-01-22 23:46:32 +00:00
|
|
|
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, ARG_CF_NAME};
|
2013-01-11 19:09:23 +00:00
|
|
|
ret.insert(ret.end(), options.begin(), options.end());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
bool ParseIntOption(const map<string, string>& options, const string& option,
|
|
|
|
int& value, LDBCommandExecuteResult& exec_state);
|
2012-12-05 23:37:03 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
bool ParseStringOption(const map<string, string>& options,
|
|
|
|
const string& option, string* value);
|
2012-12-05 23:37:03 +00:00
|
|
|
|
2013-04-12 03:21:49 +00:00
|
|
|
Options options_;
|
2016-01-22 23:46:32 +00:00
|
|
|
std::vector<ColumnFamilyDescriptor> column_families_;
|
2014-06-20 06:54:13 +00:00
|
|
|
LDBOptions ldb_options_;
|
2013-04-12 03:21:49 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
private:
|
2013-06-20 23:02:36 +00:00
|
|
|
|
2013-01-11 19:09:23 +00:00
|
|
|
/**
|
|
|
|
* Interpret command line options and flags to determine if the key
|
|
|
|
* should be input/output in hex.
|
|
|
|
*/
|
2014-11-01 02:22:49 +00:00
|
|
|
bool IsKeyHex(const map<string, string>& options,
|
|
|
|
const vector<string>& flags) {
|
2013-01-11 19:09:23 +00:00
|
|
|
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.
|
|
|
|
*/
|
2014-11-01 02:22:49 +00:00
|
|
|
bool IsValueHex(const map<string, string>& options,
|
|
|
|
const vector<string>& flags) {
|
2013-01-11 19:09:23 +00:00
|
|
|
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).
|
|
|
|
*/
|
2014-11-01 02:22:49 +00:00
|
|
|
bool ParseBooleanOption(const map<string, string>& options,
|
|
|
|
const string& option, bool default_val) {
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
map<string, string>::const_iterator itr = options.find(option);
|
2013-01-11 19:09:23 +00:00
|
|
|
if (itr != options.end()) {
|
2014-11-01 02:22:49 +00:00
|
|
|
string option_val = itr->second;
|
2013-01-11 19:09:23 +00:00
|
|
|
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.
|
|
|
|
*/
|
2014-11-01 02:22:49 +00:00
|
|
|
bool StringToBool(string val) {
|
2015-07-01 23:13:49 +00:00
|
|
|
std::transform(val.begin(), val.end(), val.begin(),
|
2015-07-13 19:11:05 +00:00
|
|
|
[](char ch) -> char { return ::tolower(ch); });
|
|
|
|
|
2013-01-11 19:09:23 +00:00
|
|
|
if (val == "true") {
|
|
|
|
return true;
|
|
|
|
} else if (val == "false") {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
throw "Invalid value for boolean argument";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-12 03:21:49 +00:00
|
|
|
static LDBCommand* SelectCommand(
|
2014-11-01 02:22:49 +00:00
|
|
|
const string& cmd,
|
|
|
|
const vector<string>& cmdParams,
|
|
|
|
const map<string, string>& option_map,
|
|
|
|
const vector<string>& flags
|
2013-04-12 03:21:49 +00:00
|
|
|
);
|
|
|
|
|
2012-10-31 18:47:18 +00:00
|
|
|
};
|
|
|
|
|
2013-01-11 19:09:23 +00:00
|
|
|
class CompactorCommand: public LDBCommand {
|
2014-11-01 02:22:49 +00:00
|
|
|
public:
|
|
|
|
static string Name() { return "compact"; }
|
2012-10-31 18:47:18 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
CompactorCommand(const vector<string>& params,
|
|
|
|
const map<string, string>& options, const vector<string>& flags);
|
2012-10-31 18:47:18 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
static void Help(string& ret);
|
2012-10-31 18:47:18 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual void DoCommand() override;
|
2012-10-31 18:47:18 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
private:
|
2012-10-31 18:47:18 +00:00
|
|
|
bool null_from_;
|
2014-11-01 02:22:49 +00:00
|
|
|
string from_;
|
2012-10-31 18:47:18 +00:00
|
|
|
bool null_to_;
|
2014-11-01 02:22:49 +00:00
|
|
|
string to_;
|
2012-10-31 18:47:18 +00:00
|
|
|
};
|
|
|
|
|
2014-11-24 18:04:16 +00:00
|
|
|
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);
|
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual void DoCommand() override;
|
2014-11-24 18:04:16 +00:00
|
|
|
};
|
|
|
|
|
2013-01-11 19:09:23 +00:00
|
|
|
class DBDumperCommand: public LDBCommand {
|
2014-11-01 02:22:49 +00:00
|
|
|
public:
|
|
|
|
static string Name() { return "dump"; }
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
DBDumperCommand(const vector<string>& params,
|
|
|
|
const map<string, string>& options, const vector<string>& flags);
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
static void Help(string& ret);
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual void DoCommand() override;
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
private:
|
2016-01-06 22:19:08 +00:00
|
|
|
/**
|
|
|
|
* Extract file name from the full path. We handle both the forward slash (/)
|
|
|
|
* and backslash (\) to make sure that different OS-s are supported.
|
|
|
|
*/
|
|
|
|
static string GetFileNameFromPath(const string& s) {
|
|
|
|
std::size_t n = s.find_last_of("/\\");
|
|
|
|
|
|
|
|
if (std::string::npos == n) {
|
|
|
|
return s;
|
|
|
|
} else {
|
|
|
|
return s.substr(n + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoDumpCommand();
|
|
|
|
|
2012-10-31 18:47:18 +00:00
|
|
|
bool null_from_;
|
2014-11-01 02:22:49 +00:00
|
|
|
string from_;
|
2012-10-31 18:47:18 +00:00
|
|
|
bool null_to_;
|
2014-11-01 02:22:49 +00:00
|
|
|
string to_;
|
|
|
|
int max_keys_;
|
|
|
|
string delim_;
|
2012-10-31 18:47:18 +00:00
|
|
|
bool count_only_;
|
2013-11-01 20:59:14 +00:00
|
|
|
bool count_delim_;
|
2012-10-31 18:47:18 +00:00
|
|
|
bool print_stats_;
|
2016-01-06 22:19:08 +00:00
|
|
|
string path_;
|
2012-10-31 18:47:18 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
static const string ARG_COUNT_ONLY;
|
|
|
|
static const string ARG_COUNT_DELIM;
|
|
|
|
static const string ARG_STATS;
|
|
|
|
static const string ARG_TTL_BUCKET;
|
2012-10-31 18:47:18 +00:00
|
|
|
};
|
|
|
|
|
2013-06-20 23:02:36 +00:00
|
|
|
class InternalDumpCommand: public LDBCommand {
|
2014-11-01 02:22:49 +00:00
|
|
|
public:
|
|
|
|
static string Name() { return "idump"; }
|
2013-06-20 23:02:36 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
InternalDumpCommand(const vector<string>& params,
|
|
|
|
const map<string, string>& options,
|
|
|
|
const vector<string>& flags);
|
2013-06-20 23:02:36 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
static void Help(string& ret);
|
2013-06-20 23:02:36 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual void DoCommand() override;
|
2013-06-20 23:02:36 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
private:
|
2013-06-20 23:02:36 +00:00
|
|
|
bool has_from_;
|
2014-11-01 02:22:49 +00:00
|
|
|
string from_;
|
2013-06-20 23:02:36 +00:00
|
|
|
bool has_to_;
|
2014-11-01 02:22:49 +00:00
|
|
|
string to_;
|
2013-06-20 23:02:36 +00:00
|
|
|
int max_keys_;
|
2014-11-01 02:22:49 +00:00
|
|
|
string delim_;
|
2013-06-20 23:02:36 +00:00
|
|
|
bool count_only_;
|
2013-11-01 20:59:14 +00:00
|
|
|
bool count_delim_;
|
2013-06-20 23:02:36 +00:00
|
|
|
bool print_stats_;
|
2013-08-08 22:51:16 +00:00
|
|
|
bool is_input_key_hex_;
|
2013-06-20 23:02:36 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
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;
|
2013-06-20 23:02:36 +00:00
|
|
|
};
|
|
|
|
|
2013-01-11 19:09:23 +00:00
|
|
|
class DBLoaderCommand: public LDBCommand {
|
2014-11-01 02:22:49 +00:00
|
|
|
public:
|
|
|
|
static string Name() { return "load"; }
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
DBLoaderCommand(string& db_name, vector<string>& args);
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
DBLoaderCommand(const vector<string>& params,
|
|
|
|
const map<string, string>& options, const vector<string>& flags);
|
|
|
|
|
|
|
|
static void Help(string& ret);
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual void DoCommand() override;
|
2012-12-17 01:06:51 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual Options PrepareOptionsForOpenDB() override;
|
2012-12-17 01:06:51 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
private:
|
2012-12-17 01:06:51 +00:00
|
|
|
bool create_if_missing_;
|
|
|
|
bool disable_wal_;
|
2013-02-26 06:57:37 +00:00
|
|
|
bool bulk_load_;
|
|
|
|
bool compact_;
|
2012-12-17 01:06:51 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
static const string ARG_DISABLE_WAL;
|
|
|
|
static const string ARG_BULK_LOAD;
|
|
|
|
static const string ARG_COMPACT;
|
2012-12-17 01:06:51 +00:00
|
|
|
};
|
|
|
|
|
2013-03-22 16:17:30 +00:00
|
|
|
class ManifestDumpCommand: public LDBCommand {
|
2014-11-01 02:22:49 +00:00
|
|
|
public:
|
|
|
|
static string Name() { return "manifest_dump"; }
|
2013-03-22 16:17:30 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
ManifestDumpCommand(const vector<string>& params,
|
|
|
|
const map<string, string>& options, const vector<string>& flags);
|
2013-03-22 16:17:30 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
static void Help(string& ret);
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual void DoCommand() override;
|
2013-03-22 16:17:30 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual bool NoDBOpen() override { return true; }
|
2013-03-22 16:17:30 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
private:
|
2013-03-22 16:17:30 +00:00
|
|
|
bool verbose_;
|
Added JSON manifest dump option to ldb command
Summary:
Added a new flag --json to the ldb manifest_dump command
that prints out the version edits as JSON objects for easier
reading and parsing of information.
Test Plan:
**Sample usage: **
```
./ldb manifest_dump --json --path=path/to/manifest/file
```
**Sample output:**
```
{"EditNumber": 0, "Comparator": "leveldb.BytewiseComparator", "ColumnFamily": 0}
{"EditNumber": 1, "LogNumber": 0, "ColumnFamily": 0}
{"EditNumber": 2, "LogNumber": 4, "PrevLogNumber": 0, "NextFileNumber": 7, "LastSeq": 35356, "AddedFiles": [{"Level": 0, "FileNumber": 5, "FileSize": 1949284, "SmallestIKey": "'", "LargestIKey": "'"}], "ColumnFamily": 0}
...
{"EditNumber": 13, "PrevLogNumber": 0, "NextFileNumber": 36, "LastSeq": 290994, "DeletedFiles": [{"Level": 0, "FileNumber": 17}, {"Level": 0, "FileNumber": 20}, {"Level": 0, "FileNumber": 22}, {"Level": 0, "FileNumber": 24}, {"Level": 1, "FileNumber": 13}, {"Level": 1, "FileNumber": 14}, {"Level": 1, "FileNumber": 15}, {"Level": 1, "FileNumber": 18}], "AddedFiles": [{"Level": 1, "FileNumber": 25, "FileSize": 2114340, "SmallestIKey": "'", "LargestIKey": "'"}, {"Level": 1, "FileNumber": 26, "FileSize": 2115213, "SmallestIKey": "'", "LargestIKey": "'"}, {"Level": 1, "FileNumber": 27, "FileSize": 2114807, "SmallestIKey": "'", "LargestIKey": "'"}, {"Level": 1, "FileNumber": 30, "FileSize": 2115271, "SmallestIKey": "'", "LargestIKey": "'"}, {"Level": 1, "FileNumber": 31, "FileSize": 2115165, "SmallestIKey": "'", "LargestIKey": "'"}, {"Level": 1, "FileNumber": 32, "FileSize": 2114683, "SmallestIKey": "'", "LargestIKey": "'"}, {"Level": 1, "FileNumber": 35, "FileSize": 1757512, "SmallestIKey": "'", "LargestIKey": "'"}], "ColumnFamily": 0}
...
```
Reviewers: sdong, anthony, yhchiang, igor
Reviewed By: igor
Subscribers: dhruba
Differential Revision: https://reviews.facebook.net/D41727
2015-07-17 17:07:40 +00:00
|
|
|
bool json_;
|
2014-11-01 02:22:49 +00:00
|
|
|
string path_;
|
2013-03-22 16:17:30 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
static const string ARG_VERBOSE;
|
Added JSON manifest dump option to ldb command
Summary:
Added a new flag --json to the ldb manifest_dump command
that prints out the version edits as JSON objects for easier
reading and parsing of information.
Test Plan:
**Sample usage: **
```
./ldb manifest_dump --json --path=path/to/manifest/file
```
**Sample output:**
```
{"EditNumber": 0, "Comparator": "leveldb.BytewiseComparator", "ColumnFamily": 0}
{"EditNumber": 1, "LogNumber": 0, "ColumnFamily": 0}
{"EditNumber": 2, "LogNumber": 4, "PrevLogNumber": 0, "NextFileNumber": 7, "LastSeq": 35356, "AddedFiles": [{"Level": 0, "FileNumber": 5, "FileSize": 1949284, "SmallestIKey": "'", "LargestIKey": "'"}], "ColumnFamily": 0}
...
{"EditNumber": 13, "PrevLogNumber": 0, "NextFileNumber": 36, "LastSeq": 290994, "DeletedFiles": [{"Level": 0, "FileNumber": 17}, {"Level": 0, "FileNumber": 20}, {"Level": 0, "FileNumber": 22}, {"Level": 0, "FileNumber": 24}, {"Level": 1, "FileNumber": 13}, {"Level": 1, "FileNumber": 14}, {"Level": 1, "FileNumber": 15}, {"Level": 1, "FileNumber": 18}], "AddedFiles": [{"Level": 1, "FileNumber": 25, "FileSize": 2114340, "SmallestIKey": "'", "LargestIKey": "'"}, {"Level": 1, "FileNumber": 26, "FileSize": 2115213, "SmallestIKey": "'", "LargestIKey": "'"}, {"Level": 1, "FileNumber": 27, "FileSize": 2114807, "SmallestIKey": "'", "LargestIKey": "'"}, {"Level": 1, "FileNumber": 30, "FileSize": 2115271, "SmallestIKey": "'", "LargestIKey": "'"}, {"Level": 1, "FileNumber": 31, "FileSize": 2115165, "SmallestIKey": "'", "LargestIKey": "'"}, {"Level": 1, "FileNumber": 32, "FileSize": 2114683, "SmallestIKey": "'", "LargestIKey": "'"}, {"Level": 1, "FileNumber": 35, "FileSize": 1757512, "SmallestIKey": "'", "LargestIKey": "'"}], "ColumnFamily": 0}
...
```
Reviewers: sdong, anthony, yhchiang, igor
Reviewed By: igor
Subscribers: dhruba
Differential Revision: https://reviews.facebook.net/D41727
2015-07-17 17:07:40 +00:00
|
|
|
static const string ARG_JSON;
|
2014-11-01 02:22:49 +00:00
|
|
|
static const string ARG_PATH;
|
2013-03-22 16:17:30 +00:00
|
|
|
};
|
|
|
|
|
2014-02-28 00:18:23 +00:00
|
|
|
class ListColumnFamiliesCommand : public LDBCommand {
|
|
|
|
public:
|
2014-11-01 02:22:49 +00:00
|
|
|
static string Name() { return "list_column_families"; }
|
2014-02-28 00:18:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
ListColumnFamiliesCommand(const vector<string>& params,
|
|
|
|
const map<string, string>& options,
|
|
|
|
const vector<string>& flags);
|
2014-02-28 00:18:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
static void Help(string& ret);
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual void DoCommand() override;
|
2014-02-28 00:18:23 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual bool NoDBOpen() override { return true; }
|
2014-02-28 00:18:23 +00:00
|
|
|
|
|
|
|
private:
|
2014-11-01 02:22:49 +00:00
|
|
|
string dbname_;
|
2014-02-28 00:18:23 +00:00
|
|
|
};
|
|
|
|
|
2016-01-22 23:46:32 +00:00
|
|
|
class CreateColumnFamilyCommand : public LDBCommand {
|
|
|
|
public:
|
|
|
|
static string Name() { return "create_column_family"; }
|
|
|
|
|
|
|
|
CreateColumnFamilyCommand(const vector<string>& params,
|
|
|
|
const map<string, string>& options,
|
|
|
|
const vector<string>& flags);
|
|
|
|
|
|
|
|
static void Help(string& ret);
|
|
|
|
virtual void DoCommand() override;
|
|
|
|
|
|
|
|
virtual bool NoDBOpen() override { return false; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
string new_cf_name_;
|
|
|
|
};
|
|
|
|
|
2013-01-11 19:09:23 +00:00
|
|
|
class ReduceDBLevelsCommand : public LDBCommand {
|
2014-11-01 02:22:49 +00:00
|
|
|
public:
|
|
|
|
static string Name() { return "reduce_levels"; }
|
2012-12-26 23:15:54 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
ReduceDBLevelsCommand(const vector<string>& params,
|
|
|
|
const map<string, string>& options, const vector<string>& flags);
|
2012-10-31 18:47:18 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual Options PrepareOptionsForOpenDB() override;
|
2012-10-31 18:47:18 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual void DoCommand() override;
|
2012-10-31 18:47:18 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual bool NoDBOpen() override { return true; }
|
2012-11-09 02:45:19 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
static void Help(string& msg);
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
static vector<string> PrepareArgs(const string& db_path, int new_levels,
|
2012-10-31 18:47:18 +00:00
|
|
|
bool print_old_level = false);
|
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
private:
|
2012-11-09 02:45:19 +00:00
|
|
|
int old_levels_;
|
2012-10-31 18:47:18 +00:00
|
|
|
int new_levels_;
|
|
|
|
bool print_old_levels_;
|
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
static const string ARG_NEW_LEVELS;
|
|
|
|
static const string ARG_PRINT_OLD_LEVELS;
|
2012-11-09 02:45:19 +00:00
|
|
|
|
2013-04-12 03:21:49 +00:00
|
|
|
Status GetOldNumOfLevels(Options& opt, int* levels);
|
2012-10-31 18:47:18 +00:00
|
|
|
};
|
|
|
|
|
2013-09-04 20:13:08 +00:00
|
|
|
class ChangeCompactionStyleCommand : public LDBCommand {
|
2014-11-01 02:22:49 +00:00
|
|
|
public:
|
|
|
|
static string Name() { return "change_compaction_style"; }
|
2013-09-04 20:13:08 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
ChangeCompactionStyleCommand(const vector<string>& params,
|
|
|
|
const map<string, string>& options, const vector<string>& flags);
|
2013-09-04 20:13:08 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual Options PrepareOptionsForOpenDB() override;
|
2013-09-04 20:13:08 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual void DoCommand() override;
|
2013-09-04 20:13:08 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
static void Help(string& msg);
|
2013-09-04 20:13:08 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
private:
|
2013-09-04 20:13:08 +00:00
|
|
|
int old_compaction_style_;
|
|
|
|
int new_compaction_style_;
|
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
static const string ARG_OLD_COMPACTION_STYLE;
|
|
|
|
static const string ARG_NEW_COMPACTION_STYLE;
|
2013-09-04 20:13:08 +00:00
|
|
|
};
|
|
|
|
|
2013-01-11 19:09:23 +00:00
|
|
|
class WALDumperCommand : public LDBCommand {
|
2014-11-01 02:22:49 +00:00
|
|
|
public:
|
|
|
|
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 00:45:45 +00:00
|
|
|
|
2014-11-01 02:22:49 +00: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 00:45:45 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual bool NoDBOpen() override { return true; }
|
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 00:45:45 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
static void Help(string& ret);
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual void DoCommand() override;
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
private:
|
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 00:45:45 +00:00
|
|
|
bool print_header_;
|
2014-11-01 02:22:49 +00:00
|
|
|
string wal_file_;
|
2013-02-20 02:12:20 +00:00
|
|
|
bool print_values_;
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
static const string ARG_WAL_FILE;
|
|
|
|
static const string ARG_PRINT_HEADER;
|
|
|
|
static const string ARG_PRINT_VALUE;
|
2013-01-11 19:09:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class GetCommand : public LDBCommand {
|
2014-11-01 02:22:49 +00:00
|
|
|
public:
|
|
|
|
static string Name() { return "get"; }
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
GetCommand(const vector<string>& params, const map<string, string>& options,
|
|
|
|
const vector<string>& flags);
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual void DoCommand() override;
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
static void Help(string& ret);
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
private:
|
|
|
|
string key_;
|
2013-01-11 19:09:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ApproxSizeCommand : public LDBCommand {
|
2014-11-01 02:22:49 +00:00
|
|
|
public:
|
|
|
|
static string Name() { return "approxsize"; }
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
ApproxSizeCommand(const vector<string>& params,
|
|
|
|
const map<string, string>& options, const vector<string>& flags);
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual void DoCommand() override;
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
static void Help(string& ret);
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
private:
|
|
|
|
string start_key_;
|
|
|
|
string end_key_;
|
2013-01-11 19:09:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class BatchPutCommand : public LDBCommand {
|
2014-11-01 02:22:49 +00:00
|
|
|
public:
|
|
|
|
static string Name() { return "batchput"; }
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
BatchPutCommand(const vector<string>& params,
|
|
|
|
const map<string, string>& options, const vector<string>& flags);
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual void DoCommand() override;
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
static void Help(string& ret);
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual Options PrepareOptionsForOpenDB() override;
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
private:
|
2013-01-11 19:09:23 +00:00
|
|
|
/**
|
|
|
|
* The key-values to be inserted.
|
|
|
|
*/
|
2014-11-01 02:22:49 +00:00
|
|
|
vector<std::pair<string, string>> key_values_;
|
2013-01-11 19:09:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ScanCommand : public LDBCommand {
|
2014-11-01 02:22:49 +00:00
|
|
|
public:
|
|
|
|
static string Name() { return "scan"; }
|
2012-10-31 18:47:18 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
ScanCommand(const vector<string>& params, const map<string, string>& options,
|
|
|
|
const vector<string>& flags);
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual void DoCommand() override;
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
static void Help(string& ret);
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
private:
|
|
|
|
string start_key_;
|
|
|
|
string end_key_;
|
2013-01-11 19:09:23 +00:00
|
|
|
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 00:45:45 +00:00
|
|
|
};
|
2013-01-11 19:09:23 +00:00
|
|
|
|
|
|
|
class DeleteCommand : public LDBCommand {
|
2014-11-01 02:22:49 +00:00
|
|
|
public:
|
|
|
|
static string Name() { return "delete"; }
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
DeleteCommand(const vector<string>& params,
|
|
|
|
const map<string, string>& options, const vector<string>& flags);
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual void DoCommand() override;
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
static void Help(string& ret);
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
private:
|
|
|
|
string key_;
|
2013-01-11 19:09:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PutCommand : public LDBCommand {
|
2014-11-01 02:22:49 +00:00
|
|
|
public:
|
|
|
|
static string Name() { return "put"; }
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
PutCommand(const vector<string>& params, const map<string, string>& options,
|
|
|
|
const vector<string>& flags);
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual void DoCommand() override;
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
static void Help(string& ret);
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual Options PrepareOptionsForOpenDB() override;
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
private:
|
|
|
|
string key_;
|
|
|
|
string value_;
|
2013-01-11 19:09:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Command that starts up a REPL shell that allows
|
|
|
|
* get/put/delete.
|
|
|
|
*/
|
|
|
|
class DBQuerierCommand: public LDBCommand {
|
2014-11-01 02:22:49 +00:00
|
|
|
public:
|
|
|
|
static string Name() { return "query"; }
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
DBQuerierCommand(const vector<string>& params,
|
|
|
|
const map<string, string>& options, const vector<string>& flags);
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
static void Help(string& ret);
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual void DoCommand() override;
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
private:
|
2013-01-11 19:09:23 +00:00
|
|
|
static const char* HELP_CMD;
|
|
|
|
static const char* GET_CMD;
|
|
|
|
static const char* PUT_CMD;
|
|
|
|
static const char* DELETE_CMD;
|
|
|
|
};
|
|
|
|
|
2014-03-20 20:42:45 +00:00
|
|
|
class CheckConsistencyCommand : public LDBCommand {
|
2014-11-01 02:22:49 +00:00
|
|
|
public:
|
|
|
|
static string Name() { return "checkconsistency"; }
|
2014-03-20 20:42:45 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
CheckConsistencyCommand(const vector<string>& params,
|
|
|
|
const map<string, string>& options, const vector<string>& flags);
|
2014-03-20 20:42:45 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual void DoCommand() override;
|
2014-03-20 20:42:45 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual bool NoDBOpen() override { return true; }
|
2014-03-20 20:42:45 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
static void Help(string& ret);
|
2014-03-20 20:42:45 +00:00
|
|
|
};
|
|
|
|
|
2013-10-04 04:49:15 +00:00
|
|
|
} // namespace rocksdb
|
2014-11-13 19:39:30 +00:00
|
|
|
|
|
|
|
#endif // ROCKSDB_LITE
|