|
|
|
// 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.
|
|
|
|
|
|
|
|
#include "util/ldb_cmd.h"
|
|
|
|
|
|
|
|
namespace leveldb {
|
|
|
|
|
|
|
|
class LDBCommandRunner {
|
|
|
|
public:
|
|
|
|
|
|
|
|
static void PrintHelp(const char* exec_name) {
|
|
|
|
std::string ret;
|
|
|
|
ret.append("--- compact ----:\n");
|
|
|
|
ret.append(exec_name);
|
|
|
|
ret.append(" compact ");
|
|
|
|
Compactor::Help(ret);
|
|
|
|
|
|
|
|
ret.append("\n--- dump ----:\n");
|
|
|
|
ret.append(exec_name);
|
|
|
|
ret.append(" dump ");
|
|
|
|
DBDumper::Help(ret);
|
|
|
|
|
|
|
|
ret.append("\n---reduce_levels ----:\n");
|
|
|
|
ret.append(exec_name);
|
|
|
|
ret.append(" reduce_levels ");
|
|
|
|
ReduceDBLevels::Help(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
12 years ago
|
|
|
ret.append("\n---dump_wal----:\n");
|
|
|
|
ret.append(exec_name);
|
|
|
|
ret.append(" dump_wal ");
|
|
|
|
WALDumper::Help(ret);
|
|
|
|
fprintf(stderr, "%s\n", ret.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void RunCommand(int argc, char** argv) {
|
|
|
|
if (argc <= 2) {
|
|
|
|
PrintHelp(argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
const char* cmd = argv[1];
|
|
|
|
std::string db_name;
|
|
|
|
std::vector<std::string> args;
|
|
|
|
for (int i = 2; i < argc; i++) {
|
|
|
|
if (strncmp(argv[i], "--db=", strlen("--db=")) == 0) {
|
|
|
|
db_name = argv[i] + strlen("--db=");
|
|
|
|
} else {
|
|
|
|
args.push_back(argv[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LDBCommand* cmdObj = NULL;
|
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
12 years ago
|
|
|
if (strcmp(cmd, "compact") == 0) {
|
|
|
|
// run compactor
|
|
|
|
cmdObj = new Compactor(db_name, args);
|
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
12 years ago
|
|
|
} else if (strcmp(cmd, "dump") == 0) {
|
|
|
|
// run dump
|
|
|
|
cmdObj = new DBDumper(db_name, args);
|
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
12 years ago
|
|
|
} else if (strcmp(cmd, "reduce_levels") == 0) {
|
|
|
|
// reduce db levels
|
|
|
|
cmdObj = new ReduceDBLevels(db_name, args);
|
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
12 years ago
|
|
|
} else if (strcmp(cmd, "dump_wal") == 0) {
|
|
|
|
cmdObj = new WALDumper(args);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Unknown command: %s\n", cmd);
|
|
|
|
PrintHelp(argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
cmdObj->Run();
|
|
|
|
LDBCommandExecuteResult ret = cmdObj->GetExecuteState();
|
|
|
|
fprintf(stderr, "%s\n", ret.ToString().c_str());
|
|
|
|
delete cmdObj;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
leveldb::LDBCommandRunner::RunCommand(argc, argv);
|
|
|
|
}
|