git-hulk commented on code in PR #1219:
URL: 
https://github.com/apache/incubator-kvrocks/pull/1219#discussion_r1064622540


##########
src/cluster/cluster.cc:
##########
@@ -487,8 +490,46 @@ Status Cluster::GetClusterNodes(std::string *nodes_str) {
 }
 
 std::string Cluster::GenNodesDescription() {
-  // Generate slots info firstly
+  UpdateSlotsInfo();
+
+  std::string nodes_desc;
+  for (const auto &item : nodes_) {
+    const std::shared_ptr<ClusterNode> n = item.second;
+
+    std::string node_str;
+    // ID, host, port
+    node_str.append(n->id_ + " ");
+    node_str.append(fmt::format("{}:{}@{} ", n->host_, n->port_, n->port_ + 
kClusterPortIncr));
+
+    // Flags
+    if (n->id_ == myid_) node_str.append("myself,");
+    if (n->role_ == kClusterMaster) {
+      node_str.append("master - ");
+    } else {
+      node_str.append("slave " + n->master_id_ + " ");
+    }
+
+    // Ping sent, pong received, config epoch, link status
+    auto now = Util::GetTimeStampMS();
+    node_str.append(fmt::format("{} {} {} connected", now - 1, now, version_));
+
+    if (n->role_ == kClusterMaster && n->slots_info_.size() > 0) {
+      node_str.append(" " + n->slots_info_);
+    }
+
+    nodes_desc.append(node_str + "\n");
+  }
+  return nodes_desc;
+}
+
+void Cluster::UpdateSlotsInfo() {
   int start = -1;
+  // reset the previous slots info
+  for (const auto &item : nodes_) {
+    const std::shared_ptr<ClusterNode> n = item.second;

Review Comment:
   Yes, can do it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to