diff options
-rw-r--r-- | src/cluster.c | 153 | ||||
-rw-r--r-- | src/cluster.h | 2 | ||||
-rw-r--r-- | src/debug.c | 13 |
3 files changed, 95 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"); diff --git a/src/cluster.h b/src/cluster.h index 4f1f9bf87..4c93dbc8d 100644 --- a/src/cluster.h +++ b/src/cluster.h @@ -419,5 +419,7 @@ void slotToChannelAdd(sds channel); void slotToChannelDel(sds channel); void clusterUpdateMyselfHostname(void); void clusterUpdateMyselfAnnouncedPorts(void); +sds clusterGenNodesDescription(int filter, int use_pport); +sds genClusterInfoString(); #endif /* __CLUSTER_H */ diff --git a/src/debug.c b/src/debug.c index 43de7d2db..c9495e5d8 100644 --- a/src/debug.c +++ b/src/debug.c @@ -35,6 +35,7 @@ #include "bio.h" #include "quicklist.h" #include "fpconv_dtoa.h" +#include "cluster.h" #include <arpa/inet.h> #include <signal.h> @@ -1763,6 +1764,15 @@ void logStackTrace(void *eip, int uplevel) { #endif /* HAVE_BACKTRACE */ +sds genClusterDebugString(sds infostring) { + infostring = sdscatprintf(infostring, "\r\n# Cluster info\r\n"); + infostring = sdscatsds(infostring, genClusterInfoString()); + infostring = sdscatprintf(infostring, "\n------ CLUSTER NODES OUTPUT ------\n"); + infostring = sdscatsds(infostring, clusterGenNodesDescription(0, 0)); + + return infostring; +} + /* Log global server info */ void logServerInfo(void) { sds infostring, clients; @@ -1772,6 +1782,9 @@ void logServerInfo(void) { argv[0] = createStringObject("all", strlen("all")); dict *section_dict = genInfoSectionDict(argv, 1, NULL, &all, &everything); infostring = genRedisInfoString(section_dict, all, everything); + if (server.cluster_enabled){ + infostring = genClusterDebugString(infostring); + } serverLogRaw(LL_WARNING|LL_RAW, infostring); serverLogRaw(LL_WARNING|LL_RAW, "\n------ CLIENT LIST OUTPUT ------\n"); clients = getAllClientsInfoString(-1); |