mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-26 07:30:54 +00:00
Expose RepairDB as ldb command
Summary: This will make it easier for admins and devs to use RepairDB. Test Plan: Tried deleting the manifest and verified it recovers: $ ldb --create_if_missing --db=/tmp/test_db put ok ok $ rm -f /tmp/test_db/MANIFEST-000001 $ ./ldb --db=/tmp/test_db repair $ ldb --db=/tmp/test_db get ok ok Reviewers: yhchiang, sdong, IslamAbdelRahman Reviewed By: IslamAbdelRahman Subscribers: leveldb, andrewkr, dhruba Differential Revision: https://reviews.facebook.net/D55359
This commit is contained in:
parent
580fede347
commit
08304c0867
|
@ -191,6 +191,8 @@ LDBCommand* LDBCommand::SelectCommand(
|
|||
return new InternalDumpCommand(cmdParams, option_map, flags);
|
||||
} else if (cmd == CheckConsistencyCommand::Name()) {
|
||||
return new CheckConsistencyCommand(cmdParams, option_map, flags);
|
||||
} else if (cmd == RepairCommand::Name()) {
|
||||
return new RepairCommand(cmdParams, option_map, flags);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -2144,6 +2146,29 @@ void CheckConsistencyCommand::DoCommand() {
|
|||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
RepairCommand::RepairCommand(const vector<string>& params,
|
||||
const map<string, string>& options,
|
||||
const vector<string>& flags)
|
||||
: LDBCommand(options, flags, false, BuildCmdLineOptions({})) {}
|
||||
|
||||
void RepairCommand::Help(string& ret) {
|
||||
ret.append(" ");
|
||||
ret.append(RepairCommand::Name());
|
||||
ret.append("\n");
|
||||
}
|
||||
|
||||
void RepairCommand::DoCommand() {
|
||||
Options options = PrepareOptionsForOpenDB();
|
||||
Status status = RepairDB(db_path_, options);
|
||||
if (status.ok()) {
|
||||
printf("OK\n");
|
||||
} else {
|
||||
exec_state_ = LDBCommandExecuteResult::Failed(status.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
namespace {
|
||||
|
||||
void DumpSstFile(std::string filename, bool output_hex, bool show_properties) {
|
||||
|
|
|
@ -883,6 +883,21 @@ public:
|
|||
static void Help(string& ret);
|
||||
};
|
||||
|
||||
class RepairCommand : public LDBCommand {
|
||||
public:
|
||||
static string Name() { return "repair"; }
|
||||
|
||||
RepairCommand(const vector<string>& params,
|
||||
const map<string, string>& options,
|
||||
const vector<string>& flags);
|
||||
|
||||
virtual void DoCommand() override;
|
||||
|
||||
virtual bool NoDBOpen() override { return true; }
|
||||
|
||||
static void Help(string& ret);
|
||||
};
|
||||
|
||||
} // namespace rocksdb
|
||||
|
||||
#endif // ROCKSDB_LITE
|
||||
|
|
|
@ -77,6 +77,7 @@ public:
|
|||
ListColumnFamiliesCommand::Help(ret);
|
||||
DBFileDumperCommand::Help(ret);
|
||||
InternalDumpCommand::Help(ret);
|
||||
RepairCommand::Help(ret);
|
||||
|
||||
fprintf(stderr, "%s\n", ret.c_str());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue