MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / clusterManagerNodeWithLeastReplicas

Function clusterManagerNodeWithLeastReplicas

src/redis-cli.c:4119–4134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4117 * number of replicas, one at random is returned. */
4118
4119static clusterManagerNode *clusterManagerNodeWithLeastReplicas() {
4120 clusterManagerNode *node = NULL;
4121 int lowest_count = 0;
4122 listIter li;
4123 listNode *ln;
4124 listRewind(cluster_manager.nodes, &li);
4125 while ((ln = listNext(&li)) != NULL) {
4126 clusterManagerNode *n = ln->value;
4127 if (n->flags & CLUSTER_MANAGER_FLAG_SLAVE) continue;
4128 if (node == NULL || n->replicas_count < lowest_count) {
4129 node = n;
4130 lowest_count = n->replicas_count;
4131 }
4132 }
4133 return node;
4134}
4135
4136/* Slot 'slot' was found to be in importing or migrating state in one or
4137 * more nodes. This function fixes this condition by migrating keys where

Callers 2

Calls 2

listRewindFunction · 0.85
listNextFunction · 0.85

Tested by

no test coverage detected