mirror of
https://github.com/fluencelabs/redis
synced 2025-03-19 17:10:50 +00:00
Cluster: make getNodeByQuery() responsible of -CLUSTERDOWN errors.
This fixes a bug introduced by d827dbf, and makes the code consistent with the logic of always allowing, while the cluster is down, commands that don't target any key. As a side effect the code is also simpler now.
This commit is contained in:
parent
330715afd8
commit
971e3c51b6
@ -5065,7 +5065,10 @@ void readwriteCommand(client *c) {
|
|||||||
* CLUSTER_REDIR_DOWN_UNBOUND if the request addresses a slot which is
|
* CLUSTER_REDIR_DOWN_UNBOUND if the request addresses a slot which is
|
||||||
* not bound to any node. In this case the cluster global state should be
|
* not bound to any node. In this case the cluster global state should be
|
||||||
* already "down" but it is fragile to rely on the update of the global state,
|
* already "down" but it is fragile to rely on the update of the global state,
|
||||||
* so we also handle it here. */
|
* so we also handle it here.
|
||||||
|
*
|
||||||
|
* CLUSTER_REDIR_DOWN_STATE if the cluster is down but the user attempts to
|
||||||
|
* execute a command that addresses one or more keys. */
|
||||||
clusterNode *getNodeByQuery(client *c, struct redisCommand *cmd, robj **argv, int argc, int *hashslot, int *error_code) {
|
clusterNode *getNodeByQuery(client *c, struct redisCommand *cmd, robj **argv, int argc, int *hashslot, int *error_code) {
|
||||||
clusterNode *n = NULL;
|
clusterNode *n = NULL;
|
||||||
robj *firstkey = NULL;
|
robj *firstkey = NULL;
|
||||||
@ -5172,9 +5175,15 @@ clusterNode *getNodeByQuery(client *c, struct redisCommand *cmd, robj **argv, in
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* No key at all in command? then we can serve the request
|
/* No key at all in command? then we can serve the request
|
||||||
* without redirections or errors. */
|
* without redirections or errors in all the cases. */
|
||||||
if (n == NULL) return myself;
|
if (n == NULL) return myself;
|
||||||
|
|
||||||
|
/* Cluster is globally down but we got keys? We can't serve the request. */
|
||||||
|
if (server.cluster->state != CLUSTER_OK) {
|
||||||
|
if (error_code) *error_code = CLUSTER_REDIR_DOWN_STATE;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Return the hashslot by reference. */
|
/* Return the hashslot by reference. */
|
||||||
if (hashslot) *hashslot = slot;
|
if (hashslot) *hashslot = slot;
|
||||||
|
|
||||||
|
10
src/server.c
10
src/server.c
@ -2391,14 +2391,9 @@ int processCommand(client *c) {
|
|||||||
c->cmd->proc != execCommand))
|
c->cmd->proc != execCommand))
|
||||||
{
|
{
|
||||||
int hashslot;
|
int hashslot;
|
||||||
|
|
||||||
if (server.cluster->state != CLUSTER_OK) {
|
|
||||||
flagTransaction(c);
|
|
||||||
clusterRedirectClient(c,NULL,0,CLUSTER_REDIR_DOWN_STATE);
|
|
||||||
return C_OK;
|
|
||||||
} else {
|
|
||||||
int error_code;
|
int error_code;
|
||||||
clusterNode *n = getNodeByQuery(c,c->cmd,c->argv,c->argc,&hashslot,&error_code);
|
clusterNode *n = getNodeByQuery(c,c->cmd,c->argv,c->argc,
|
||||||
|
&hashslot,&error_code);
|
||||||
if (n == NULL || n != server.cluster->myself) {
|
if (n == NULL || n != server.cluster->myself) {
|
||||||
if (c->cmd->proc == execCommand) {
|
if (c->cmd->proc == execCommand) {
|
||||||
discardTransaction(c);
|
discardTransaction(c);
|
||||||
@ -2409,7 +2404,6 @@ int processCommand(client *c) {
|
|||||||
return C_OK;
|
return C_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* Handle the maxmemory directive.
|
/* Handle the maxmemory directive.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user