helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject helix git commit: [HELIX-699] Compare InstanceConfigs using their IDs in RoutingTable
Date Thu, 19 Apr 2018 21:13:54 GMT
Repository: helix
Updated Branches:
  refs/heads/master 0e4163f18 -> 90ef589aa


[HELIX-699] Compare InstanceConfigs using their IDs in RoutingTable

A possible race condition was causing a NPE on InstanceConfig.getHostName(). Instead of comparing
hostnames and ports, we compare IDs, which are supposed to be concatenation of instance name,
hostname, and port anyways and should always be set.


Project: http://git-wip-us.apache.org/repos/asf/helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/helix/commit/90ef589a
Tree: http://git-wip-us.apache.org/repos/asf/helix/tree/90ef589a
Diff: http://git-wip-us.apache.org/repos/asf/helix/diff/90ef589a

Branch: refs/heads/master
Commit: 90ef589aa47ef1726356ce5ea37e12d27372b342
Parents: 0e4163f
Author: Hunter Lee <narendly@gmail.com>
Authored: Thu Apr 19 13:47:28 2018 -0700
Committer: Hunter Lee <narendly@gmail.com>
Committed: Thu Apr 19 14:10:50 2018 -0700

----------------------------------------------------------------------
 .../org/apache/helix/spectator/RoutingTable.java   | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/90ef589a/helix-core/src/main/java/org/apache/helix/spectator/RoutingTable.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/spectator/RoutingTable.java b/helix-core/src/main/java/org/apache/helix/spectator/RoutingTable.java
index b705dff..46cf471 100644
--- a/helix-core/src/main/java/org/apache/helix/spectator/RoutingTable.java
+++ b/helix-core/src/main/java/org/apache/helix/spectator/RoutingTable.java
@@ -464,23 +464,18 @@ class RoutingTable {
   private static Comparator<InstanceConfig> INSTANCE_CONFIG_COMPARATOR =
       new Comparator<InstanceConfig>() {
         @Override
-        public int compare(InstanceConfig o1, InstanceConfig o2) {
-          if (o1 == o2) {
+        public int compare(InstanceConfig config1, InstanceConfig config2) {
+          if (config1 == config2) {
             return 0;
           }
-          if (o1 == null) {
+          if (config1 == null) {
             return -1;
           }
-          if (o2 == null) {
+          if (config2 == null) {
             return 1;
           }
-
-          int compareTo = o1.getHostName().compareTo(o2.getHostName());
-          if (compareTo == 0) {
-            return o1.getPort().compareTo(o2.getPort());
-          }
-
-          return compareTo;
+          // IDs for InstanceConfigs are a concatenation of instance name, host, and port.
+          return config1.getId().compareTo(config2.getId());
         }
       };
 }


Mime
View raw message