From 8d28ad1245e004f7435ff98e45a7c56ec3351537 Mon Sep 17 00:00:00 2001 From: PragmaTwice Date: Sat, 23 Nov 2024 16:24:24 +0800 Subject: [PATCH] feat(conn): allow CONFIG in stale-data replica --- src/server/redis_connection.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/server/redis_connection.cc b/src/server/redis_connection.cc index 2e4ed68c552..092df73d382 100644 --- a/src/server/redis_connection.cc +++ b/src/server/redis_connection.cc @@ -366,6 +366,10 @@ static bool IsCmdForIndexing(uint64_t cmd_flags, CommandCategory cmd_cat) { (cmd_cat == CommandCategory::Hash || cmd_cat == CommandCategory::JSON || cmd_cat == CommandCategory::Key); } +static bool IsCmdAllowedInStaleData(const std::string &cmd_name) { + return cmd_name == "info" || cmd_name == "slaveof" || cmd_name == "config"; +} + void Connection::ExecuteCommands(std::deque *to_process_cmds) { const Config *config = srv_->GetConfig(); std::string reply; @@ -479,7 +483,7 @@ void Connection::ExecuteCommands(std::deque *to_process_cmds) { continue; } - if (!config->slave_serve_stale_data && srv_->IsSlave() && cmd_name != "info" && cmd_name != "slaveof" && + if (!config->slave_serve_stale_data && srv_->IsSlave() && !IsCmdAllowedInStaleData(cmd_name) && srv_->GetReplicationState() != kReplConnected) { Reply(redis::Error({Status::RedisMasterDown, "Link with MASTER is down "