Skip to content

Commit

Permalink
Expose RepairDB as ldb command
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ajkr committed Mar 12, 2016
1 parent 580fede commit 08304c0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tools/ldb_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions tools/ldb_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,21 @@ class CheckConsistencyCommand : public LDBCommand {
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
1 change: 1 addition & 0 deletions tools/ldb_tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class LDBCommandRunner {
ListColumnFamiliesCommand::Help(ret);
DBFileDumperCommand::Help(ret);
InternalDumpCommand::Help(ret);
RepairCommand::Help(ret);

fprintf(stderr, "%s\n", ret.c_str());
}
Expand Down

0 comments on commit 08304c0

Please sign in to comment.