From 282b82e9d20433aa266cd9f16ef1ccbbee199ce0 Mon Sep 17 00:00:00 2001 From: Chen Tianjie Date: Mon, 6 Nov 2023 17:48:58 +0800 Subject: [PATCH] Handle all CLUSTER_REDIR_ error code when verifying script. (#12707) Clarify the errors related to the cluster mode in the script, return the command that encountered an execution error along with the specific error message. --------- Co-authored-by: Madelyn Olson --- src/script.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/script.c b/src/script.c index 6a798a6e1..d0b9b9635 100644 --- a/src/script.c +++ b/src/script.c @@ -437,7 +437,22 @@ static int scriptVerifyClusterState(scriptRunCtx *run_ctx, client *c, client *or } else if (error_code == CLUSTER_REDIR_DOWN_STATE) { *err = sdsnew("Script attempted to execute a command while the " "cluster is down"); + } else if (error_code == CLUSTER_REDIR_CROSS_SLOT) { + *err = sdscatfmt(sdsempty(), + "Command '%S' in script attempted to access keys that don't hash to the same slot", + c->cmd->fullname); + } else if (error_code == CLUSTER_REDIR_UNSTABLE) { + /* The request spawns multiple keys in the same slot, + * but the slot is not "stable" currently as there is + * a migration or import in progress. */ + *err = sdscatfmt(sdsempty(), + "Unable to execute command '%S' in script " + "because undeclared keys were accessed during rehashing of the slot", + c->cmd->fullname); + } else if (error_code == CLUSTER_REDIR_DOWN_UNBOUND) { + *err = sdsnew("Script attempted to access a slot not served"); } else { + /* error_code == CLUSTER_REDIR_MOVED || error_code == CLUSTER_REDIR_ASK */ *err = sdsnew("Script attempted to access a non local key in a " "cluster node"); }