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

Make special exclusive command check a function #1638

Merged
merged 2 commits into from
Aug 6, 2023
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
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