Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add subcommand and permission check to RDB command #1834

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/commands/cmd_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,14 @@ class CommandRestore : public Commander {
class CommandRdb : public Commander {
public:
Status Parse(const std::vector<std::string> &args) override {
CommandParser parser(args, 3);
CommandParser parser(args, 1);

type_ = GET_OR_RET(parser.TakeStr());
if (!util::EqualICase(type_, "load")) {
return {Status::RedisParseErr, "unknown subcommand"};
}

path_ = GET_OR_RET(parser.TakeStr());
while (parser.Good()) {
if (parser.EatEqICase("NX")) {
overwrite_exist_key_ = false;
Expand All @@ -1093,12 +1100,13 @@ class CommandRdb : public Commander {
}

Status Execute(Server *svr, Connection *conn, std::string *output) override {
rocksdb::Status db_status;
if (!conn->IsAdmin()) {
return {Status::RedisExecErr, errAdminPermissionRequired};
}

redis::Database redis(svr->storage, conn->GetNamespace());
auto type = args_[1];
auto path = args_[2];

auto stream_ptr = std::make_unique<RdbFileStream>(path);
auto stream_ptr = std::make_unique<RdbFileStream>(path_);
GET_OR_RET(stream_ptr->Open());

RDB rdb(svr->storage, conn->GetNamespace(), std::move(stream_ptr));
Expand All @@ -1109,6 +1117,8 @@ class CommandRdb : public Commander {
}

private:
std::string type_;
std::string path_;
bool overwrite_exist_key_ = true; // default overwrite exist key
uint32_t db_index_ = 0;
};
Expand Down