You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by jx...@apache.org on 2018/07/10 18:15:57 UTC

helix git commit: [HELIX-721] Clean up code in ClusterDataCache

Repository: helix
Updated Branches:
  refs/heads/master 034424cc4 -> 698532598


[HELIX-721] Clean up code in ClusterDataCache


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

Branch: refs/heads/master
Commit: 698532598f2cb10d0eb1c67f3961cdd6219db965
Parents: 034424c
Author: Hunter Lee <na...@gmail.com>
Authored: Mon Jul 9 18:27:15 2018 -0700
Committer: Hunter Lee <na...@gmail.com>
Committed: Mon Jul 9 18:27:15 2018 -0700

----------------------------------------------------------------------
 .../helix/common/caches/TaskDataCache.java      | 39 ++++++-----------
 .../controller/stages/ClusterDataCache.java     | 46 ++++++++++----------
 2 files changed, 37 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/69853259/helix-core/src/main/java/org/apache/helix/common/caches/TaskDataCache.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/common/caches/TaskDataCache.java b/helix-core/src/main/java/org/apache/helix/common/caches/TaskDataCache.java
index 2dbb4f8..bc01d39 100644
--- a/helix-core/src/main/java/org/apache/helix/common/caches/TaskDataCache.java
+++ b/helix-core/src/main/java/org/apache/helix/common/caches/TaskDataCache.java
@@ -29,6 +29,7 @@ import org.apache.helix.HelixDataAccessor;
 import org.apache.helix.PropertyType;
 import org.apache.helix.ZNRecord;
 import org.apache.helix.model.ResourceConfig;
+import org.apache.helix.task.AssignableInstanceManager;
 import org.apache.helix.task.JobConfig;
 import org.apache.helix.task.JobContext;
 import org.apache.helix.task.TaskConstants;
@@ -44,21 +45,18 @@ public class TaskDataCache {
   private static final Logger LOG = LoggerFactory.getLogger(TaskDataCache.class.getName());
   private static final String NAME = "NAME";
 
+  private String _clusterName;
   private Map<String, JobConfig> _jobConfigMap = new HashMap<>();
   private Map<String, WorkflowConfig> _workflowConfigMap = new HashMap<>();
   private Map<String, ZNRecord> _contextMap = new HashMap<>();
 
-  private String _clusterName;
-
   public TaskDataCache(String clusterName) {
     _clusterName = clusterName;
   }
 
   /**
    * This refreshes the cluster data by re-fetching the data from zookeeper in an efficient way
-   *
    * @param accessor
-   *
    * @return
    */
   public synchronized boolean refresh(HelixDataAccessor accessor,
@@ -112,14 +110,13 @@ public class TaskDataCache {
     }
 
     if (LOG.isDebugEnabled()) {
-      LOG.debug("# of workflow/job context read from zk: " + _contextMap.size() + ". Take " + (
-          System.currentTimeMillis() - start) + " ms");
+      LOG.debug("# of workflow/job context read from zk: " + _contextMap.size() + ". Take "
+          + (System.currentTimeMillis() - start) + " ms");
     }
   }
 
   /**
    * Returns job config map
-   *
    * @return
    */
   public Map<String, JobConfig> getJobConfigMap() {
@@ -128,9 +125,7 @@ public class TaskDataCache {
 
   /**
    * Returns job config
-   *
    * @param resource
-   *
    * @return
    */
   public JobConfig getJobConfig(String resource) {
@@ -139,7 +134,6 @@ public class TaskDataCache {
 
   /**
    * Returns workflow config map
-   *
    * @return
    */
   public Map<String, WorkflowConfig> getWorkflowConfigMap() {
@@ -148,9 +142,7 @@ public class TaskDataCache {
 
   /**
    * Returns workflow config
-   *
    * @param resource
-   *
    * @return
    */
   public WorkflowConfig getWorkflowConfig(String resource) {
@@ -159,9 +151,7 @@ public class TaskDataCache {
 
   /**
    * Return the JobContext by resource name
-   *
    * @param resourceName
-   *
    * @return
    */
   public JobContext getJobContext(String resourceName) {
@@ -173,9 +163,7 @@ public class TaskDataCache {
 
   /**
    * Return the WorkflowContext by resource name
-   *
    * @param resourceName
-   *
    * @return
    */
   public WorkflowContext getWorkflowContext(String resourceName) {
@@ -213,20 +201,19 @@ public class TaskDataCache {
 
   /**
    * Return map of WorkflowContexts or JobContexts
-   *
    * @return
    */
   public Map<String, ZNRecord> getContexts() {
     return _contextMap;
   }
 
-  @Override public String toString() {
-    return "TaskDataCache{" +
-        "_jobConfigMap=" + _jobConfigMap +
-        ", _workflowConfigMap=" + _workflowConfigMap +
-        ", _contextMap=" + _contextMap +
-        ", _clusterName='" + _clusterName + '\'' +
-        '}';
+  @Override
+  public String toString() {
+    return "TaskDataCache{"
+        + "_jobConfigMap=" + _jobConfigMap
+        + ", _workflowConfigMap=" + _workflowConfigMap
+        + ", _contextMap=" + _contextMap
+        + ", _clusterName='" + _clusterName
+        + '\'' + '}';
   }
-}
-
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/helix/blob/69853259/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 16b8633..4354818 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
@@ -69,7 +69,6 @@ import static org.apache.helix.HelixConstants.ChangeType;
  */
 public class ClusterDataCache {
   private static final Logger LOG = LoggerFactory.getLogger(ClusterDataCache.class.getName());
-  private static final String NAME = "NAME";
 
   private ClusterConfig _clusterConfig;
   private Map<String, LiveInstance> _liveInstanceMap;
@@ -123,7 +122,7 @@ public class ClusterDataCache {
   public ClusterDataCache(String clusterName) {
     _propertyDataChangedMap = new ConcurrentHashMap<>();
     for (ChangeType type : ChangeType.values()) {
-      _propertyDataChangedMap.put(type, Boolean.valueOf(true));
+      _propertyDataChangedMap.put(type, true);
     }
     _clusterName = clusterName;
     _currentStateCache = new CurrentStateCache(_clusterName);
@@ -142,14 +141,14 @@ public class ClusterDataCache {
     Builder keyBuilder = accessor.keyBuilder();
 
     if (_propertyDataChangedMap.get(ChangeType.IDEAL_STATE)) {
-      _propertyDataChangedMap.put(ChangeType.IDEAL_STATE, Boolean.valueOf(false));
+      _propertyDataChangedMap.put(ChangeType.IDEAL_STATE, false);
       clearCachedResourceAssignments();
       _idealStateCacheMap = refreshIdealStates(accessor);
     }
 
     if (_propertyDataChangedMap.get(ChangeType.LIVE_INSTANCE)) {
       long start = System.currentTimeMillis();
-      _propertyDataChangedMap.put(ChangeType.LIVE_INSTANCE, Boolean.valueOf(false));
+      _propertyDataChangedMap.put(ChangeType.LIVE_INSTANCE, false);
       clearCachedResourceAssignments();
       _liveInstanceCacheMap = accessor.getChildValuesMap(keyBuilder.liveInstances(), true);
       _updateInstanceOfflineTime = true;
@@ -158,7 +157,7 @@ public class ClusterDataCache {
     }
 
     if (_propertyDataChangedMap.get(ChangeType.INSTANCE_CONFIG)) {
-      _propertyDataChangedMap.put(ChangeType.INSTANCE_CONFIG, Boolean.valueOf(false));
+      _propertyDataChangedMap.put(ChangeType.INSTANCE_CONFIG, false);
       clearCachedResourceAssignments();
       _instanceConfigCacheMap = accessor.getChildValuesMap(keyBuilder.instanceConfigs(), true);
       if (LOG.isDebugEnabled()) {
@@ -167,18 +166,19 @@ public class ClusterDataCache {
     }
 
     if (_propertyDataChangedMap.get(ChangeType.RESOURCE_CONFIG)) {
-      _propertyDataChangedMap.put(ChangeType.RESOURCE_CONFIG, Boolean.valueOf(false));
+      _propertyDataChangedMap.put(ChangeType.RESOURCE_CONFIG, false);
       clearCachedResourceAssignments();
-      _resourceConfigCacheMap = accessor.getChildValuesMap(accessor.keyBuilder().resourceConfigs(), true);
+      _resourceConfigCacheMap =
+          accessor.getChildValuesMap(accessor.keyBuilder().resourceConfigs(), true);
       if (LOG.isDebugEnabled()) {
         LOG.debug("Reload ResourceConfigs: " + _resourceConfigCacheMap.size());
       }
     }
 
     _idealStateMap = new HashMap<>(_idealStateCacheMap);
-    _liveInstanceMap = new HashMap(_liveInstanceCacheMap);
+    _liveInstanceMap = new HashMap<>(_liveInstanceCacheMap);
     _instanceConfigMap = new ConcurrentHashMap<>(_instanceConfigCacheMap);
-    _resourceConfigMap = new HashMap(_resourceConfigCacheMap);
+    _resourceConfigMap = new HashMap<>(_resourceConfigCacheMap);
 
     if (_updateInstanceOfflineTime) {
       updateOfflineInstanceHistory(accessor);
@@ -207,12 +207,12 @@ public class ClusterDataCache {
     if (_clusterConfig != null) {
       _idealStateRuleMap = _clusterConfig.getIdealStateRules();
     } else {
-      _idealStateRuleMap = new HashMap();
+      _idealStateRuleMap = new HashMap<>();
       LOG.warn("Cluster config is null!");
     }
 
     MaintenanceSignal maintenanceSignal = accessor.getProperty(keyBuilder.maintenance());
-    _isMaintenanceModeEnabled = (maintenanceSignal != null) ? true : false;
+    _isMaintenanceModeEnabled = maintenanceSignal != null;
 
     updateDisabledInstances();
 
@@ -225,9 +225,9 @@ public class ClusterDataCache {
       LOG.debug("# of StateModelDefinition read from zk: " + _stateModelDefMap.size());
       LOG.debug("# of ConstraintMap read from zk: " + _constraintMap.size());
       LOG.debug("LiveInstances: " + _liveInstanceMap.keySet());
-        for (LiveInstance instance : _liveInstanceMap.values()) {
-          LOG.debug("live instance: " + instance.getInstanceName() + " " + instance.getSessionId());
-        }
+      for (LiveInstance instance : _liveInstanceMap.values()) {
+        LOG.debug("live instance: " + instance.getInstanceName() + " " + instance.getSessionId());
+      }
       LOG.debug("IdealStates: " + _idealStateMap.keySet());
       LOG.debug("ResourceConfigs: " + _resourceConfigMap.keySet());
       LOG.debug("InstanceConfigs: " + _instanceConfigMap.keySet());
@@ -323,7 +323,7 @@ public class ClusterDataCache {
   }
 
   public synchronized void setIdealStates(List<IdealState> idealStates) {
-    Map<String, IdealState> idealStateMap = new HashMap();
+    Map<String, IdealState> idealStateMap = new HashMap<>();
     for (IdealState idealState : idealStates) {
       idealStateMap.put(idealState.getId(), idealState);
     }
@@ -409,7 +409,7 @@ public class ClusterDataCache {
 
 
   public synchronized void setLiveInstances(List<LiveInstance> liveInstances) {
-    Map<String, LiveInstance> liveInstanceMap = new HashMap();
+    Map<String, LiveInstance> liveInstanceMap = new HashMap<>();
     for (LiveInstance liveInstance : liveInstances) {
       liveInstanceMap.put(liveInstance.getId(), liveInstance);
     }
@@ -501,7 +501,7 @@ public class ClusterDataCache {
    * Notify the cache that some part of the cluster data has been changed.
    */
   public void notifyDataChange(ChangeType changeType) {
-    _propertyDataChangedMap.put(changeType, Boolean.valueOf(true));
+    _propertyDataChangedMap.put(changeType, true);
   }
 
   /**
@@ -556,7 +556,7 @@ public class ClusterDataCache {
 
 
   public synchronized void setInstanceConfigs(List<InstanceConfig> instanceConfigs) {
-    Map<String, InstanceConfig> instanceConfigMap = new HashMap();
+    Map<String, InstanceConfig> instanceConfigMap = new HashMap<>();
     for (InstanceConfig instanceConfig : instanceConfigs) {
       instanceConfigMap.put(instanceConfig.getId(), instanceConfig);
     }
@@ -707,6 +707,8 @@ public class ClusterDataCache {
     return Collections.unmodifiableMap(newIdealStateMap);
   }
 
+
+
   /**
    * Return the JobContext by resource name
    * @param resourceName
@@ -794,7 +796,7 @@ public class ClusterDataCache {
    */
   public synchronized void requireFullRefresh() {
     for(ChangeType type : ChangeType.values()) {
-      _propertyDataChangedMap.put(type, Boolean.valueOf(true));
+      _propertyDataChangedMap.put(type, true);
     }
   }
 
@@ -884,7 +886,7 @@ public class ClusterDataCache {
   }
 
   /**
-   * Set the cache is serving for Task pipleline or not
+   * Set the cache is serving for Task pipeline or not
    * @param taskCache
    */
   public void setTaskCache(boolean taskCache) {
@@ -892,7 +894,7 @@ public class ClusterDataCache {
   }
 
   /**
-   * Get the cache is serving for Task pipleline or not
+   * Get the cache is serving for Task pipeline or not
    * @return
    */
   public boolean isTaskCache() {
@@ -926,4 +928,4 @@ public class ClusterDataCache {
 
     return sb.toString();
   }
-}
+}
\ No newline at end of file