add checkpoint to ldb

Summary: Closes https://github.com/facebook/rocksdb/pull/2017

Differential Revision: D4747656

Pulled By: lightmark

fbshipit-source-id: c52f160
main
Aaron Gao 8 years ago committed by Facebook Github Bot
parent 4b04addfce
commit 78cb195595
  1. 46
      tools/ldb_cmd.cc
  2. 18
      tools/ldb_cmd_impl.h
  3. 1
      tools/ldb_tool.cc

@ -21,6 +21,7 @@
#include "rocksdb/cache.h" #include "rocksdb/cache.h"
#include "rocksdb/table_properties.h" #include "rocksdb/table_properties.h"
#include "rocksdb/utilities/backupable_db.h" #include "rocksdb/utilities/backupable_db.h"
#include "rocksdb/utilities/checkpoint.h"
#include "rocksdb/utilities/object_registry.h" #include "rocksdb/utilities/object_registry.h"
#include "rocksdb/write_batch.h" #include "rocksdb/write_batch.h"
#include "rocksdb/write_buffer_manager.h" #include "rocksdb/write_buffer_manager.h"
@ -222,6 +223,10 @@ LDBCommand* LDBCommand::SelectCommand(const ParsedParams& parsed_params) {
return new CheckConsistencyCommand(parsed_params.cmd_params, return new CheckConsistencyCommand(parsed_params.cmd_params,
parsed_params.option_map, parsed_params.option_map,
parsed_params.flags); parsed_params.flags);
} else if (parsed_params.cmd == CheckPointCommand::Name()) {
return new CheckPointCommand(parsed_params.cmd_params,
parsed_params.option_map,
parsed_params.flags);
} else if (parsed_params.cmd == RepairCommand::Name()) { } else if (parsed_params.cmd == RepairCommand::Name()) {
return new RepairCommand(parsed_params.cmd_params, parsed_params.option_map, return new RepairCommand(parsed_params.cmd_params, parsed_params.option_map,
parsed_params.flags); parsed_params.flags);
@ -2564,6 +2569,47 @@ void CheckConsistencyCommand::DoCommand() {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
const std::string CheckPointCommand::ARG_CHECKPOINT_DIR = "checkpoint_dir";
CheckPointCommand::CheckPointCommand(
const std::vector<std::string>& params,
const std::map<std::string, std::string>& options,
const std::vector<std::string>& flags)
: LDBCommand(options, flags, false /* is_read_only */,
BuildCmdLineOptions({ARG_CHECKPOINT_DIR})) {
auto itr = options.find(ARG_CHECKPOINT_DIR);
if (itr == options.end()) {
exec_state_ = LDBCommandExecuteResult::Failed(
"--" + ARG_CHECKPOINT_DIR + ": missing checkpoint directory");
} else {
checkpoint_dir_ = itr->second;
}
}
void CheckPointCommand::Help(std::string& ret) {
ret.append(" ");
ret.append(CheckPointCommand::Name());
ret.append(" [--" + ARG_CHECKPOINT_DIR + "] ");
ret.append("\n");
}
void CheckPointCommand::DoCommand() {
if (!db_) {
assert(GetExecuteState().IsFailed());
return;
}
Checkpoint* checkpoint;
Status status = Checkpoint::Create(db_, &checkpoint);
status = checkpoint->CreateCheckpoint(checkpoint_dir_);
if (status.ok()) {
printf("OK\n");
} else {
exec_state_ = LDBCommandExecuteResult::Failed(status.ToString());
}
}
// ----------------------------------------------------------------------------
RepairCommand::RepairCommand(const std::vector<std::string>& params, RepairCommand::RepairCommand(const std::vector<std::string>& params,
const std::map<std::string, std::string>& options, const std::map<std::string, std::string>& options,
const std::vector<std::string>& flags) const std::vector<std::string>& flags)

@ -448,6 +448,23 @@ class CheckConsistencyCommand : public LDBCommand {
static void Help(std::string& ret); static void Help(std::string& ret);
}; };
class CheckPointCommand : public LDBCommand {
public:
static std::string Name() { return "checkpoint"; }
CheckPointCommand(const std::vector<std::string>& params,
const std::map<std::string, std::string>& options,
const std::vector<std::string>& flags);
virtual void DoCommand() override;
static void Help(std::string& ret);
std::string checkpoint_dir_;
private:
static const std::string ARG_CHECKPOINT_DIR;
};
class RepairCommand : public LDBCommand { class RepairCommand : public LDBCommand {
public: public:
static std::string Name() { return "repair"; } static std::string Name() { return "repair"; }
@ -503,4 +520,5 @@ class RestoreCommand : public BackupableCommand {
virtual bool NoDBOpen() override { return true; } virtual bool NoDBOpen() override { return true; }
static void Help(std::string& ret); static void Help(std::string& ret);
}; };
} // namespace rocksdb } // namespace rocksdb

@ -82,6 +82,7 @@ void LDBCommandRunner::PrintHelp(const char* exec_name) {
RepairCommand::Help(ret); RepairCommand::Help(ret);
BackupCommand::Help(ret); BackupCommand::Help(ret);
RestoreCommand::Help(ret); RestoreCommand::Help(ret);
CheckPointCommand::Help(ret);
fprintf(stderr, "%s\n", ret.c_str()); fprintf(stderr, "%s\n", ret.c_str());
} }

Loading…
Cancel
Save