diff --git a/tools/ldb_cmd.cc b/tools/ldb_cmd.cc index 44571a8797..be743955d7 100644 --- a/tools/ldb_cmd.cc +++ b/tools/ldb_cmd.cc @@ -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& params, + const map& options, + const vector& 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) { diff --git a/tools/ldb_cmd.h b/tools/ldb_cmd.h index af6d6019c8..cc3814c2fc 100644 --- a/tools/ldb_cmd.h +++ b/tools/ldb_cmd.h @@ -883,6 +883,21 @@ public: static void Help(string& ret); }; +class RepairCommand : public LDBCommand { + public: + static string Name() { return "repair"; } + + RepairCommand(const vector& params, + const map& options, + const vector& flags); + + virtual void DoCommand() override; + + virtual bool NoDBOpen() override { return true; } + + static void Help(string& ret); +}; + } // namespace rocksdb #endif // ROCKSDB_LITE diff --git a/tools/ldb_tool.cc b/tools/ldb_tool.cc index 4e24997afe..7ec56f115e 100644 --- a/tools/ldb_tool.cc +++ b/tools/ldb_tool.cc @@ -77,6 +77,7 @@ public: ListColumnFamiliesCommand::Help(ret); DBFileDumperCommand::Help(ret); InternalDumpCommand::Help(ret); + RepairCommand::Help(ret); fprintf(stderr, "%s\n", ret.c_str()); }