You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ea...@apache.org on 2019/06/04 06:04:38 UTC

[incubator-iotdb] branch cluster updated: sort ip for Status

This is an automated email from the ASF dual-hosted git repository.

east pushed a commit to branch cluster
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git


The following commit(s) were added to refs/heads/cluster by this push:
     new 873724f  sort ip for Status
     new 6e4b783  Merge remote-tracking branch 'origin/cluster' into cluster
873724f is described below

commit 873724fb1e565038ff0e585f44803cb28f6af235
Author: mdf369 <95...@qq.com>
AuthorDate: Tue Jun 4 14:04:12 2019 +0800

    sort ip for Status
---
 .../org/apache/iotdb/cluster/utils/RaftUtils.java  | 30 ++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/utils/RaftUtils.java b/cluster/src/main/java/org/apache/iotdb/cluster/utils/RaftUtils.java
index 1e1908d..f8546b7 100644
--- a/cluster/src/main/java/org/apache/iotdb/cluster/utils/RaftUtils.java
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/utils/RaftUtils.java
@@ -40,6 +40,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 import java.util.SortedMap;
+import java.util.TreeMap;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ThreadLocalRandom;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -758,12 +759,37 @@ public class RaftUtils {
    */
   public static Map<String, Boolean> getStatusMapForCluster() {
     PeerId[] peerIds = RaftUtils.convertStringArrayToPeerIdArray(config.getNodes());
-    Map<String, Boolean> res = new HashMap<>();
+    SortedMap<String, Boolean> treeMap = new TreeMap<>(new Comparator<String>() {
+      @Override
+      public int compare(String o1, String o2) {
+        int[] nums1 = convertIPToNums(o1);
+        int[] nums2 = convertIPToNums(o2);
+        for (int i = 0; i < Math.min(nums1.length, nums2.length); i++) {
+          if (nums1[i] == nums2[i]) {
+            continue;
+          } else {
+            return ((Integer) nums1[i]).compareTo(nums2[i]);
+          }
+        }
+        return 0;
+      }
+
+      private int[] convertIPToNums(String ip) {
+        String[] ss = ip.split("\\.");
+        int[] nums = new int[ss.length];
+        for (int i = 0; i < nums.length; i++) {
+          nums[i] = Integer.parseInt(ss[i]);
+        }
+        return nums;
+      }
+    });
     for (int i = 0; i < peerIds.length; i++) {
       PeerId peerId = peerIds[i];
-      res.put(peerId.getIp(), getStatusOfNode(peerId));
+      treeMap.put(peerId.getIp(), getStatusOfNode(peerId));
     }
 
+    Map<String, Boolean> res = new LinkedHashMap<>();
+    treeMap.forEach((ip, status) -> res.put(ip, status));
     return res;
   }