Send the client the right redirection code, according to error_code * that should be set to one of CLUSTER_REDIR_* macros. * * If CLUSTER_REDIR_ASK or CLUSTER_REDIR_MOVED error codes * are used, then the node 'n' should not be NULL, but should be the * node we want to mention in the redirection. Moreover hashslot should * be set to the hash slot that caused the redirection. */
| 6098 | * node we want to mention in the redirection. Moreover hashslot should |
| 6099 | * be set to the hash slot that caused the redirection. */ |
| 6100 | void clusterRedirectClient(client *c, clusterNode *n, int hashslot, int error_code) { |
| 6101 | if (error_code == CLUSTER_REDIR_CROSS_SLOT) { |
| 6102 | addReplyError(c,"-CROSSSLOT Keys in request don't hash to the same slot"); |
| 6103 | } else if (error_code == CLUSTER_REDIR_UNSTABLE) { |
| 6104 | /* The request spawns multiple keys in the same slot, |
| 6105 | * but the slot is not "stable" currently as there is |
| 6106 | * a migration or import in progress. */ |
| 6107 | addReplyError(c,"-TRYAGAIN Multiple keys request during rehashing of slot"); |
| 6108 | } else if (error_code == CLUSTER_REDIR_DOWN_STATE) { |
| 6109 | addReplyError(c,"-CLUSTERDOWN The cluster is down"); |
| 6110 | } else if (error_code == CLUSTER_REDIR_DOWN_RO_STATE) { |
| 6111 | addReplyError(c,"-CLUSTERDOWN The cluster is down and only accepts read commands"); |
| 6112 | } else if (error_code == CLUSTER_REDIR_DOWN_UNBOUND) { |
| 6113 | addReplyError(c,"-CLUSTERDOWN Hash slot not served"); |
| 6114 | } else if (error_code == CLUSTER_REDIR_MOVED || |
| 6115 | error_code == CLUSTER_REDIR_ASK) |
| 6116 | { |
| 6117 | /* Redirect to IP:port. Include plaintext port if cluster is TLS but |
| 6118 | * client is non-TLS. */ |
| 6119 | int use_pport = (g_pserver->tls_cluster && |
| 6120 | c->conn && connGetType(c->conn) != CONN_TYPE_TLS); |
| 6121 | int port = use_pport && n->pport ? n->pport : n->port; |
| 6122 | addReplyErrorSds(c,sdscatprintf(sdsempty(), |
| 6123 | "-%s %d %s:%d", |
| 6124 | (error_code == CLUSTER_REDIR_ASK) ? "ASK" : "MOVED", |
| 6125 | hashslot, n->ip, port)); |
| 6126 | } else { |
| 6127 | serverPanic("getNodeByQuery() unknown error."); |
| 6128 | } |
| 6129 | } |
| 6130 | |
| 6131 | /* This function is called by the function processing clients incrementally |
| 6132 | * to detect timeouts, in order to handle the following case: |
no test coverage detected