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

fix: spop binlog , rewritten as srem #2541

Merged
merged 8 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
55 changes: 30 additions & 25 deletions include/pika_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,36 @@ class SAddCmd : public Cmd {
void DoInitial() override;
};

class SRemCmd : public Cmd {
public:
SRemCmd(const std::string& name, int arity, uint32_t flag)
: Cmd(name, arity, flag, static_cast<uint32_t>(AclCategory::SET)) {}
std::vector<std::string> current_key() const override {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
void Do() override;
void DoUpdateCache() override;
void DoThroughDB() override;
void Split(const HintKeys& hint_keys) override{};
void Merge() override{};
Cmd* Clone() override { return new SRemCmd(*this); }

private:
std::string key_;
std::vector<std::string> members_;
rocksdb::Status s_;
int32_t deleted_ = 0;
void DoInitial() override;
chenbt-hz marked this conversation as resolved.
Show resolved Hide resolved
};

class SPopCmd : public Cmd {
public:
SPopCmd(const std::string& name, int arity, uint32_t flag)
: Cmd(name, arity, flag, static_cast<uint32_t>(AclCategory::SET)) {}
: Cmd(name, arity, flag, static_cast<uint32_t>(AclCategory::SET)) {
srem_cmd_ = std::make_shared<SRemCmd>(kCmdNameSRem, -3, kCmdFlagsWrite | kCmdFlagsSet);
}
std::vector<std::string> current_key() const override {
std::vector<std::string> res;
res.push_back(key_);
Expand All @@ -51,10 +77,13 @@ class SPopCmd : public Cmd {
void Split(const HintKeys& hint_keys) override{};
void Merge() override{};
Cmd* Clone() override { return new SPopCmd(*this); }
void DoBinlog() override;

private:
std::string key_;
std::vector<std::string> members_;
// used for write binlog
std::shared_ptr<SRemCmd> srem_cmd_;
int64_t count_ = 1;
rocksdb::Status s_;
void DoInitial() override;
Expand Down Expand Up @@ -131,30 +160,6 @@ class SScanCmd : public Cmd {
}
};

class SRemCmd : public Cmd {
public:
SRemCmd(const std::string& name, int arity, uint32_t flag)
: Cmd(name, arity, flag, static_cast<uint32_t>(AclCategory::SET)) {}
std::vector<std::string> current_key() const override {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
void Do() override;
void DoUpdateCache() override;
void DoThroughDB() override;
void Split(const HintKeys& hint_keys) override{};
void Merge() override{};
Cmd* Clone() override { return new SRemCmd(*this); }

private:
std::string key_;
std::vector<std::string> members_;
rocksdb::Status s_;
int32_t deleted_ = 0;
void DoInitial() override;
};

class SUnionCmd : public Cmd {
public:
SUnionCmd(const std::string& name, int arity, uint32_t flag)
Expand Down
18 changes: 18 additions & 0 deletions src/pika_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,24 @@ void SPopCmd::DoUpdateCache() {
}
}

void SPopCmd::DoBinlog() {
if (!s_.ok()) {
return;
}

PikaCmdArgsType srem_args;
srem_args.emplace_back("srem");
srem_args.emplace_back(key_);
for (auto m = members_.begin(); m != members_.end(); ++m) {
srem_args.emplace_back(*m);
}

srem_cmd_->Initial(srem_args, db_name_);
srem_cmd_->SetConn(GetConn());
srem_cmd_->SetResp(resp_.lock());
srem_cmd_->DoBinlog();
}

void SCardCmd::DoInitial() {
if (!CheckArg(argv_.size())) {
res_.SetRes(CmdRes::kWrongNum, kCmdNameSCard);
Expand Down
Loading