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

Function clusterManagerShowClusterInfo

src/redis-cli.c:2958–3005  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2956}
2957
2958static void clusterManagerShowClusterInfo(void) {
2959 int masters = 0;
2960 int keys = 0;
2961 listIter li;
2962 listNode *ln;
2963 listRewind(cluster_manager.nodes, &li);
2964 while ((ln = listNext(&li)) != NULL) {
2965 clusterManagerNode *node = ln->value;
2966 if (!(node->flags & CLUSTER_MANAGER_FLAG_SLAVE)) {
2967 if (!node->name) continue;
2968 int replicas = 0;
2969 int dbsize = -1;
2970 char name[9];
2971 memcpy(name, node->name, 8);
2972 name[8] = '\0';
2973 listIter ri;
2974 listNode *rn;
2975 listRewind(cluster_manager.nodes, &ri);
2976 while ((rn = listNext(&ri)) != NULL) {
2977 clusterManagerNode *n = rn->value;
2978 if (n == node || !(n->flags & CLUSTER_MANAGER_FLAG_SLAVE))
2979 continue;
2980 if (n->replicate && !strcmp(n->replicate, node->name))
2981 replicas++;
2982 }
2983 redisReply *reply = CLUSTER_MANAGER_COMMAND(node, "DBSIZE");
2984 if (reply != NULL && reply->type == REDIS_REPLY_INTEGER)
2985 dbsize = reply->integer;
2986 if (dbsize < 0) {
2987 char *err = "";
2988 if (reply != NULL && reply->type == REDIS_REPLY_ERROR)
2989 err = reply->str;
2990 CLUSTER_MANAGER_PRINT_REPLY_ERROR(node, err);
2991 if (reply != NULL) freeReplyObject(reply);
2992 return;
2993 };
2994 if (reply != NULL) freeReplyObject(reply);
2995 printf("%s:%d (%s...) -> %d keys | %d slots | %d slaves.\n",
2996 node->ip, node->port, name, dbsize,
2997 node->slots_count, replicas);
2998 masters++;
2999 keys += dbsize;
3000 }
3001 }
3002 clusterManagerLogOk("[OK] %d keys in %d masters.\n", keys, masters);
3003 float keys_per_slot = keys / (float) CLUSTER_MANAGER_SLOTS;
3004 printf("%.2f keys per slot on average.\n", keys_per_slot);
3005}
3006
3007/* Flush dirty slots configuration of the node by calling CLUSTER ADDSLOTS */
3008static int clusterManagerAddSlots(clusterManagerNode *node, char**err)

Callers 2

Calls 3

listRewindFunction · 0.85
listNextFunction · 0.85
freeReplyObjectFunction · 0.85

Tested by

no test coverage detected