2012-09-25 01:53:13 +02: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.
|
|
|
|
|
2012-10-31 19:47:18 +01:00
|
|
|
#include "util/ldb_cmd.h"
|
2012-09-25 01:53:13 +02:00
|
|
|
|
2012-10-31 19:47:18 +01:00
|
|
|
namespace leveldb {
|
2012-09-25 01:53:13 +02:00
|
|
|
|
2012-10-31 19:47:18 +01:00
|
|
|
class LDBCommandRunner {
|
|
|
|
public:
|
2012-09-25 01:53:13 +02:00
|
|
|
|
2012-10-31 19:47:18 +01:00
|
|
|
static void PrintHelp(const char* exec_name) {
|
|
|
|
std::string ret;
|
|
|
|
ret.append("--- compact ----:\n");
|
|
|
|
ret.append(exec_name);
|
|
|
|
ret.append(" compact ");
|
|
|
|
Compactor::Help(ret);
|
2012-09-26 17:06:19 +02:00
|
|
|
|
2012-10-31 19:47:18 +01:00
|
|
|
ret.append("\n--- dump ----:\n");
|
|
|
|
ret.append(exec_name);
|
|
|
|
ret.append(" dump ");
|
|
|
|
DBDumper::Help(ret);
|
2012-09-26 17:06:19 +02:00
|
|
|
|
2012-10-31 19:47:18 +01:00
|
|
|
ret.append("\n---reduce_levels ----:\n");
|
|
|
|
ret.append(exec_name);
|
|
|
|
ret.append(" reduce_levels ");
|
|
|
|
ReduceDBLevels::Help(ret);
|
2012-09-26 17:06:19 +02: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
|
|
|
ret.append("\n---dump_wal----:\n");
|
|
|
|
ret.append(exec_name);
|
|
|
|
ret.append(" dump_wal ");
|
|
|
|
WALDumper::Help(ret);
|
2012-10-31 19:47:18 +01:00
|
|
|
fprintf(stderr, "%s\n", ret.c_str());
|
2012-09-25 01:53:13 +02:00
|
|
|
}
|
|
|
|
|
2012-10-31 19:47:18 +01:00
|
|
|
static void RunCommand(int argc, char** argv) {
|
|
|
|
if (argc <= 2) {
|
|
|
|
PrintHelp(argv[0]);
|
|
|
|
exit(1);
|
2012-09-25 01:53:13 +02:00
|
|
|
}
|
2012-10-31 19:47:18 +01:00
|
|
|
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=");
|
2012-09-25 01:53:13 +02:00
|
|
|
} else {
|
2012-10-31 19:47:18 +01:00
|
|
|
args.push_back(argv[i]);
|
2012-09-25 01:53:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-31 19:47:18 +01:00
|
|
|
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
2012-11-13 01:45:45 +01:00
|
|
|
if (strcmp(cmd, "compact") == 0) {
|
2012-10-31 19:47:18 +01:00
|
|
|
// 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
2012-11-13 01:45:45 +01:00
|
|
|
} else if (strcmp(cmd, "dump") == 0) {
|
2012-10-31 19:47:18 +01:00
|
|
|
// 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
2012-11-13 01:45:45 +01:00
|
|
|
} else if (strcmp(cmd, "reduce_levels") == 0) {
|
2012-10-31 19:47:18 +01:00
|
|
|
// 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
2012-11-13 01:45:45 +01:00
|
|
|
} else if (strcmp(cmd, "dump_wal") == 0) {
|
|
|
|
cmdObj = new WALDumper(args);
|
2012-09-26 17:06:19 +02:00
|
|
|
} else {
|
2012-10-31 19:47:18 +01:00
|
|
|
fprintf(stderr, "Unknown command: %s\n", cmd);
|
|
|
|
PrintHelp(argv[0]);
|
2012-09-26 17:06:19 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2012-10-31 19:47:18 +01:00
|
|
|
cmdObj->Run();
|
|
|
|
LDBCommandExecuteResult ret = cmdObj->GetExecuteState();
|
|
|
|
fprintf(stderr, "%s\n", ret.ToString().c_str());
|
|
|
|
delete cmdObj;
|
2012-09-26 17:06:19 +02:00
|
|
|
}
|
2012-10-31 19:47:18 +01:00
|
|
|
};
|
2012-09-26 17:06:19 +02:00
|
|
|
|
2012-10-31 19:47:18 +01:00
|
|
|
}
|
2012-09-26 17:06:19 +02:00
|
|
|
|
2012-10-31 19:47:18 +01:00
|
|
|
int main(int argc, char** argv) {
|
|
|
|
leveldb::LDBCommandRunner::RunCommand(argc, argv);
|
2012-09-26 17:06:19 +02:00
|
|
|
}
|