Cluster refactor: Add failover cmd support to cluster api
The failover command is up until now not supported in cluster mode. This commit allows a cluster implementation to support the command. The legacy clustering implementation still does not support this command. Signed-off-by: Josh Hershberg <yehoshua@redis.com>
This commit is contained in:
parent
c6157b3510
commit
2e5181ef28
@ -96,6 +96,8 @@ char* clusterNodeHostname(clusterNode *node);
|
|||||||
const char *getPreferredEndpoint(clusterNode *n);
|
const char *getPreferredEndpoint(clusterNode *n);
|
||||||
void migrateCommand(client *c);
|
void migrateCommand(client *c);
|
||||||
long long getReplOffset(clusterNode *node);
|
long long getReplOffset(clusterNode *node);
|
||||||
|
int clusterAllowFailoverCmd(client *c);
|
||||||
|
void clusterPromoteSelfToMaster(void);
|
||||||
|
|
||||||
char **clusterDebugCommandHelp(void);
|
char **clusterDebugCommandHelp(void);
|
||||||
ConnectionType *connTypeOfCluster(void);
|
ConnectionType *connTypeOfCluster(void);
|
||||||
|
@ -6400,11 +6400,27 @@ long long getReplOffset(clusterNode *node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *getPreferredEndpoint(clusterNode *n) {
|
const char *getPreferredEndpoint(clusterNode *n) {
|
||||||
char* hostname = clusterNodeHostname(n);
|
char *hostname = clusterNodeHostname(n);
|
||||||
switch(server.cluster_preferred_endpoint_type) {
|
switch (server.cluster_preferred_endpoint_type) {
|
||||||
case CLUSTER_ENDPOINT_TYPE_IP: return clusterNodeIp(n);
|
case CLUSTER_ENDPOINT_TYPE_IP:
|
||||||
case CLUSTER_ENDPOINT_TYPE_HOSTNAME: return (hostname != NULL && hostname[0] != '\0') ? hostname : "?";
|
return clusterNodeIp(n);
|
||||||
case CLUSTER_ENDPOINT_TYPE_UNKNOWN_ENDPOINT: return "";
|
case CLUSTER_ENDPOINT_TYPE_HOSTNAME:
|
||||||
|
return (hostname != NULL && hostname[0] != '\0') ? hostname : "?";
|
||||||
|
case CLUSTER_ENDPOINT_TYPE_UNKNOWN_ENDPOINT:
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int clusterAllowFailoverCmd(client *c) {
|
||||||
|
if (!server.cluster_enabled) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
addReplyError(c,"FAILOVER not allowed in cluster mode. "
|
||||||
|
"Use CLUSTER FAILOVER command instead.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void clusterPromoteSelfToMaster(void) {
|
||||||
|
replicationUnsetMaster();
|
||||||
|
}
|
||||||
|
@ -951,7 +951,11 @@ void syncCommand(client *c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!strcasecmp(c->argv[1]->ptr,server.replid)) {
|
if (!strcasecmp(c->argv[1]->ptr,server.replid)) {
|
||||||
replicationUnsetMaster();
|
if (server.cluster_enabled) {
|
||||||
|
clusterPromoteSelfToMaster();
|
||||||
|
} else {
|
||||||
|
replicationUnsetMaster();
|
||||||
|
}
|
||||||
sds client = catClientInfoString(sdsempty(),c);
|
sds client = catClientInfoString(sdsempty(),c);
|
||||||
serverLog(LL_NOTICE,
|
serverLog(LL_NOTICE,
|
||||||
"MASTER MODE enabled (failover request from '%s')",client);
|
"MASTER MODE enabled (failover request from '%s')",client);
|
||||||
@ -4061,12 +4065,10 @@ void abortFailover(const char *err) {
|
|||||||
* will attempt forever and must be manually aborted.
|
* will attempt forever and must be manually aborted.
|
||||||
*/
|
*/
|
||||||
void failoverCommand(client *c) {
|
void failoverCommand(client *c) {
|
||||||
if (server.cluster_enabled) {
|
if (!clusterAllowFailoverCmd(c)) {
|
||||||
addReplyError(c,"FAILOVER not allowed in cluster mode. "
|
|
||||||
"Use CLUSTER FAILOVER command instead.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle special case for abort */
|
/* Handle special case for abort */
|
||||||
if ((c->argc == 2) && !strcasecmp(c->argv[1]->ptr,"abort")) {
|
if ((c->argc == 2) && !strcasecmp(c->argv[1]->ptr,"abort")) {
|
||||||
if (server.failover_state == NO_FAILOVER) {
|
if (server.failover_state == NO_FAILOVER) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user