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/03/25 21:44:52 UTC

[1/6] helix git commit: Add old API back for compatibility

Repository: helix
Updated Branches:
  refs/heads/master c1ab0b5ed -> c78f84284


Add old API back for compatibility


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

Branch: refs/heads/master
Commit: c78f842840c4dbd6702337efcfe960bb85d51fae
Parents: db949d0
Author: Junkai Xue <jx...@linkedin.com>
Authored: Tue Mar 20 16:37:43 2018 -0700
Committer: dasahcc <ju...@gmail.com>
Committed: Sun Mar 25 14:43:42 2018 -0700

----------------------------------------------------------------------
 .../src/main/java/org/apache/helix/task/TaskDriver.java     | 9 +++++++++
 1 file changed, 9 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/c78f8428/helix-core/src/main/java/org/apache/helix/task/TaskDriver.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/task/TaskDriver.java b/helix-core/src/main/java/org/apache/helix/task/TaskDriver.java
index f434ae3..44aa930 100644
--- a/helix-core/src/main/java/org/apache/helix/task/TaskDriver.java
+++ b/helix-core/src/main/java/org/apache/helix/task/TaskDriver.java
@@ -401,6 +401,15 @@ public class TaskDriver {
   }
 
   /**
+   * Keep the old name of API for backward compatibility
+   * @param queue
+   */
+  @Deprecated
+  public void cleanupJobQueue(String queue) {
+    cleanupQueue(queue);
+  }
+
+  /**
    * Remove all jobs that are in final states (ABORTED, FAILED, COMPLETED) from the job queue. The
    * job config, job context will be removed from Zookeeper.
    *


[6/6] helix git commit: Add new API for getProperty and get

Posted by jx...@apache.org.
Add new API for getProperty and get

These new APIs will perform different behavior as before. It will throw an exception if throwException flag set to be true and at least one of path is failed to read in the list. Previous behavior is ignoring the read failure and filled with null for unread data.


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

Branch: refs/heads/master
Commit: 38b9a7982da3a2f994da14571545dd40b696e5e7
Parents: 0e632b7
Author: Junkai Xue <jx...@linkedin.com>
Authored: Fri Mar 23 11:51:04 2018 -0700
Committer: dasahcc <ju...@gmail.com>
Committed: Sun Mar 25 14:43:42 2018 -0700

----------------------------------------------------------------------
 .../java/org/apache/helix/BaseDataAccessor.java |  13 +++
 .../org/apache/helix/HelixDataAccessor.java     |  39 +++++++
 .../helix/manager/zk/ZKHelixDataAccessor.java   |  42 +++++--
 .../helix/manager/zk/ZkBaseDataAccessor.java    |  15 ++-
 .../manager/zk/ZkCacheBaseDataAccessor.java     |  11 +-
 .../java/org/apache/helix/MockAccessor.java     |  15 +++
 .../manager/TestHelixDataAccessor.java          |  51 ++++++++
 .../apache/helix/mock/MockBaseDataAccessor.java |   6 +
 .../org/apache/helix/mock/MockZkClient.java     | 116 +++++++++++++++++++
 9 files changed, 298 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/38b9a798/helix-core/src/main/java/org/apache/helix/BaseDataAccessor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/BaseDataAccessor.java b/helix-core/src/main/java/org/apache/helix/BaseDataAccessor.java
index c42c700..7d024fa 100644
--- a/helix-core/src/main/java/org/apache/helix/BaseDataAccessor.java
+++ b/helix-core/src/main/java/org/apache/helix/BaseDataAccessor.java
@@ -141,6 +141,19 @@ public interface BaseDataAccessor<T> {
   List<T> get(List<String> paths, List<Stat> stats, int options);
 
   /**
+   * Get List of {@link T} corresponding to the paths using async api
+   * @param paths paths to the ZNodes
+   * @param stats retrieve a list of stats for the ZNodes
+   * @param options Set the type of ZNode see the valid values in {@link AccessOption}
+   * @param throwException Will throw an exception when it set to be true and one of the path
+   *                             is failed to read.
+   * @return List of record data stored at each ZNode, node value will return null if the node does
+   *         not exist
+   */
+  List<T> get(List<String> paths, List<Stat> stats, int options, boolean throwException)
+      throws HelixException;
+
+  /**
    * Get the children under a parent path using async api
    *
    * For this API, if some of child node is failed to read, Helix will return the data of read

http://git-wip-us.apache.org/repos/asf/helix/blob/38b9a798/helix-core/src/main/java/org/apache/helix/HelixDataAccessor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/HelixDataAccessor.java b/helix-core/src/main/java/org/apache/helix/HelixDataAccessor.java
index f8ae131..d8dde1e 100644
--- a/helix-core/src/main/java/org/apache/helix/HelixDataAccessor.java
+++ b/helix-core/src/main/java/org/apache/helix/HelixDataAccessor.java
@@ -86,6 +86,19 @@ public interface HelixDataAccessor {
   <T extends HelixProperty> List<T> getProperty(List<PropertyKey> keys);
 
   /**
+   * Return a list of property values, each of which must be refer to a single Helix
+   * Property. Property may be bucketized.
+   *
+   * Value will be null if not does not exist. If the node is failed to read, will throw exception
+   * when throwException is set to true.
+   *
+   * @param keys
+   * @param throwException
+   * @return
+   */
+  <T extends HelixProperty> List<T> getProperty(List<PropertyKey> keys, boolean throwException);
+
+  /**
    * Removes the property
    * @param key
    * @return true if removal was successful or node does not exist. false if the
@@ -124,6 +137,18 @@ public interface HelixDataAccessor {
   <T extends HelixProperty> List<T> getChildValues(PropertyKey key);
 
   /**
+   * Get the child values for a property. PropertyKey needs to refer to just one
+   * level above the non leaf. PropertyKey.isCollection must be true.
+   *
+   * Value will be null if not does not exist. If the node is failed to read, will throw exception
+   * when throwException is set to true.
+   * @param key
+   * @param throwException
+   * @return subPropertyValues
+   */
+  <T extends HelixProperty> List<T> getChildValues(PropertyKey key, boolean throwException);
+
+  /**
    * Same as getChildValues except that it converts list into a map using the id
    * of the HelixProperty
    * @param key
@@ -133,6 +158,20 @@ public interface HelixDataAccessor {
   <T extends HelixProperty> Map<String, T> getChildValuesMap(PropertyKey key);
 
   /**
+   * Same as getChildValues except that it converts list into a map using the id
+   * of the HelixProperty
+   *
+   * Value will be null if not does not exist. If the node is failed to read, will throw exception
+   * when throwException is set to true.
+   * @param key
+   * @param throwException
+   * @return a map of property identifiers to typed properties
+   */
+
+  <T extends HelixProperty> Map<String, T> getChildValuesMap(PropertyKey key,
+      boolean throwException);
+
+  /**
    * Adds multiple children to a parent.
    * @param keys
    * @param children

http://git-wip-us.apache.org/repos/asf/helix/blob/38b9a798/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixDataAccessor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixDataAccessor.java b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixDataAccessor.java
index eff76f8..a0c06f7 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixDataAccessor.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixDataAccessor.java
@@ -193,8 +193,15 @@ public class ZKHelixDataAccessor implements HelixDataAccessor {
     return success;
   }
 
+  @Deprecated
   @Override
   public <T extends HelixProperty> List<T> getProperty(List<PropertyKey> keys) {
+    return getProperty(keys, false);
+  }
+
+  @Override
+  public <T extends HelixProperty> List<T> getProperty(List<PropertyKey> keys,
+      boolean throwException) throws HelixException {
     if (keys == null || keys.size() == 0) {
       return Collections.emptyList();
     }
@@ -208,7 +215,7 @@ public class ZKHelixDataAccessor implements HelixDataAccessor {
       paths.add(key.getPath());
       stats.add(new Stat());
     }
-    List<ZNRecord> children = _baseDataAccessor.get(paths, stats, 0);
+    List<ZNRecord> children = _baseDataAccessor.get(paths, stats, 0, throwException);
 
     // check if bucketized
     for (int i = 0; i < keys.size(); i++) {
@@ -240,7 +247,7 @@ public class ZKHelixDataAccessor implements HelixDataAccessor {
             property.getRecord().getMapFields().clear();
             property.getRecord().getListFields().clear();
 
-            List<ZNRecord> childRecords = _baseDataAccessor.getChildren(path, null, options);
+            List<ZNRecord> childRecords = _baseDataAccessor.getChildren(path, null, options, 1, 0);
             ZNRecord assembledRecord = new ZNRecordAssembler().assemble(childRecords);
 
             // merge with parent node value
@@ -382,14 +389,24 @@ public class ZKHelixDataAccessor implements HelixDataAccessor {
     return childNames;
   }
 
+  @Deprecated
   @Override
   public <T extends HelixProperty> List<T> getChildValues(PropertyKey key) {
+    return getChildValues(key, false);
+  }
+
+  @Override
+  public <T extends HelixProperty> List<T> getChildValues(PropertyKey key, boolean throwException) {
     PropertyType type = key.getType();
     String parentPath = key.getPath();
     int options = constructOptions(type);
     List<T> childValues = new ArrayList<T>();
-
-    List<ZNRecord> children = _baseDataAccessor.getChildren(parentPath, null, options);
+    List<ZNRecord> children;
+    if (throwException) {
+      children = _baseDataAccessor.getChildren(parentPath, null, options, 1, 0);
+    } else {
+      children = _baseDataAccessor.getChildren(parentPath, null, options);
+    }
     if (children != null) {
       for (ZNRecord record : children) {
         switch (type) {
@@ -403,7 +420,12 @@ public class ZKHelixDataAccessor implements HelixDataAccessor {
             if (bucketSize > 0) {
               // TODO: fix this if record.id != pathName
               String childPath = parentPath + "/" + record.getId();
-              List<ZNRecord> childRecords = _baseDataAccessor.getChildren(childPath, null, options);
+              List<ZNRecord> childRecords;
+              if (throwException) {
+                childRecords = _baseDataAccessor.getChildren(childPath, null, options, 1, 0);
+              } else {
+                childRecords = _baseDataAccessor.getChildren(childPath, null, options);
+              }
               ZNRecord assembledRecord = new ZNRecordAssembler().assemble(childRecords);
 
               // merge with parent node value
@@ -430,18 +452,24 @@ public class ZKHelixDataAccessor implements HelixDataAccessor {
     return childValues;
   }
 
+  @Deprecated
   @Override
   public <T extends HelixProperty> Map<String, T> getChildValuesMap(PropertyKey key) {
+    return getChildValuesMap(key, false);
+  }
+
+  @Override
+  public <T extends HelixProperty> Map<String, T> getChildValuesMap(PropertyKey key,
+      boolean throwException) {
     PropertyType type = key.getType();
     String parentPath = key.getPath();
     int options = constructOptions(type);
-    List<T> children = getChildValues(key);
+    List<T> children = getChildValues(key, throwException);
     Map<String, T> childValuesMap = new HashMap<String, T>();
     for (T t : children) {
       childValuesMap.put(t.getRecord().getId(), t);
     }
     return childValuesMap;
-
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/helix/blob/38b9a798/helix-core/src/main/java/org/apache/helix/manager/zk/ZkBaseDataAccessor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ZkBaseDataAccessor.java b/helix-core/src/main/java/org/apache/helix/manager/zk/ZkBaseDataAccessor.java
index 9525103..c83d9d5 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ZkBaseDataAccessor.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/ZkBaseDataAccessor.java
@@ -336,10 +336,21 @@ public class ZkBaseDataAccessor<T> implements BaseDataAccessor<T> {
     return get(paths, stats, needRead, false);
   }
 
+
+  @Override
+  public List<T> get(List<String> paths, List<Stat> stats, int options,
+      boolean throwException) throws HelixException {
+    boolean[] needRead = new boolean[paths.size()];
+    Arrays.fill(needRead, true);
+
+    return get(paths, stats, needRead, throwException);
+  }
+
   /**
    * async get
    */
-  List<T> get(List<String> paths, List<Stat> stats, boolean[] needRead, boolean throwException) {
+  List<T> get(List<String> paths, List<Stat> stats, boolean[] needRead, boolean throwException)
+      throws HelixException {
     if (paths == null || paths.size() == 0) {
       return Collections.emptyList();
     }
@@ -398,6 +409,8 @@ public class ZkBaseDataAccessor<T> implements BaseDataAccessor<T> {
         LOG.warn("Fail to read record for paths: " + pathFailToRead);
       }
       return records;
+    } catch (Exception e) {
+      throw new HelixException(String.format("Fail to read nodes for %s", paths));
     } finally {
       long endT = System.nanoTime();
       if (LOG.isTraceEnabled()) {

http://git-wip-us.apache.org/repos/asf/helix/blob/38b9a798/helix-core/src/main/java/org/apache/helix/manager/zk/ZkCacheBaseDataAccessor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ZkCacheBaseDataAccessor.java b/helix-core/src/main/java/org/apache/helix/manager/zk/ZkCacheBaseDataAccessor.java
index 3a7553f..4c0fcf2 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ZkCacheBaseDataAccessor.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/ZkCacheBaseDataAccessor.java
@@ -567,6 +567,12 @@ public class ZkCacheBaseDataAccessor<T> implements HelixPropertyStore<T> {
 
   @Override
   public List<T> get(List<String> paths, List<Stat> stats, int options) {
+    return get(paths, stats, options, false);
+  }
+
+  @Override
+  public List<T> get(List<String> paths, List<Stat> stats, int options, boolean throwException)
+      throws HelixException {
     if (paths == null || paths.isEmpty()) {
       return Collections.emptyList();
     }
@@ -603,7 +609,8 @@ public class ZkCacheBaseDataAccessor<T> implements HelixPropertyStore<T> {
       if (needRead) {
         cache.lockWrite();
         try {
-          List<T> readRecords = _baseAccessor.get(serverPaths, readStats, needReads, false);
+          List<T> readRecords =
+              _baseAccessor.get(serverPaths, readStats, needReads, throwException);
           for (int i = 0; i < size; i++) {
             if (needReads[i]) {
               records.set(i, readRecords.get(i));
@@ -624,7 +631,7 @@ public class ZkCacheBaseDataAccessor<T> implements HelixPropertyStore<T> {
     }
 
     // no cache
-    return _baseAccessor.get(serverPaths, stats, options);
+    return _baseAccessor.get(serverPaths, stats, options, throwException);
   }
 
   // TODO: add cache

http://git-wip-us.apache.org/repos/asf/helix/blob/38b9a798/helix-core/src/test/java/org/apache/helix/MockAccessor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/MockAccessor.java b/helix-core/src/test/java/org/apache/helix/MockAccessor.java
index 14c1845..e3189f8 100644
--- a/helix-core/src/test/java/org/apache/helix/MockAccessor.java
+++ b/helix-core/src/test/java/org/apache/helix/MockAccessor.java
@@ -190,12 +190,22 @@ public class MockAccessor implements HelixDataAccessor {
     return (List<T>) HelixProperty.convertToTypedList(propertyKey.getTypeClass(), children);
   }
 
+  @Override public <T extends HelixProperty> List<T> getChildValues(PropertyKey key,
+      boolean throwException) {
+    return null;
+  }
+
   @Override
   public <T extends HelixProperty> Map<String, T> getChildValuesMap(PropertyKey key) {
     List<T> list = getChildValues(key);
     return HelixProperty.convertListToMap(list);
   }
 
+  @Override public <T extends HelixProperty> Map<String, T> getChildValuesMap(PropertyKey key,
+      boolean throwException) {
+    return null;
+  }
+
   @Override
   public <T extends HelixProperty> boolean[] createChildren(List<PropertyKey> keys,
       List<T> children) {
@@ -239,4 +249,9 @@ public class MockAccessor implements HelixDataAccessor {
     }
     return list;
   }
+
+  @Override public <T extends HelixProperty> List<T> getProperty(List<PropertyKey> keys,
+      boolean throwException) {
+    return null;
+  }
 }

http://git-wip-us.apache.org/repos/asf/helix/blob/38b9a798/helix-core/src/test/java/org/apache/helix/integration/manager/TestHelixDataAccessor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/manager/TestHelixDataAccessor.java b/helix-core/src/test/java/org/apache/helix/integration/manager/TestHelixDataAccessor.java
new file mode 100644
index 0000000..ec0275a
--- /dev/null
+++ b/helix-core/src/test/java/org/apache/helix/integration/manager/TestHelixDataAccessor.java
@@ -0,0 +1,51 @@
+package org.apache.helix.integration.manager;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import org.apache.helix.BaseDataAccessor;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixException;
+import org.apache.helix.HelixProperty;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.ZNRecord;
+import org.apache.helix.integration.common.ZkIntegrationTestBase;
+import org.apache.helix.manager.zk.ZKHelixDataAccessor;
+import org.apache.helix.manager.zk.ZkBaseDataAccessor;
+import org.apache.helix.mock.MockZkClient;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class TestHelixDataAccessor extends ZkIntegrationTestBase{
+  private MockZkClient _zkClient;
+
+  @BeforeClass
+  public void beforeClass() {
+    _zkClient = new MockZkClient(ZK_ADDR);
+  }
+
+  @Test(expectedExceptions = HelixException.class)
+  public void testHelixDataAccessorReadData() {
+    BaseDataAccessor<ZNRecord> baseDataAccessor = new ZkBaseDataAccessor<>(_zkClient);
+    HelixDataAccessor accessor = new ZKHelixDataAccessor("HELIX", baseDataAccessor);
+
+    Map<String, HelixProperty> paths = new TreeMap<>();
+    List<PropertyKey> propertyKeys = new ArrayList<>();
+    for (int i = 0; i < 5; i++) {
+      PropertyKey key = accessor.keyBuilder().idealStates("RESOURCE" + i);
+      propertyKeys.add(key);
+      paths.put(key.getPath(), new HelixProperty("RESOURCE" + i));
+      accessor.setProperty(key, paths.get(key.getPath()));
+    }
+
+    List<HelixProperty> data = accessor.getProperty(new ArrayList<>(propertyKeys));
+    Assert.assertEquals(data.size(), 5);
+
+    PropertyKey key = accessor.keyBuilder().idealStates("RESOURCE6");
+    propertyKeys.add(key);
+    _zkClient.putData(key.getPath(), null);
+    accessor.getProperty(new ArrayList<>(propertyKeys), true);
+  }
+}

http://git-wip-us.apache.org/repos/asf/helix/blob/38b9a798/helix-core/src/test/java/org/apache/helix/mock/MockBaseDataAccessor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/mock/MockBaseDataAccessor.java b/helix-core/src/test/java/org/apache/helix/mock/MockBaseDataAccessor.java
index 099b3fc..55e0853 100644
--- a/helix-core/src/test/java/org/apache/helix/mock/MockBaseDataAccessor.java
+++ b/helix-core/src/test/java/org/apache/helix/mock/MockBaseDataAccessor.java
@@ -151,6 +151,12 @@ public class MockBaseDataAccessor implements BaseDataAccessor<ZNRecord> {
 
   @Override
   public List<ZNRecord> get(List<String> paths, List<Stat> stats, int options) {
+    return get(paths, stats, options, false);
+  }
+
+  @Override
+  public List<ZNRecord> get(List<String> paths, List<Stat> stats, int options,
+      boolean throwException) throws HelixException {
     List<ZNRecord> records = new ArrayList<>();
     for (int i = 0; i < paths.size(); i++) {
       ZNRecord record = get(paths.get(i), stats.get(i), options);

http://git-wip-us.apache.org/repos/asf/helix/blob/38b9a798/helix-core/src/test/java/org/apache/helix/mock/MockZkClient.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/mock/MockZkClient.java b/helix-core/src/test/java/org/apache/helix/mock/MockZkClient.java
new file mode 100644
index 0000000..05d7894
--- /dev/null
+++ b/helix-core/src/test/java/org/apache/helix/mock/MockZkClient.java
@@ -0,0 +1,116 @@
+package org.apache.helix.mock;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.I0Itec.zkclient.IZkConnection;
+import org.I0Itec.zkclient.serialize.ZkSerializer;
+import org.apache.helix.manager.zk.PathBasedZkSerializer;
+import org.apache.helix.manager.zk.ZNRecordSerializer;
+import org.apache.helix.manager.zk.ZkAsyncCallbacks;
+import org.apache.helix.manager.zk.ZkClient;
+import org.apache.zookeeper.KeeperException;
+
+public class MockZkClient extends ZkClient {
+  Map<String, byte[]> _dataMap;
+
+  public MockZkClient(String zkAddress) {
+    super(zkAddress);
+    _dataMap = new HashMap<>();
+    setZkSerializer(new ZNRecordSerializer());
+  }
+  public MockZkClient(IZkConnection zkConnection, int connectionTimeout, long operationRetryTimeout,
+      PathBasedZkSerializer zkSerializer, String monitorType, String monitorKey,
+      String monitorInstanceName, boolean monitorRootPathOnly) {
+    super(zkConnection, connectionTimeout, operationRetryTimeout, zkSerializer, monitorType,
+        monitorKey, monitorInstanceName, monitorRootPathOnly);
+  }
+
+  public MockZkClient(IZkConnection connection, int connectionTimeout,
+      PathBasedZkSerializer zkSerializer, String monitorType, String monitorKey,
+      long operationRetryTimeout) {
+    super(connection, connectionTimeout, zkSerializer, monitorType, monitorKey,
+        operationRetryTimeout);
+  }
+
+  public MockZkClient(IZkConnection connection, int connectionTimeout,
+      PathBasedZkSerializer zkSerializer, String monitorType, String monitorKey) {
+    super(connection, connectionTimeout, zkSerializer, monitorType, monitorKey);
+  }
+
+  public MockZkClient(String zkServers, String monitorType, String monitorKey) {
+    super(zkServers, monitorType, monitorKey);
+  }
+
+  public MockZkClient(String zkServers, int sessionTimeout, int connectionTimeout,
+      PathBasedZkSerializer zkSerializer, String monitorType, String monitorKey) {
+    super(zkServers, sessionTimeout, connectionTimeout, zkSerializer, monitorType, monitorKey);
+  }
+
+  public MockZkClient(IZkConnection connection, int connectionTimeout,
+      PathBasedZkSerializer zkSerializer) {
+    super(connection, connectionTimeout, zkSerializer);
+  }
+
+  public MockZkClient(IZkConnection connection, int connectionTimeout, ZkSerializer zkSerializer) {
+    super(connection, connectionTimeout, zkSerializer);
+  }
+
+  public MockZkClient(IZkConnection connection, int connectionTimeout) {
+    super(connection, connectionTimeout);
+  }
+
+  public MockZkClient(IZkConnection connection) {
+    super(connection);
+  }
+
+  public MockZkClient(String zkServers, int sessionTimeout, int connectionTimeout,
+      ZkSerializer zkSerializer) {
+    super(zkServers, sessionTimeout, connectionTimeout, zkSerializer);
+  }
+
+  public MockZkClient(String zkServers, int sessionTimeout, int connectionTimeout,
+      PathBasedZkSerializer zkSerializer) {
+    super(zkServers, sessionTimeout, connectionTimeout, zkSerializer);
+  }
+
+  public MockZkClient(String zkServers, int sessionTimeout, int connectionTimeout) {
+    super(zkServers, sessionTimeout, connectionTimeout);
+  }
+
+  public MockZkClient(String zkServers, int connectionTimeout) {
+    super(zkServers, connectionTimeout);
+  }
+
+  public MockZkClient(String zkServers, int sessionTimeout, int connectionTimeout,
+      ZkSerializer zkSerializer, long operationRetryTimeout) {
+    super(zkServers, sessionTimeout, connectionTimeout, zkSerializer, operationRetryTimeout);
+  }
+
+  public MockZkClient(IZkConnection zkConnection, int connectionTimeout, ZkSerializer zkSerializer,
+      long operationRetryTimeout) {
+    super(zkConnection, connectionTimeout, zkSerializer, operationRetryTimeout);
+  }
+
+
+  @Override
+  public void asyncGetData(final String path,
+      final ZkAsyncCallbacks.GetDataCallbackHandler cb) {
+    if (_dataMap.containsKey(path)) {
+      if (_dataMap.get(path) == null) {
+        cb.processResult(4, path, null, _dataMap.get(path), null);
+      } else {
+        cb.processResult(0, path, null, _dataMap.get(path), null);
+      }
+    } else {
+      cb.processResult(KeeperException.Code.NONODE.intValue(), path, null, null, null);
+    }
+  }
+
+  public void putData(String path, byte[] data) {
+    _dataMap.put(path, data);
+  }
+
+  public byte[] removeData(String path) {
+    return _dataMap.remove(path);
+  }
+}


[2/6] helix git commit: Fix Timeout scheduling issue.

Posted by jx...@apache.org.
Fix Timeout scheduling issue.

If there is no timeout specified in the workflow, it will keep scheduling the rebalancer which trigger events.


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

Branch: refs/heads/master
Commit: 305add9be0da711c6257e4b0bf82027587b5493b
Parents: 38b9a79
Author: Junkai Xue <jx...@linkedin.com>
Authored: Fri Mar 2 15:51:09 2018 -0800
Committer: dasahcc <ju...@gmail.com>
Committed: Sun Mar 25 14:43:42 2018 -0700

----------------------------------------------------------------------
 .../helix/controller/rebalancer/util/RebalanceScheduler.java    | 3 +++
 .../src/main/java/org/apache/helix/task/TaskRebalancer.java     | 5 +++--
 2 files changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/305add9b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/util/RebalanceScheduler.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/util/RebalanceScheduler.java b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/util/RebalanceScheduler.java
index 81e5d8d..5ddcf4c 100644
--- a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/util/RebalanceScheduler.java
+++ b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/util/RebalanceScheduler.java
@@ -60,6 +60,9 @@ public class RebalanceScheduler {
     }
 
     long delay = startTime - System.currentTimeMillis();
+    if (delay < 0) {
+      LOG.debug(String.format("Delay time is %s, will not be scheduled", delay));
+    }
     LOG.info(
         "Schedule rebalance for resource : " + resource + " at time: " + startTime + " delay: "
             + delay);

http://git-wip-us.apache.org/repos/asf/helix/blob/305add9b/helix-core/src/main/java/org/apache/helix/task/TaskRebalancer.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/task/TaskRebalancer.java b/helix-core/src/main/java/org/apache/helix/task/TaskRebalancer.java
index 5e0fe01..e0e9903 100644
--- a/helix-core/src/main/java/org/apache/helix/task/TaskRebalancer.java
+++ b/helix-core/src/main/java/org/apache/helix/task/TaskRebalancer.java
@@ -296,8 +296,9 @@ public abstract class TaskRebalancer implements Rebalancer, MappingCalculator {
       long timeoutPeriod) {
     long nextTimeout = getTimeoutTime(startTime, timeoutPeriod);
     long nextRebalanceTime = _rebalanceScheduler.getRebalanceTime(resourceId);
-    if (nextRebalanceTime == TaskConstants.DEFAULT_NEVER_TIMEOUT
-        || nextTimeout < nextRebalanceTime) {
+    if (nextTimeout >= System.currentTimeMillis() && (
+        nextRebalanceTime == TaskConstants.DEFAULT_NEVER_TIMEOUT
+            || nextTimeout < nextRebalanceTime)) {
       _rebalanceScheduler.scheduleRebalance(_manager, resourceId, nextTimeout);
     }
   }


[5/6] helix git commit: Avoid redundant calculation for disabled instances

Posted by jx...@apache.org.
Avoid redundant calculation for disabled instances

For Pinot reported issue that BestPossibleStage takes 100s for initial resource calculation, the part of delay caused by recalculating disabled instances for partition.
Improve this with calculate it once when refresh data.
TODO: once we can do major refactor that can identify the ClusterConfig change in cache, we can optimize it with recalculating it only when instance config and cluster config changes.


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

Branch: refs/heads/master
Commit: db949d0f64c5a4ac9923bc7bdf3736dd0e7a8640
Parents: 305add9
Author: Junkai Xue <jx...@linkedin.com>
Authored: Sat Mar 24 21:36:54 2018 -0700
Committer: dasahcc <ju...@gmail.com>
Committed: Sun Mar 25 14:43:42 2018 -0700

----------------------------------------------------------------------
 .../controller/stages/ClusterDataCache.java     | 58 +++++++++++++-------
 .../rebalancer/TestAutoRebalanceStrategy.java   |  2 +
 .../stages/TestMessageThrottleStage.java        |  4 ++
 .../stages/TestRebalancePipeline.java           | 23 +++-----
 .../stages/TestResourceValidationStage.java     |  5 +-
 .../task/TestTaskRebalancerStopResume.java      |  3 +-
 6 files changed, 59 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/db949d0f/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 e946a9d..2317197 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
@@ -83,6 +83,8 @@ public class ClusterDataCache {
   private Map<String, Map<String, String>> _idealStateRuleMap;
   private Map<String, Map<String, Long>> _missingTopStateMap = new HashMap<>();
   private Map<String, ExternalView> _targetExternalViewMap = new HashMap<>();
+  private Map<String, Map<String, Set<String>>> _disabledInstanceForPartitionMap = new HashMap<>();
+  private Set<String> _disabledInstanceSet = new HashSet<>();
 
   private CurrentStateCache _currentStateCache;
   private TaskDataCache _taskDataCache;
@@ -207,6 +209,8 @@ public class ClusterDataCache {
     MaintenanceSignal maintenanceSignal = accessor.getProperty(keyBuilder.maintenance());
     _isMaintenanceModeEnabled = (maintenanceSignal != null) ? true : false;
 
+    updateDisabledInstances();
+
     long endTime = System.currentTimeMillis();
     LOG.info(
         "END: ClusterDataCache.refresh() for cluster " + getClusterName() + ", took " + (endTime
@@ -232,6 +236,33 @@ public class ClusterDataCache {
     return true;
   }
 
+  private void updateDisabledInstances() {
+    // Move the calculating disabled instances to refresh
+    _disabledInstanceForPartitionMap.clear();
+    _disabledInstanceSet.clear();
+    for (InstanceConfig config : _instanceConfigMap.values()) {
+      Map<String, List<String>> disabledPartitionMap = config.getDisabledPartitionsMap();
+      if (!config.getInstanceEnabled()) {
+        _disabledInstanceSet.add(config.getInstanceName());
+      }
+      for (String resource : disabledPartitionMap.keySet()) {
+        if (!_disabledInstanceForPartitionMap.containsKey(resource)) {
+          _disabledInstanceForPartitionMap.put(resource, new HashMap<String, Set<String>>());
+        }
+        for (String partition : disabledPartitionMap.get(resource)) {
+          if (!_disabledInstanceForPartitionMap.get(resource).containsKey(partition)) {
+            _disabledInstanceForPartitionMap.get(resource).put(partition, new HashSet<String>());
+          }
+          _disabledInstanceForPartitionMap.get(resource).get(partition)
+              .add(config.getInstanceName());
+        }
+      }
+    }
+    if (_clusterConfig.getDisabledInstances() != null) {
+      _disabledInstanceSet.addAll(_clusterConfig.getDisabledInstances().keySet());
+    }
+  }
+
   private void updateOfflineInstanceHistory(HelixDataAccessor accessor) {
     List<String> offlineNodes = new ArrayList<>(_instanceConfigMap.keySet());
     offlineNodes.removeAll(_liveInstanceMap.keySet());
@@ -533,16 +564,14 @@ public class ClusterDataCache {
    * @return
    */
   public Set<String> getDisabledInstancesForPartition(String resource, String partition) {
-    Set<String> disabledInstancesSet = new HashSet<String>();
-    for (String instance : _instanceConfigMap.keySet()) {
-      InstanceConfig config = _instanceConfigMap.get(instance);
-      if (config.getInstanceEnabled() == false || (_clusterConfig.getDisabledInstances() != null
-          && _clusterConfig.getDisabledInstances().containsKey(instance))
-          || config.getInstanceEnabledForPartition(resource, partition) == false) {
-        disabledInstancesSet.add(instance);
-      }
+    Set<String> disabledInstancesForPartition = new HashSet<>(_disabledInstanceSet);
+    if (_disabledInstanceForPartitionMap.containsKey(resource) && _disabledInstanceForPartitionMap
+        .get(resource).containsKey(partition)) {
+      disabledInstancesForPartition
+          .addAll(_disabledInstanceForPartitionMap.get(resource).get(partition));
     }
-    return disabledInstancesSet;
+
+    return disabledInstancesForPartition;
   }
 
   /**
@@ -551,16 +580,7 @@ public class ClusterDataCache {
    * @return
    */
   public Set<String> getDisabledInstances() {
-    Set<String> disabledInstancesSet = new HashSet<>();
-    for (String instance : _instanceConfigMap.keySet()) {
-      InstanceConfig config = _instanceConfigMap.get(instance);
-      if (!config.getInstanceEnabled()
-          || (_clusterConfig.getDisabledInstances() != null && _clusterConfig.getDisabledInstances()
-          .containsKey(instance))) {
-        disabledInstancesSet.add(instance);
-      }
-    }
-    return disabledInstancesSet;
+    return Collections.unmodifiableSet(_disabledInstanceSet);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/helix/blob/db949d0f/helix-core/src/test/java/org/apache/helix/controller/rebalancer/TestAutoRebalanceStrategy.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/controller/rebalancer/TestAutoRebalanceStrategy.java b/helix-core/src/test/java/org/apache/helix/controller/rebalancer/TestAutoRebalanceStrategy.java
index 29aa863..56fc615 100644
--- a/helix-core/src/test/java/org/apache/helix/controller/rebalancer/TestAutoRebalanceStrategy.java
+++ b/helix-core/src/test/java/org/apache/helix/controller/rebalancer/TestAutoRebalanceStrategy.java
@@ -41,6 +41,7 @@ import org.apache.helix.ZNRecord;
 import org.apache.helix.controller.rebalancer.strategy.AutoRebalanceStrategy;
 import org.apache.helix.controller.rebalancer.strategy.RebalanceStrategy;
 import org.apache.helix.controller.stages.ClusterDataCache;
+import org.apache.helix.model.ClusterConfig;
 import org.apache.helix.model.IdealState;
 import org.apache.helix.model.LiveInstance;
 import org.apache.helix.model.StateModelDefinition;
@@ -217,6 +218,7 @@ public class TestAutoRebalanceStrategy {
       ClusterDataCache cache = new ClusterDataCache();
       MockAccessor accessor = new MockAccessor();
       Builder keyBuilder = accessor.keyBuilder();
+      accessor.setProperty(keyBuilder.clusterConfig(), new ClusterConfig("TestCluster"));
       for (String node : _liveNodes) {
         LiveInstance liveInstance = new LiveInstance(node);
         liveInstance.setSessionId("testSession");

http://git-wip-us.apache.org/repos/asf/helix/blob/db949d0f/helix-core/src/test/java/org/apache/helix/controller/stages/TestMessageThrottleStage.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/controller/stages/TestMessageThrottleStage.java b/helix-core/src/test/java/org/apache/helix/controller/stages/TestMessageThrottleStage.java
index fa6b084..9054a1d 100644
--- a/helix-core/src/test/java/org/apache/helix/controller/stages/TestMessageThrottleStage.java
+++ b/helix-core/src/test/java/org/apache/helix/controller/stages/TestMessageThrottleStage.java
@@ -72,7 +72,9 @@ public class TestMessageThrottleStage extends ZkUnitTestBase {
     setupStateModel(clusterName);
 
     ClusterEvent event = new ClusterEvent(ClusterEventType.Unknown);
+    ClusterDataCache cache = new ClusterDataCache(clusterName);
     event.addAttribute(AttributeName.helixmanager.name(), manager);
+    event.addAttribute(AttributeName.ClusterDataCache.name(), cache);
 
     MessageThrottleStage throttleStage = new MessageThrottleStage();
     try {
@@ -259,7 +261,9 @@ public class TestMessageThrottleStage extends ZkUnitTestBase {
 
     // test messageThrottleStage
     ClusterEvent event = new ClusterEvent(ClusterEventType.Unknown);
+    ClusterDataCache cache = new ClusterDataCache(clusterName);
     event.addAttribute(AttributeName.helixmanager.name(), manager);
+    event.addAttribute(AttributeName.ClusterDataCache.name(), cache);
 
     Pipeline dataRefresh = new Pipeline();
     dataRefresh.addStage(new ReadClusterDataStage());

http://git-wip-us.apache.org/repos/asf/helix/blob/db949d0f/helix-core/src/test/java/org/apache/helix/controller/stages/TestRebalancePipeline.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/controller/stages/TestRebalancePipeline.java b/helix-core/src/test/java/org/apache/helix/controller/stages/TestRebalancePipeline.java
index 7c4bba6..9d4790d 100644
--- a/helix-core/src/test/java/org/apache/helix/controller/stages/TestRebalancePipeline.java
+++ b/helix-core/src/test/java/org/apache/helix/controller/stages/TestRebalancePipeline.java
@@ -56,7 +56,7 @@ public class TestRebalancePipeline extends ZkUnitTestBase {
 
     HelixDataAccessor accessor =
         new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
-
+    refreshClusterConfig(clusterName, accessor);
     HelixManager manager = new DummyClusterManager(clusterName, accessor);
     ClusterEvent event = new ClusterEvent(ClusterEventType.Unknown);
     event.addAttribute(AttributeName.helixmanager.name(), manager);
@@ -95,7 +95,6 @@ public class TestRebalancePipeline extends ZkUnitTestBase {
         "OFFLINE");
 
     runPipeline(event, dataRefresh);
-    refreshClusterConfig(event, clusterName);
     runPipeline(event, rebalancePipeline);
     MessageSelectionStageOutput msgSelOutput =
         event.getAttribute(AttributeName.MESSAGES_SELECTED.name());
@@ -113,7 +112,7 @@ public class TestRebalancePipeline extends ZkUnitTestBase {
         "SLAVE");
 
     runPipeline(event, dataRefresh);
-    refreshClusterConfig(event, clusterName);
+    refreshClusterConfig(clusterName, accessor);
     runPipeline(event, rebalancePipeline);
     msgSelOutput = event.getAttribute(AttributeName.MESSAGES_SELECTED.name());
     messages = msgSelOutput.getMessages(resourceName, new Partition(resourceName + "_0"));
@@ -132,7 +131,7 @@ public class TestRebalancePipeline extends ZkUnitTestBase {
         new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
     HelixManager manager = new DummyClusterManager(clusterName, accessor);
     ClusterEvent event = new ClusterEvent(ClusterEventType.Unknown);
-
+    refreshClusterConfig(clusterName, accessor);
     final String resourceName = "testResource_dup";
     String[] resourceGroups = new String[] {
       resourceName
@@ -156,7 +155,6 @@ public class TestRebalancePipeline extends ZkUnitTestBase {
     ClusterControllerManager controller =
         new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
     controller.syncStart();
-
     // round1: controller sends O->S to both node0 and node1
     Thread.sleep(1000);
 
@@ -246,7 +244,7 @@ public class TestRebalancePipeline extends ZkUnitTestBase {
 
     ClusterDataCache cache = new ClusterDataCache();
     event.addAttribute(AttributeName.ClusterDataCache.name(), cache);
-    refreshClusterConfig(event, clusterName);
+    refreshClusterConfig(clusterName, accessor);
 
     final String resourceName = "testResource_pending";
     String[] resourceGroups = new String[] {
@@ -282,7 +280,6 @@ public class TestRebalancePipeline extends ZkUnitTestBase {
         "OFFLINE");
 
     runPipeline(event, dataRefresh);
-    refreshClusterConfig(event, clusterName);
     runPipeline(event, rebalancePipeline);
     MessageSelectionStageOutput msgSelOutput =
         event.getAttribute(AttributeName.MESSAGES_SELECTED.name());
@@ -316,7 +313,6 @@ public class TestRebalancePipeline extends ZkUnitTestBase {
     List<String> msgIds = accessor.getChildNames(keyBuilder.messages("localhost_0"));
     accessor.removeProperty(keyBuilder.message("localhost_0", msgIds.get(0)));
     runPipeline(event, dataRefresh);
-    refreshClusterConfig(event, clusterName);
     runPipeline(event, rebalancePipeline);
     msgSelOutput = event.getAttribute(AttributeName.MESSAGES_SELECTED.name());
     messages = msgSelOutput.getMessages(resourceName, new Partition(resourceName + "_0"));
@@ -341,6 +337,7 @@ public class TestRebalancePipeline extends ZkUnitTestBase {
     HelixManager manager = new DummyClusterManager(clusterName, accessor);
     ClusterEvent event = new ClusterEvent(ClusterEventType.Unknown);
     event.addAttribute(AttributeName.helixmanager.name(), manager);
+    refreshClusterConfig(clusterName, accessor);
 
     final String resourceName = "testResource_xfer";
     String[] resourceGroups = new String[] {
@@ -376,7 +373,6 @@ public class TestRebalancePipeline extends ZkUnitTestBase {
         "SLAVE");
 
     runPipeline(event, dataRefresh);
-    refreshClusterConfig(event, clusterName);
     runPipeline(event, rebalancePipeline);
     MessageSelectionStageOutput msgSelOutput =
         event.getAttribute(AttributeName.MESSAGES_SELECTED.name());
@@ -397,7 +393,6 @@ public class TestRebalancePipeline extends ZkUnitTestBase {
         "SLAVE");
 
     runPipeline(event, dataRefresh);
-    refreshClusterConfig(event, clusterName);
     runPipeline(event, rebalancePipeline);
     msgSelOutput = event.getAttribute(AttributeName.MESSAGES_SELECTED.name());
     messages = msgSelOutput.getMessages(resourceName, new Partition(resourceName + "_0"));
@@ -418,6 +413,7 @@ public class TestRebalancePipeline extends ZkUnitTestBase {
     HelixManager manager = new DummyClusterManager(clusterName, accessor);
     ClusterEvent event = new ClusterEvent(ClusterEventType.Unknown);
     event.addAttribute(AttributeName.helixmanager.name(), manager);
+    refreshClusterConfig(clusterName, accessor);
 
     final String resourceName = "testResource_no_duplicated_master";
     String[] resourceGroups = new String[] {
@@ -457,7 +453,6 @@ public class TestRebalancePipeline extends ZkUnitTestBase {
         "MASTER");
 
     runPipeline(event, dataRefresh);
-    refreshClusterConfig(event, clusterName);
     runPipeline(event, rebalancePipeline);
     MessageSelectionStageOutput msgSelOutput =
         event.getAttribute(AttributeName.MESSAGES_SELECTED.name());
@@ -493,9 +488,7 @@ public class TestRebalancePipeline extends ZkUnitTestBase {
     accessor.setProperty(keyBuilder.currentState(instance, sessionId, resourceGroupName), curState);
   }
 
-  private void refreshClusterConfig(ClusterEvent event, String clusterName) {
-    ClusterDataCache cache = event.getAttribute(AttributeName.ClusterDataCache.name());
-    cache.setClusterConfig(new ClusterConfig(clusterName));
-    event.addAttribute(AttributeName.ClusterDataCache.name(), cache);
+  private void refreshClusterConfig(String clusterName, HelixDataAccessor accessor) {
+    accessor.setProperty(accessor.keyBuilder().clusterConfig(), new ClusterConfig(clusterName));
   }
 }

http://git-wip-us.apache.org/repos/asf/helix/blob/db949d0f/helix-core/src/test/java/org/apache/helix/controller/stages/TestResourceValidationStage.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/controller/stages/TestResourceValidationStage.java b/helix-core/src/test/java/org/apache/helix/controller/stages/TestResourceValidationStage.java
index 57cc478..6334720 100644
--- a/helix-core/src/test/java/org/apache/helix/controller/stages/TestResourceValidationStage.java
+++ b/helix-core/src/test/java/org/apache/helix/controller/stages/TestResourceValidationStage.java
@@ -25,6 +25,7 @@ import org.apache.helix.HelixDataAccessor;
 import org.apache.helix.HelixProperty;
 import org.apache.helix.MockAccessor;
 import org.apache.helix.PropertyKey;
+import org.apache.helix.model.ClusterConfig;
 import org.apache.helix.model.IdealState;
 import org.apache.helix.model.IdealState.IdealStateProperty;
 import org.apache.helix.model.IdealState.RebalanceMode;
@@ -44,6 +45,7 @@ public class TestResourceValidationStage {
   @Test
   public void testIdealStateValidity() throws Exception {
     MockAccessor accessor = new MockAccessor();
+    accessor.setProperty(accessor.keyBuilder().clusterConfig(), new ClusterConfig("TestCluster"));
 
     // create some ideal states
     String masterSlaveCustomResource = "masterSlaveCustomResource";
@@ -88,6 +90,7 @@ public class TestResourceValidationStage {
   @Test
   public void testNoSpec() throws Exception {
     MockAccessor accessor = new MockAccessor();
+    accessor.setProperty(accessor.keyBuilder().clusterConfig(), new ClusterConfig("TestCluster"));
 
     // create an ideal state and no spec
     String masterSlaveCustomResource = "masterSlaveCustomResource";
@@ -116,7 +119,7 @@ public class TestResourceValidationStage {
   @Test
   public void testMissingStateModel() throws Exception {
     MockAccessor accessor = new MockAccessor();
-
+    accessor.setProperty(accessor.keyBuilder().clusterConfig(), new ClusterConfig("TestCluster"));
     // create an ideal state and no spec
     String masterSlaveCustomResource = "masterSlaveCustomResource";
     String leaderStandbyCustomResource = "leaderStandbyCustomResource";

http://git-wip-us.apache.org/repos/asf/helix/blob/db949d0f/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancerStopResume.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancerStopResume.java b/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancerStopResume.java
index a808633..8540a84 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancerStopResume.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancerStopResume.java
@@ -253,12 +253,13 @@ public class TestTaskRebalancerStopResume extends TaskTestBase {
       preJobFinish = jobContext.getFinishTime();
     }
 
+    TimeUnit.MILLISECONDS.sleep(2000);
     // Flush queue
     LOG.info("Flusing job-queue: " + queueName);
     _driver.flushQueue(queueName);
 
     // TODO: Use TestHelper.verify() instead of waiting here.
-    TimeUnit.MILLISECONDS.sleep(5000);
+    TimeUnit.MILLISECONDS.sleep(2000);
 
     // verify the cleanup
     for (int i = 0; i < currentJobNames.size(); i++) {


[4/6] helix git commit: Fixed broken TestZkHelixAdmin()

Posted by jx...@apache.org.
Fixed broken TestZkHelixAdmin()


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

Branch: refs/heads/master
Commit: 0e632b7797a03ce3b63feee394ff43567a73d014
Parents: 284c66d
Author: hrzhang <hr...@linkedin.com>
Authored: Thu Mar 8 14:33:47 2018 -0800
Committer: dasahcc <ju...@gmail.com>
Committed: Sun Mar 25 14:43:42 2018 -0700

----------------------------------------------------------------------
 .../src/main/java/org/apache/helix/model/InstanceConfig.java       | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/0e632b77/helix-core/src/main/java/org/apache/helix/model/InstanceConfig.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/InstanceConfig.java b/helix-core/src/main/java/org/apache/helix/model/InstanceConfig.java
index a26c039..3cc3c58 100644
--- a/helix-core/src/main/java/org/apache/helix/model/InstanceConfig.java
+++ b/helix-core/src/main/java/org/apache/helix/model/InstanceConfig.java
@@ -330,7 +330,7 @@ public class InstanceConfig extends HelixProperty {
       disabledPartitions.addAll(oldDisabled);
     }
 
-    if (newDisabledMap != null) {
+    if (newDisabledMap != null && newDisabledMap.containsKey(resourceName)) {
       disabledPartitions.addAll(HelixUtil.deserializeByComma(newDisabledMap.get(resourceName)));
     }
     return new ArrayList<String>(disabledPartitions);


[3/6] helix git commit: Remove empty resource entry if there is no partition disabled for this instance

Posted by jx...@apache.org.
Remove empty resource entry if there is no partition disabled for this instance


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

Branch: refs/heads/master
Commit: 284c66d07c38ac43b5aa408165b50f7ce8e1c36a
Parents: c1ab0b5
Author: Junkai Xue <jx...@linkedin.com>
Authored: Tue Feb 27 14:24:38 2018 -0800
Committer: dasahcc <ju...@gmail.com>
Committed: Sun Mar 25 14:43:42 2018 -0700

----------------------------------------------------------------------
 .../src/main/java/org/apache/helix/model/InstanceConfig.java       | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/284c66d0/helix-core/src/main/java/org/apache/helix/model/InstanceConfig.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/InstanceConfig.java b/helix-core/src/main/java/org/apache/helix/model/InstanceConfig.java
index 4343006..a26c039 100644
--- a/helix-core/src/main/java/org/apache/helix/model/InstanceConfig.java
+++ b/helix-core/src/main/java/org/apache/helix/model/InstanceConfig.java
@@ -412,7 +412,7 @@ public class InstanceConfig extends HelixProperty {
       currentDisabled = new HashMap<>();
     }
 
-    if (disabledPartitionList != null) {
+    if (disabledPartitionList != null && !disabledPartitionList.isEmpty()) {
       currentDisabled.put(resourceName, HelixUtil.serializeByComma(disabledPartitionList));
     } else {
       currentDisabled.remove(resourceName);