Unverified Commit ac6bc5d1 authored by Tyler Bream (Event pipeline)'s avatar Tyler Bream (Event pipeline) Committed by GitHub
Browse files

redis-cli: Fix print of keys per cluster host when over int max (#11698)

When running cluster info, and the number of keys overflows the integer
value, the summary no longer makes sense. This fixes by using an appropriate
type to handle values over the max int value.
parent 17904780
...@@ -4577,7 +4577,7 @@ static void clusterManagerShowNodes(void) { ...@@ -4577,7 +4577,7 @@ static void clusterManagerShowNodes(void) {
static void clusterManagerShowClusterInfo(void) { static void clusterManagerShowClusterInfo(void) {
int masters = 0; int masters = 0;
int keys = 0; long long keys = 0;
listIter li; listIter li;
listNode *ln; listNode *ln;
listRewind(cluster_manager.nodes, &li); listRewind(cluster_manager.nodes, &li);
...@@ -4586,7 +4586,7 @@ static void clusterManagerShowClusterInfo(void) { ...@@ -4586,7 +4586,7 @@ static void clusterManagerShowClusterInfo(void) {
if (!(node->flags & CLUSTER_MANAGER_FLAG_SLAVE)) { if (!(node->flags & CLUSTER_MANAGER_FLAG_SLAVE)) {
if (!node->name) continue; if (!node->name) continue;
int replicas = 0; int replicas = 0;
int dbsize = -1; long long dbsize = -1;
char name[9]; char name[9];
memcpy(name, node->name, 8); memcpy(name, node->name, 8);
name[8] = '\0'; name[8] = '\0';
...@@ -4612,14 +4612,14 @@ static void clusterManagerShowClusterInfo(void) { ...@@ -4612,14 +4612,14 @@ static void clusterManagerShowClusterInfo(void) {
return; return;
}; };
if (reply != NULL) freeReplyObject(reply); if (reply != NULL) freeReplyObject(reply);
printf("%s:%d (%s...) -> %d keys | %d slots | %d slaves.\n", printf("%s:%d (%s...) -> %lld keys | %d slots | %d slaves.\n",
node->ip, node->port, name, dbsize, node->ip, node->port, name, dbsize,
node->slots_count, replicas); node->slots_count, replicas);
masters++; masters++;
keys += dbsize; keys += dbsize;
} }
} }
clusterManagerLogOk("[OK] %d keys in %d masters.\n", keys, masters); clusterManagerLogOk("[OK] %lld keys in %d masters.\n", keys, masters);
float keys_per_slot = keys / (float) CLUSTER_MANAGER_SLOTS; float keys_per_slot = keys / (float) CLUSTER_MANAGER_SLOTS;
printf("%.2f keys per slot on average.\n", keys_per_slot); printf("%.2f keys per slot on average.\n", keys_per_slot);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment