helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l...@apache.org
Subject helix git commit: [HELIX-637] Populate the StateModelDefinition once it is updated
Date Sat, 05 Nov 2016 00:16:56 GMT
Repository: helix
Updated Branches:
  refs/heads/helix-0.6.x 08bc1efac -> f08d867cb


[HELIX-637] Populate the StateModelDefinition once it is updated

Did a check for StateModeDefinition. Will be rewrite once it is updated.


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

Branch: refs/heads/helix-0.6.x
Commit: f08d867cb47650a5f9cf5e1f9bebb70745294555
Parents: 08bc1ef
Author: Junkai Xue <jxue@linkedin.com>
Authored: Mon Oct 31 11:48:17 2016 -0700
Committer: Junkai Xue <jxue@linkedin.com>
Committed: Fri Nov 4 17:16:03 2016 -0700

----------------------------------------------------------------------
 .../apache/helix/manager/zk/ZKHelixManager.java | 25 ++++++++++++++++----
 .../helix/model/StateModelDefinition.java       | 18 ++++++++++++++
 2 files changed, 39 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/f08d867c/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixManager.java b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixManager.java
index 8bf8a54..16b0882 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixManager.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixManager.java
@@ -28,6 +28,7 @@ import java.util.concurrent.TimeUnit;
 
 import org.I0Itec.zkclient.IZkStateListener;
 import org.I0Itec.zkclient.ZkConnection;
+import org.apache.helix.AccessOption;
 import org.apache.helix.BaseDataAccessor;
 import org.apache.helix.ClusterMessagingService;
 import org.apache.helix.ConfigAccessor;
@@ -41,6 +42,7 @@ import org.apache.helix.HelixDataAccessor;
 import org.apache.helix.HelixException;
 import org.apache.helix.HelixManager;
 import org.apache.helix.HelixManagerProperties;
+import org.apache.helix.HelixProperty;
 import org.apache.helix.HelixTimerTask;
 import org.apache.helix.IdealStateChangeListener;
 import org.apache.helix.InstanceConfigChangeListener;
@@ -63,6 +65,7 @@ import org.apache.helix.messaging.DefaultMessagingService;
 import org.apache.helix.model.BuiltInStateModelDefinitions;
 import org.apache.helix.model.HelixConfigScope.ConfigScopeProperty;
 import org.apache.helix.model.LiveInstance;
+import org.apache.helix.model.StateModelDefinition;
 import org.apache.helix.monitoring.ZKPathDataDumpTask;
 import org.apache.helix.participant.HelixStateMachineEngine;
 import org.apache.helix.participant.StateMachineEngine;
@@ -458,11 +461,25 @@ public class ZKHelixManager implements HelixManager, IZkStateListener
{
    * Add Helix built-in state model definitions if not exist
    */
   private void addBuiltInStateModelDefinitions() {
-    PropertyKey.Builder keyBuilder = _dataAccessor.keyBuilder();
     for (BuiltInStateModelDefinitions def : BuiltInStateModelDefinitions.values()) {
-      PropertyKey key = keyBuilder.stateModelDef(def.getStateModelDefinition().getId());
-      // creation succeeds only if not exist
-      _dataAccessor.createProperty(key, def.getStateModelDefinition());
+      String path = String
+          .format("/%s/STATEMODELDEFS/%s", _clusterName, def.getStateModelDefinition().getId());
+
+      HelixProperty property = _dataAccessor.getProperty(new PropertyKey.Builder(_clusterName)
+          .stateModelDef(def.getStateModelDefinition().getId()));
+
+      // Set new StateModelDefinition if it is different from old one.
+      if (property != null) {
+        // StateModelDefinition need to be updated
+        if (!new StateModelDefinition(property.getRecord()).equals(def.getStateModelDefinition()))
{
+          _baseDataAccessor
+              .set(path, def.getStateModelDefinition().getRecord(), AccessOption.PERSISTENT);
+        }
+      } else {
+        // StateModeDefinition does not exist
+        _baseDataAccessor
+            .create(path, def.getStateModelDefinition().getRecord(), AccessOption.PERSISTENT);
+      }
     }
   }
 

http://git-wip-us.apache.org/repos/asf/helix/blob/f08d867c/helix-core/src/main/java/org/apache/helix/model/StateModelDefinition.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/StateModelDefinition.java b/helix-core/src/main/java/org/apache/helix/model/StateModelDefinition.java
index b5eb58b..fc1d021 100644
--- a/helix-core/src/main/java/org/apache/helix/model/StateModelDefinition.java
+++ b/helix-core/src/main/java/org/apache/helix/model/StateModelDefinition.java
@@ -364,4 +364,22 @@ public class StateModelDefinition extends HelixProperty {
 
   }
 
+  @Override
+  public boolean equals(Object o) {
+    if (o == null) {
+      return false;
+    }
+
+    if (!(o instanceof StateModelDefinition)) {
+      return false;
+    }
+
+    StateModelDefinition stateModelDefinition = (StateModelDefinition) o;
+    return _initialState.equals(stateModelDefinition._initialState) && _statesCountMap
+        .equals(stateModelDefinition._statesCountMap) && _statesPriorityList
+        .equals(stateModelDefinition._statesPriorityList) && _stateTransitionPriorityList
+        .equals(stateModelDefinition._stateTransitionPriorityList) &&
+        _stateTransitionTable.equals(stateModelDefinition._stateTransitionTable);
+  }
+
 }


Mime
View raw message