From bf821954672121c592ced7454b6de182ddb0d4b7 Mon Sep 17 00:00:00 2001 From: antirez Date: Fri, 15 Mar 2013 15:43:53 +0100 Subject: [PATCH] Cluster: added function to broadcast pings. See the function top-comment for info why this is useful sometimes. --- src/cluster.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/cluster.c b/src/cluster.c index b9d96c985..e32052e89 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -1193,6 +1193,27 @@ void clusterSendPing(clusterLink *link, int type) { clusterSendMessage(link,buf,totlen); } +/* Send a PING packet to every connected node that's not in handshake state. + * + * Usually cluster nodes will ping just another node every second, however + * in Redis Cluster pings are not just used for failure detection, but also + * to carry important configuration informations. So broadcasting a ping is + * useful when something changes in the configuration and we want to make + * the cluster aware ASAP (for instance after a slave promotion). */ +void clusterBroadcastPing(void) { + dictIterator *di; + dictEntry *de; + + di = dictGetIterator(server.cluster->nodes); + while((de = dictNext(di)) != NULL) { + clusterNode *node = dictGetVal(de); + + if (node->flags & (REDIS_NODE_MYSELF|REDIS_NODE_HANDSHAKE)) continue; + clusterSendPing(node->link,CLUSTERMSG_TYPE_PONG); + } + dictReleaseIterator(di); +} + /* Send a PUBLISH message. * * If link is NULL, then the message is broadcasted to the whole cluster. */ -- GitLab