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

Function clusterManagerShowClusterInfo

app/redis-6.2.6/src/redis-cli.c:3347–3394  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3345}
3346
3347static void clusterManagerShowClusterInfo(void) {
3348 int masters = 0;
3349 int keys = 0;
3350 listIter li;
3351 listNode *ln;
3352 listRewind(cluster_manager.nodes, &li);
3353 while ((ln = listNext(&li)) != NULL) {
3354 clusterManagerNode *node = ln->value;
3355 if (!(node->flags & CLUSTER_MANAGER_FLAG_SLAVE)) {
3356 if (!node->name) continue;
3357 int replicas = 0;
3358 int dbsize = -1;
3359 char name[9];
3360 memcpy(name, node->name, 8);
3361 name[8] = '\0';
3362 listIter ri;
3363 listNode *rn;
3364 listRewind(cluster_manager.nodes, &ri);
3365 while ((rn = listNext(&ri)) != NULL) {
3366 clusterManagerNode *n = rn->value;
3367 if (n == node || !(n->flags & CLUSTER_MANAGER_FLAG_SLAVE))
3368 continue;
3369 if (n->replicate && !strcmp(n->replicate, node->name))
3370 replicas++;
3371 }
3372 redisReply *reply = CLUSTER_MANAGER_COMMAND(node, "DBSIZE");
3373 if (reply != NULL && reply->type == REDIS_REPLY_INTEGER)
3374 dbsize = reply->integer;
3375 if (dbsize < 0) {
3376 char *err = "";
3377 if (reply != NULL && reply->type == REDIS_REPLY_ERROR)
3378 err = reply->str;
3379 CLUSTER_MANAGER_PRINT_REPLY_ERROR(node, err);
3380 if (reply != NULL) freeReplyObject(reply);
3381 return;
3382 };
3383 if (reply != NULL) freeReplyObject(reply);
3384 printf("%s:%d (%s...) -> %d keys | %d slots | %d slaves.\n",
3385 node->ip, node->port, name, dbsize,
3386 node->slots_count, replicas);
3387 masters++;
3388 keys += dbsize;
3389 }
3390 }
3391 clusterManagerLogOk("[OK] %d keys in %d masters.\n", keys, masters);
3392 float keys_per_slot = keys / (float) CLUSTER_MANAGER_SLOTS;
3393 printf("%.2f keys per slot on average.\n", keys_per_slot);
3394}
3395
3396/* Flush dirty slots configuration of the node by calling CLUSTER ADDSLOTS */
3397static int clusterManagerAddSlots(clusterManagerNode *node, char**err)

Callers 2

Calls 6

listRewindFunction · 0.85
listNextFunction · 0.85
strcmpFunction · 0.85
freeReplyObjectFunction · 0.85
memcpyFunction · 0.50
printfFunction · 0.50

Tested by

no test coverage detected