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
main
Andrew Kryczka 9 years ago
parent 580fede347
commit 08304c0867
  1. 25
      tools/ldb_cmd.cc
  2. 15
      tools/ldb_cmd.h
  3. 1
      tools/ldb_tool.cc

@ -191,6 +191,8 @@ LDBCommand* LDBCommand::SelectCommand(
return new InternalDumpCommand(cmdParams, option_map, flags); return new InternalDumpCommand(cmdParams, option_map, flags);
} else if (cmd == CheckConsistencyCommand::Name()) { } else if (cmd == CheckConsistencyCommand::Name()) {
return new CheckConsistencyCommand(cmdParams, option_map, flags); return new CheckConsistencyCommand(cmdParams, option_map, flags);
} else if (cmd == RepairCommand::Name()) {
return new RepairCommand(cmdParams, option_map, flags);
} }
return nullptr; 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 { namespace {
void DumpSstFile(std::string filename, bool output_hex, bool show_properties) { void DumpSstFile(std::string filename, bool output_hex, bool show_properties) {

@ -883,6 +883,21 @@ public:
static void Help(string& ret); 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 } // namespace rocksdb
#endif // ROCKSDB_LITE #endif // ROCKSDB_LITE

@ -77,6 +77,7 @@ public:
ListColumnFamiliesCommand::Help(ret); ListColumnFamiliesCommand::Help(ret);
DBFileDumperCommand::Help(ret); DBFileDumperCommand::Help(ret);
InternalDumpCommand::Help(ret); InternalDumpCommand::Help(ret);
RepairCommand::Help(ret);
fprintf(stderr, "%s\n", ret.c_str()); fprintf(stderr, "%s\n", ret.c_str());
} }

Loading…
Cancel
Save