Skip to content

Commit

Permalink
Reuse obey_client variable in processCommand() function (valkey-i…
Browse files Browse the repository at this point in the history
…o#1101)

I’ve prepared a minor fix for `processCommand()` function. 

In `processCommand()`, the `obey_client` variable is created, but some
conditional statements call the `mustObeyClient()` function instead of
reusing `obey_client`.

I’ve modified these statements to `reuse obey_client`.

Since I’m relatively new to Redis, please let me know if there are any
reasons why the conditional statements need to call `mustObeyClient()`
again.

Thank you for taking the time to review my PR.

Signed-off-by: otheng03 <[email protected]>
  • Loading branch information
otheng03 authored Oct 6, 2024
1 parent 00c9797 commit a1cc7c2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -3891,7 +3891,7 @@ int processCommand(client *c) {
(c->cmd->proc == execCommand && (c->mstate.cmd_flags & (CMD_WRITE | CMD_MAY_REPLICATE)));
int is_deny_async_loading_command = (cmd_flags & CMD_NO_ASYNC_LOADING) ||
(c->cmd->proc == execCommand && (c->mstate.cmd_flags & CMD_NO_ASYNC_LOADING));
int obey_client = mustObeyClient(c);
const int obey_client = mustObeyClient(c);

if (authRequired(c)) {
/* AUTH and HELLO and no auth commands are valid even in
Expand Down Expand Up @@ -3924,7 +3924,7 @@ int processCommand(client *c) {
* However we don't perform the redirection if:
* 1) The sender of this command is our primary.
* 2) The command has no key arguments. */
if (server.cluster_enabled && !mustObeyClient(c) &&
if (server.cluster_enabled && !obey_client &&
!(!(c->cmd->flags & CMD_MOVABLE_KEYS) && c->cmd->key_specs_num == 0 && c->cmd->proc != execCommand)) {
int error_code;
clusterNode *n = getNodeByQuery(c, c->cmd, c->argv, c->argc, &c->slot, &error_code);
Expand All @@ -3941,7 +3941,7 @@ int processCommand(client *c) {
}
}

if (!server.cluster_enabled && c->capa & CLIENT_CAPA_REDIRECT && server.primary_host && !mustObeyClient(c) &&
if (!server.cluster_enabled && c->capa & CLIENT_CAPA_REDIRECT && server.primary_host && !obey_client &&
(is_write_command || (is_read_command && !c->flag.readonly))) {
if (server.failover_state == FAILOVER_IN_PROGRESS) {
/* During the FAILOVER process, when conditions are met (such as
Expand Down

0 comments on commit a1cc7c2

Please sign in to comment.