MCPcopy Create free account
hub / github.com/F-Stack/f-stack / clusterGetSlaveRank

Function clusterGetSlaveRank

app/redis-6.2.6/src/cluster.c:3009–3024  ·  view source on GitHub ↗

This function returns the "rank" of this instance, a slave, in the context * of its master-slaves ring. The rank of the slave is given by the number of * other slaves for the same master that have a better replication offset * compared to the local one (better means, greater, so they claim more data). * * A slave with rank 0 is the one with the greatest (most up to date) * replication offset

Source from the content-addressed store, hash-verified

3007 * get voted and replace a failing master. Slaves with better replication
3008 * offsets are more likely to win. */
3009int clusterGetSlaveRank(void) {
3010 long long myoffset;
3011 int j, rank = 0;
3012 clusterNode *master;
3013
3014 serverAssert(nodeIsSlave(myself));
3015 master = myself->slaveof;
3016 if (master == NULL) return 0; /* Never called by slaves without master. */
3017
3018 myoffset = replicationGetSlaveOffset();
3019 for (j = 0; j < master->numslaves; j++)
3020 if (master->slaves[j] != myself &&
3021 !nodeCantFailover(master->slaves[j]) &&
3022 master->slaves[j]->repl_offset > myoffset) rank++;
3023 return rank;
3024}
3025
3026/* This function is called by clusterHandleSlaveFailover() in order to
3027 * let the slave log why it is not able to failover. Sometimes there are

Callers 1

Calls 1

Tested by

no test coverage detected