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 slave can't execute publish command (backport #238) #240

Merged
merged 1 commit into from
Apr 30, 2021
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
17 changes: 11 additions & 6 deletions src/redis_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3279,12 +3279,17 @@ class CommandDBSize : public Commander {

class CommandPublish : public Commander {
public:
CommandPublish() : Commander("publish", 3, true) {}
Status Execute(Server *svr, Connection *conn, std::string *output) override {
Redis::PubSub pubsub_db(svr->storage_);
auto s = pubsub_db.Publish(args_[1], args_[2]);
if (!s.ok()) {
return Status(Status::RedisExecErr, s.ToString());
// mark is_write as false here because slave should be able to execute publish command
CommandPublish() : Commander("publish", 3, false) {}
Status Execute(Server *svr, Connection *conn, std::string *output) override {
if (!svr->IsSlave()) {
// Compromise: can't replicate message to sub-replicas in a cascading-like structure.
// Replication is rely on wal seq, increase the seq on slave will break the replication, hence the compromise
Redis::PubSub pubsub_db(svr->storage_);
auto s = pubsub_db.Publish(args_[1], args_[2]);
if (!s.ok()) {
return Status(Status::RedisExecErr, s.ToString());
}
}

int receivers = svr->PublishMessage(args_[1], args_[2]);
Expand Down