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

Function clusterGenNodesSlotsInfo

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

Generate the slot topology for all nodes and store the string representation * in the slots_info struct on the node. This is used to improve the efficiency * of clusterGenNodesDescription() because it removes looping of the slot space * for generating the slot info for each node individually. */

Source from the content-addressed store, hash-verified

4248 * of clusterGenNodesDescription() because it removes looping of the slot space
4249 * for generating the slot info for each node individually. */
4250void clusterGenNodesSlotsInfo(int filter) {
4251 clusterNode *n = NULL;
4252 int start = -1;
4253
4254 for (int i = 0; i <= CLUSTER_SLOTS; i++) {
4255 /* Find start node and slot id. */
4256 if (n == NULL) {
4257 if (i == CLUSTER_SLOTS) break;
4258 n = server.cluster->slots[i];
4259 start = i;
4260 continue;
4261 }
4262
4263 /* Generate slots info when occur different node with start
4264 * or end of slot. */
4265 if (i == CLUSTER_SLOTS || n != server.cluster->slots[i]) {
4266 if (!(n->flags & filter)) {
4267 if (n->slots_info == NULL) n->slots_info = sdsempty();
4268 if (start == i-1) {
4269 n->slots_info = sdscatfmt(n->slots_info," %i",start);
4270 } else {
4271 n->slots_info = sdscatfmt(n->slots_info," %i-%i",start,i-1);
4272 }
4273 }
4274 if (i == CLUSTER_SLOTS) break;
4275 n = server.cluster->slots[i];
4276 start = i;
4277 }
4278 }
4279}
4280
4281/* Generate a csv-alike representation of the nodes we are aware of,
4282 * including the "myself" node, and return an SDS string containing the

Callers 1

Calls 2

sdsemptyFunction · 0.85
sdscatfmtFunction · 0.85

Tested by

no test coverage detected