Skip to content

Commit

Permalink
Fix slave can't execute publish command (#238) (#241)
Browse files Browse the repository at this point in the history
(cherry picked from commit 7e09284)
  • Loading branch information
mergify[bot] authored Apr 30, 2021
1 parent e0ec568 commit 000b362
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/redis_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3258,12 +3258,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

0 comments on commit 000b362

Please sign in to comment.