Skip to content

Commit

Permalink
Make special exclusive command check a function (#1638)
Browse files Browse the repository at this point in the history
  • Loading branch information
PragmaTwice authored Aug 6, 2023
1 parent f254695 commit dbd5f8d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/server/redis_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "commands/commander.h"
#include "fmt/format.h"
#include "string_util.h"
#ifdef ENABLE_OPENSSL
#include <event2/bufferevent_ssl.h>
#endif
Expand Down Expand Up @@ -289,6 +290,13 @@ void Connection::RecordProfilingSampleIfNeed(const std::string &cmd, uint64_t du
svr_->GetPerfLog()->PushEntry(std::move(entry));
}

bool IsSpecialExclusiveCommand(const std::string &cmd_name, const std::vector<std::string> &cmd_tokens,
Config *config) {
return (cmd_name == "config" && cmd_tokens.size() == 2 && util::EqualICase(cmd_tokens[1], "set")) ||
(config->cluster_enabled && (cmd_name == "clusterx" || cmd_name == "cluster") && cmd_tokens.size() >= 2 &&
Cluster::SubCommandIsExecExclusive(cmd_tokens[1]));
}

void Connection::ExecuteCommands(std::deque<CommandTokens> *to_process_cmds) {
Config *config = svr_->GetConfig();
std::string reply, password = config->requirepass;
Expand Down Expand Up @@ -330,10 +338,7 @@ void Connection::ExecuteCommands(std::deque<CommandTokens> *to_process_cmds) {
// Otherwise, we just use 'ConcurrencyGuard' to allow all workers to execute commands at the same time.
if (IsFlagEnabled(Connection::kMultiExec) && attributes->name != "exec") {
// No lock guard, because 'exec' command has acquired 'WorkExclusivityGuard'
} else if (attributes->IsExclusive() ||
(cmd_name == "config" && cmd_tokens.size() == 2 && !strcasecmp(cmd_tokens[1].c_str(), "set")) ||
(config->cluster_enabled && (cmd_name == "clusterx" || cmd_name == "cluster") &&
cmd_tokens.size() >= 2 && Cluster::SubCommandIsExecExclusive(cmd_tokens[1]))) {
} else if (attributes->IsExclusive() || IsSpecialExclusiveCommand(cmd_name, cmd_tokens, config)) {
exclusivity = svr_->WorkExclusivityGuard();

// When executing lua script commands that have "exclusive" attribute, we need to know current connection,
Expand Down

0 comments on commit dbd5f8d

Please sign in to comment.