summaryrefslogtreecommitdiff
path: root/src/cluster.c
diff options
context:
space:
mode:
authoraradz44 <112960166+aradz44@users.noreply.github.com>2023-01-02 09:41:54 +0200
committerGitHub <noreply@github.com>2023-01-01 23:41:54 -0800
commitd2d6bc18ebc63265c2ee55ed79ab6ad2044b3bc3 (patch)
tree95e4799e0f5e8dc6f9a95fa14281c11475654a11 /src/cluster.c
parent383d902ce68131cf40d6122ce09e305e672e8555 (diff)
downloadredis-d2d6bc18ebc63265c2ee55ed79ab6ad2044b3bc3.tar.gz
Add cluster info and cluster nodes to bug report (#11656)
Adds the CLUSTER INFO and CLUSTER NODES to the bug report string. Co-authored-by: Madelyn Olson <34459052+madolson@users.noreply.github.com>
Diffstat (limited to 'src/cluster.c')
-rw-r--r--src/cluster.c153
1 files changed, 80 insertions, 73 deletions
diff --git a/src/cluster.c b/src/cluster.c
index 10be81930..71c45d742 100644
--- a/src/cluster.c
+++ b/src/cluster.c
@@ -56,7 +56,6 @@ void clusterSendFail(char *nodename);
void clusterSendFailoverAuthIfNeeded(clusterNode *node, clusterMsg *request);
void clusterUpdateState(void);
int clusterNodeGetSlotBit(clusterNode *n, int slot);
-sds clusterGenNodesDescription(int filter, int use_pport);
list *clusterGetNodesInMyShard(clusterNode *node);
int clusterNodeAddSlave(clusterNode *master, clusterNode *slave);
int clusterAddSlot(clusterNode *n, int slot);
@@ -5527,6 +5526,84 @@ void clusterReplyMultiBulkSlots(client * c) {
setDeferredArrayLen(c, slot_replylen, num_masters);
}
+sds genClusterInfoString() {
+ sds info = sdsempty();
+ char *statestr[] = {"ok","fail"};
+ int slots_assigned = 0, slots_ok = 0, slots_pfail = 0, slots_fail = 0;
+ uint64_t myepoch;
+ int j;
+
+ for (j = 0; j < CLUSTER_SLOTS; j++) {
+ clusterNode *n = server.cluster->slots[j];
+
+ if (n == NULL) continue;
+ slots_assigned++;
+ if (nodeFailed(n)) {
+ slots_fail++;
+ } else if (nodeTimedOut(n)) {
+ slots_pfail++;
+ } else {
+ slots_ok++;
+ }
+ }
+
+ myepoch = (nodeIsSlave(myself) && myself->slaveof) ?
+ myself->slaveof->configEpoch : myself->configEpoch;
+
+ info = sdscatprintf(info,
+ "cluster_state:%s\r\n"
+ "cluster_slots_assigned:%d\r\n"
+ "cluster_slots_ok:%d\r\n"
+ "cluster_slots_pfail:%d\r\n"
+ "cluster_slots_fail:%d\r\n"
+ "cluster_known_nodes:%lu\r\n"
+ "cluster_size:%d\r\n"
+ "cluster_current_epoch:%llu\r\n"
+ "cluster_my_epoch:%llu\r\n"
+ , statestr[server.cluster->state],
+ slots_assigned,
+ slots_ok,
+ slots_pfail,
+ slots_fail,
+ dictSize(server.cluster->nodes),
+ server.cluster->size,
+ (unsigned long long) server.cluster->currentEpoch,
+ (unsigned long long) myepoch
+ );
+
+ /* Show stats about messages sent and received. */
+ long long tot_msg_sent = 0;
+ long long tot_msg_received = 0;
+
+ for (int i = 0; i < CLUSTERMSG_TYPE_COUNT; i++) {
+ if (server.cluster->stats_bus_messages_sent[i] == 0) continue;
+ tot_msg_sent += server.cluster->stats_bus_messages_sent[i];
+ info = sdscatprintf(info,
+ "cluster_stats_messages_%s_sent:%lld\r\n",
+ clusterGetMessageTypeString(i),
+ server.cluster->stats_bus_messages_sent[i]);
+ }
+ info = sdscatprintf(info,
+ "cluster_stats_messages_sent:%lld\r\n", tot_msg_sent);
+
+ for (int i = 0; i < CLUSTERMSG_TYPE_COUNT; i++) {
+ if (server.cluster->stats_bus_messages_received[i] == 0) continue;
+ tot_msg_received += server.cluster->stats_bus_messages_received[i];
+ info = sdscatprintf(info,
+ "cluster_stats_messages_%s_received:%lld\r\n",
+ clusterGetMessageTypeString(i),
+ server.cluster->stats_bus_messages_received[i]);
+ }
+ info = sdscatprintf(info,
+ "cluster_stats_messages_received:%lld\r\n", tot_msg_received);
+
+ info = sdscatprintf(info,
+ "total_cluster_links_buffer_limit_exceeded:%llu\r\n",
+ server.cluster->stat_cluster_links_buffer_limit_exceeded);
+
+ return info;
+}
+
void clusterCommand(client *c) {
if (server.cluster_enabled == 0) {
addReplyError(c,"This instance has cluster support disabled");
@@ -5859,78 +5936,8 @@ NULL
addReplySds(c,reply);
} else if (!strcasecmp(c->argv[1]->ptr,"info") && c->argc == 2) {
/* CLUSTER INFO */
- char *statestr[] = {"ok","fail"};
- int slots_assigned = 0, slots_ok = 0, slots_pfail = 0, slots_fail = 0;
- uint64_t myepoch;
- int j;
-
- for (j = 0; j < CLUSTER_SLOTS; j++) {
- clusterNode *n = server.cluster->slots[j];
-
- if (n == NULL) continue;
- slots_assigned++;
- if (nodeFailed(n)) {
- slots_fail++;
- } else if (nodeTimedOut(n)) {
- slots_pfail++;
- } else {
- slots_ok++;
- }
- }
-
- myepoch = (nodeIsSlave(myself) && myself->slaveof) ?
- myself->slaveof->configEpoch : myself->configEpoch;
-
- sds info = sdscatprintf(sdsempty(),
- "cluster_state:%s\r\n"
- "cluster_slots_assigned:%d\r\n"
- "cluster_slots_ok:%d\r\n"
- "cluster_slots_pfail:%d\r\n"
- "cluster_slots_fail:%d\r\n"
- "cluster_known_nodes:%lu\r\n"
- "cluster_size:%d\r\n"
- "cluster_current_epoch:%llu\r\n"
- "cluster_my_epoch:%llu\r\n"
- , statestr[server.cluster->state],
- slots_assigned,
- slots_ok,
- slots_pfail,
- slots_fail,
- dictSize(server.cluster->nodes),
- server.cluster->size,
- (unsigned long long) server.cluster->currentEpoch,
- (unsigned long long) myepoch
- );
-
- /* Show stats about messages sent and received. */
- long long tot_msg_sent = 0;
- long long tot_msg_received = 0;
-
- for (int i = 0; i < CLUSTERMSG_TYPE_COUNT; i++) {
- if (server.cluster->stats_bus_messages_sent[i] == 0) continue;
- tot_msg_sent += server.cluster->stats_bus_messages_sent[i];
- info = sdscatprintf(info,
- "cluster_stats_messages_%s_sent:%lld\r\n",
- clusterGetMessageTypeString(i),
- server.cluster->stats_bus_messages_sent[i]);
- }
- info = sdscatprintf(info,
- "cluster_stats_messages_sent:%lld\r\n", tot_msg_sent);
-
- for (int i = 0; i < CLUSTERMSG_TYPE_COUNT; i++) {
- if (server.cluster->stats_bus_messages_received[i] == 0) continue;
- tot_msg_received += server.cluster->stats_bus_messages_received[i];
- info = sdscatprintf(info,
- "cluster_stats_messages_%s_received:%lld\r\n",
- clusterGetMessageTypeString(i),
- server.cluster->stats_bus_messages_received[i]);
- }
- info = sdscatprintf(info,
- "cluster_stats_messages_received:%lld\r\n", tot_msg_received);
-
- info = sdscatprintf(info,
- "total_cluster_links_buffer_limit_exceeded:%llu\r\n",
- server.cluster->stat_cluster_links_buffer_limit_exceeded);
+
+ sds info = genClusterInfoString();
/* Produce the reply protocol. */
addReplyVerbatim(c,info,sdslen(info),"txt");