ldb support for range delete
Summary: Add a subcommand to ldb with which we can delete a range of keys. Closes https://github.com/facebook/rocksdb/pull/1521 Differential Revision: D4186338 Pulled By: ajkr fbshipit-source-id: b8e9861
This commit is contained in:
parent
661e4c9267
commit
53b693f5fe
@ -167,6 +167,10 @@ LDBCommand* LDBCommand::SelectCommand(const ParsedParams& parsed_params) {
|
|||||||
} else if (parsed_params.cmd == DeleteCommand::Name()) {
|
} else if (parsed_params.cmd == DeleteCommand::Name()) {
|
||||||
return new DeleteCommand(parsed_params.cmd_params, parsed_params.option_map,
|
return new DeleteCommand(parsed_params.cmd_params, parsed_params.option_map,
|
||||||
parsed_params.flags);
|
parsed_params.flags);
|
||||||
|
} else if (parsed_params.cmd == DeleteRangeCommand::Name()) {
|
||||||
|
return new DeleteRangeCommand(parsed_params.cmd_params,
|
||||||
|
parsed_params.option_map,
|
||||||
|
parsed_params.flags);
|
||||||
} else if (parsed_params.cmd == ApproxSizeCommand::Name()) {
|
} else if (parsed_params.cmd == ApproxSizeCommand::Name()) {
|
||||||
return new ApproxSizeCommand(parsed_params.cmd_params,
|
return new ApproxSizeCommand(parsed_params.cmd_params,
|
||||||
parsed_params.option_map, parsed_params.flags);
|
parsed_params.option_map, parsed_params.flags);
|
||||||
@ -1854,6 +1858,14 @@ class InMemoryHandler : public WriteBatch::Handler {
|
|||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual Status DeleteRangeCF(uint32_t cf, const Slice& begin_key,
|
||||||
|
const Slice& end_key) override {
|
||||||
|
row_ << "DELETE_RANGE(" << cf << ") : ";
|
||||||
|
row_ << LDBCommand::StringToHex(begin_key.ToString()) << " ";
|
||||||
|
row_ << LDBCommand::StringToHex(end_key.ToString()) << " ";
|
||||||
|
return Status::OK();
|
||||||
|
}
|
||||||
|
|
||||||
virtual Status MarkBeginPrepare() override {
|
virtual Status MarkBeginPrepare() override {
|
||||||
row_ << "BEGIN_PREARE ";
|
row_ << "BEGIN_PREARE ";
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
@ -2346,6 +2358,45 @@ void DeleteCommand::DoCommand() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeleteRangeCommand::DeleteRangeCommand(
|
||||||
|
const std::vector<std::string>& params,
|
||||||
|
const std::map<std::string, std::string>& options,
|
||||||
|
const std::vector<std::string>& flags)
|
||||||
|
: LDBCommand(options, flags, false,
|
||||||
|
BuildCmdLineOptions({ARG_HEX, ARG_KEY_HEX, ARG_VALUE_HEX})) {
|
||||||
|
if (params.size() != 2) {
|
||||||
|
exec_state_ = LDBCommandExecuteResult::Failed(
|
||||||
|
"begin and end keys must be specified for the delete command");
|
||||||
|
} else {
|
||||||
|
begin_key_ = params.at(0);
|
||||||
|
end_key_ = params.at(1);
|
||||||
|
if (is_key_hex_) {
|
||||||
|
begin_key_ = HexToString(begin_key_);
|
||||||
|
end_key_ = HexToString(end_key_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeleteRangeCommand::Help(std::string& ret) {
|
||||||
|
ret.append(" ");
|
||||||
|
ret.append(DeleteRangeCommand::Name() + " <begin key> <end key>");
|
||||||
|
ret.append("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeleteRangeCommand::DoCommand() {
|
||||||
|
if (!db_) {
|
||||||
|
assert(GetExecuteState().IsFailed());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Status st =
|
||||||
|
db_->DeleteRange(WriteOptions(), GetCfHandle(), begin_key_, end_key_);
|
||||||
|
if (st.ok()) {
|
||||||
|
fprintf(stdout, "OK\n");
|
||||||
|
} else {
|
||||||
|
exec_state_ = LDBCommandExecuteResult::Failed(st.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PutCommand::PutCommand(const std::vector<std::string>& params,
|
PutCommand::PutCommand(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)
|
||||||
|
@ -374,6 +374,23 @@ class DeleteCommand : public LDBCommand {
|
|||||||
std::string key_;
|
std::string key_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class DeleteRangeCommand : public LDBCommand {
|
||||||
|
public:
|
||||||
|
static std::string Name() { return "deleterange"; }
|
||||||
|
|
||||||
|
DeleteRangeCommand(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);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string begin_key_;
|
||||||
|
std::string end_key_;
|
||||||
|
};
|
||||||
|
|
||||||
class PutCommand : public LDBCommand {
|
class PutCommand : public LDBCommand {
|
||||||
public:
|
public:
|
||||||
static std::string Name() { return "put"; }
|
static std::string Name() { return "put"; }
|
||||||
|
@ -62,6 +62,7 @@ void LDBCommandRunner::PrintHelp(const char* exec_name) {
|
|||||||
BatchPutCommand::Help(ret);
|
BatchPutCommand::Help(ret);
|
||||||
ScanCommand::Help(ret);
|
ScanCommand::Help(ret);
|
||||||
DeleteCommand::Help(ret);
|
DeleteCommand::Help(ret);
|
||||||
|
DeleteRangeCommand::Help(ret);
|
||||||
DBQuerierCommand::Help(ret);
|
DBQuerierCommand::Help(ret);
|
||||||
ApproxSizeCommand::Help(ret);
|
ApproxSizeCommand::Help(ret);
|
||||||
CheckConsistencyCommand::Help(ret);
|
CheckConsistencyCommand::Help(ret);
|
||||||
|
Loading…
Reference in New Issue
Block a user