You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/08/10 05:22:32 UTC

[GitHub] [iotdb] CRZbulabula commented on a diff in pull request #6923: [IOTDB-4038] Add the leader metrics to the cluster

CRZbulabula commented on code in PR #6923:
URL: https://github.com/apache/iotdb/pull/6923#discussion_r942027241


##########
confignode/src/main/java/org/apache/iotdb/confignode/manager/load/LoadManager.java:
##########
@@ -590,7 +591,54 @@ public int getUnknownDataNodesNum() {
     return allDataNodes.size();
   }
 
-  public void addMetrics() {
+  /**
+   * Get the LeaderCount of each DataNodeId
+   *
+   * @return Map<DataNodeId, LeaderCount>
+   */
+  public Map<Integer, Integer> getLeadershipCountByDatanode() {
+    Map<Integer, Integer> idToCountMap = new ConcurrentHashMap<>();

Review Comment:
   Add annotation to this variable like:
   
   `// Map<DataNodeId, leaderCount>`
   
   By the way, you can use Map<Integer, AtomicInteger> and map.computeIfAbsent to simplify the following code logic



##########
confignode/src/main/java/org/apache/iotdb/confignode/manager/load/LoadManager.java:
##########
@@ -590,7 +591,54 @@ public int getUnknownDataNodesNum() {
     return allDataNodes.size();
   }
 
-  public void addMetrics() {
+  /**
+   * Get the LeaderCount of each DataNodeId
+   *
+   * @return Map<DataNodeId, LeaderCount>
+   */
+  public Map<Integer, Integer> getLeadershipCountByDatanode() {
+    Map<Integer, Integer> idToCountMap = new ConcurrentHashMap<>();
+
+    regionGroupCacheMap.forEach(
+        (consensusGroupId, regionGroupCache) -> {
+          Integer count = idToCountMap.get(regionGroupCache.getLeaderDataNodeId());
+          if (count == null) {
+            idToCountMap.put(regionGroupCache.getLeaderDataNodeId(), 1);
+          } else {
+            idToCountMap.put(regionGroupCache.getLeaderDataNodeId(), count + 1);
+          }

Review Comment:
   Better use getAllLeadership interface to complete these code~



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org