From db7c17e969cb09cd2a03a13036c2aaa80e1485a4 Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 13 Mar 2013 17:21:20 +0100 Subject: [PATCH] Cluster: FAILOVER_AUTH_REQUEST message type introduced. This message is sent by a slave that is ready to failover its master to other nodes to get the authorization from the majority of masters. --- src/cluster.c | 17 +++++++++++++++++ src/redis.h | 1 + 2 files changed, 18 insertions(+) diff --git a/src/cluster.c b/src/cluster.c index a5c42415..ac44d565 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -1248,6 +1248,23 @@ void clusterPropagatePublish(robj *channel, robj *message) { * SLAVE node specific functions * -------------------------------------------------------------------------- */ +/* This function sends a FAILOVE_AUTH_REQUEST message to every node in order to + * see if there is the quorum for this slave instance to failover its failing + * master. + * + * Note that we send the failover request to everybody, master and slave nodes, + * but only the masters are supposed to reply to our query. */ +void clusterRequestFailoverAuth(void) { + unsigned char buf[4096], *payload; + clusterMsg *hdr = (clusterMsg*) buf; + uint32_t totlen; + + clusterBuildMessageHdr(hdr,CLUSTERMSG_TYPE_FAILOVER_AUTH_REQUEST); + totlen = sizeof(clusterMsg)-sizeof(union clusterMsgData); + hdr->totlen = htonl(totlen); + clusterBroadcastMessage(payload,totlen); +} + /* This function is called if we are a slave node and our master serving * a non-zero amount of hash slots is in PFAIL state. * diff --git a/src/redis.h b/src/redis.h index 694f2d01..5a2392c8 100644 --- a/src/redis.h +++ b/src/redis.h @@ -594,6 +594,7 @@ typedef struct { #define CLUSTERMSG_TYPE_MEET 2 /* Meet "let's join" message */ #define CLUSTERMSG_TYPE_FAIL 3 /* Mark node xxx as failing */ #define CLUSTERMSG_TYPE_PUBLISH 4 /* Pub/Sub Publish propagation */ +#define CLUSTERMSG_TYPE_FAILOVER_AUTH_REQUEST 5 /* May I failover? */ /* Initially we don't know our "name", but we'll find it once we connect * to the first node, using the getsockname() function. Then we'll use this -- GitLab