helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l...@apache.org
Subject [32/38] helix git commit: Refactor/renames the instances releated methods in ClusterDataCache.
Date Wed, 08 Feb 2017 18:00:07 GMT
Refactor/renames the instances releated methods in ClusterDataCache.


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

Branch: refs/heads/helix-0.6.x
Commit: fc6009feca610756dd134eb070d07b0c4918c1ba
Parents: c5e12b1
Author: Lei Xia <lxia@linkedin.com>
Authored: Fri Sep 23 08:26:50 2016 -0700
Committer: Lei Xia <lxia@linkedin.com>
Committed: Wed Feb 8 09:56:40 2017 -0800

----------------------------------------------------------------------
 .../rebalancer/DelayedAutoRebalancer.java       |  2 +-
 .../controller/stages/ClusterDataCache.java     | 40 ++++++++------------
 2 files changed, 17 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/fc6009fe/helix-core/src/main/java/org/apache/helix/controller/rebalancer/DelayedAutoRebalancer.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/DelayedAutoRebalancer.java
b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/DelayedAutoRebalancer.java
index d1718fc..1f1d94f 100644
--- a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/DelayedAutoRebalancer.java
+++ b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/DelayedAutoRebalancer.java
@@ -66,7 +66,7 @@ public class DelayedAutoRebalancer extends AbstractRebalancer {
     String instanceTag = currentIdealState.getInstanceGroupTag();
     if (instanceTag != null) {
       liveNodes = clusterData.getEnabledLiveInstancesWithTag(instanceTag);
-      allNodes = clusterData.getAllInstancesWithTag(instanceTag);
+      allNodes = clusterData.getInstancesWithTag(instanceTag);
 
       if (!liveNodes.isEmpty()) {
         // live nodes exist that have this tag

http://git-wip-us.apache.org/repos/asf/helix/blob/fc6009fe/helix-core/src/main/java/org/apache/helix/controller/stages/ClusterDataCache.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/controller/stages/ClusterDataCache.java
b/helix-core/src/main/java/org/apache/helix/controller/stages/ClusterDataCache.java
index 648fd22..9cccc64 100644
--- a/helix-core/src/main/java/org/apache/helix/controller/stages/ClusterDataCache.java
+++ b/helix-core/src/main/java/org/apache/helix/controller/stages/ClusterDataCache.java
@@ -311,11 +311,15 @@ public class ClusterDataCache {
   }
 
   /**
-  * Return all the live nodes that are enabled
-  * @return A new set contains live instance name and that are marked enabled
-  */
+   * Return all the live nodes that are enabled
+   *
+   * @return A new set contains live instance name and that are marked enabled
+   */
   public Set<String> getEnabledLiveInstances() {
-    return getAllEnabledInstances(null);
+    Set<String> enabledLiveInstances = new HashSet<String>(getLiveInstances().keySet());
+    enabledLiveInstances.removeAll(getDisabledInstances());
+
+    return enabledLiveInstances;
   }
 
   /**
@@ -338,25 +342,12 @@ public class ClusterDataCache {
    * tag.
    */
   public Set<String> getEnabledLiveInstancesWithTag(String instanceTag) {
-    return getAllEnabledInstances(instanceTag);
-  }
-
-  private Set<String> getAllEnabledInstances(String instanceTag) {
-    Set<String> enabledTagInstances = new HashSet<String>();
-    for (String instance : _liveInstanceMap.keySet()) {
-      InstanceConfig instanceConfig = _instanceConfigMap.get(instance);
+    Set<String> enabledLiveInstancesWithTag = new HashSet<String>(getLiveInstances().keySet());
+    Set<String> instancesWithTag = getInstancesWithTag(instanceTag);
+    enabledLiveInstancesWithTag.retainAll(instancesWithTag);
+    enabledLiveInstancesWithTag.removeAll(getDisabledInstances());
 
-      // Check instance is enabled
-      if (instanceConfig != null && instanceConfig.getInstanceEnabled()) {
-        // Check whether it has instance group or not
-        // If it has instance group, check whether it belongs to that group or not
-        if (instanceTag == null || instanceConfig.containsTag(instanceTag)) {
-          enabledTagInstances.add(instance);
-        }
-      }
-    }
-
-    return enabledTagInstances;
+    return enabledLiveInstancesWithTag;
   }
 
   /**
@@ -364,7 +355,7 @@ public class ClusterDataCache {
    *
    * @param instanceTag The instance group tag.
    */
-  public Set<String> getAllInstancesWithTag(String instanceTag) {
+  public Set<String> getInstancesWithTag(String instanceTag) {
     Set<String> taggedInstances = new HashSet<String>();
     for (String instance : _instanceConfigMap.keySet()) {
       InstanceConfig instanceConfig = _instanceConfigMap.get(instance);
@@ -510,13 +501,14 @@ public class ClusterDataCache {
 
   /**
    * This method allows one to fetch the set of nodes that are disabled
+   *
    * @return
    */
   public Set<String> getDisabledInstances() {
     Set<String> disabledInstancesSet = new HashSet<String>();
     for (String instance : _instanceConfigMap.keySet()) {
       InstanceConfig config = _instanceConfigMap.get(instance);
-      if (config.getInstanceEnabled() == false) {
+      if (!config.getInstanceEnabled()) {
         disabledInstancesSet.add(instance);
       }
     }


Mime
View raw message