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

Function clusterGenNodesSlotsInfo

src/cluster.cpp:4309–4338  ·  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

4307 * of clusterGenNodesDescription() because it removes looping of the slot space
4308 * for generating the slot info for each node individually. */
4309void clusterGenNodesSlotsInfo(int filter) {
4310 clusterNode *n = NULL;
4311 int start = -1;
4312
4313 for (int i = 0; i <= CLUSTER_SLOTS; i++) {
4314 /* Find start node and slot id. */
4315 if (n == NULL) {
4316 if (i == CLUSTER_SLOTS) break;
4317 n = g_pserver->cluster->slots[i];
4318 start = i;
4319 continue;
4320 }
4321
4322 /* Generate slots info when occur different node with start
4323 * or end of slot. */
4324 if (i == CLUSTER_SLOTS || n != g_pserver->cluster->slots[i]) {
4325 if (!(n->flags & filter)) {
4326 if (n->slots_info == NULL) n->slots_info = sdsempty();
4327 if (start == i-1) {
4328 n->slots_info = sdscatfmt(n->slots_info," %i",start);
4329 } else {
4330 n->slots_info = sdscatfmt(n->slots_info," %i-%i",start,i-1);
4331 }
4332 }
4333 if (i == CLUSTER_SLOTS) break;
4334 n = g_pserver->cluster->slots[i];
4335 start = i;
4336 }
4337 }
4338}
4339
4340/* Generate a csv-alike representation of the nodes we are aware of,
4341 * 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