You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by ka...@apache.org on 2013/09/30 19:38:17 UTC

[1/2] git commit: [HELIX-216] Allow HelixAdmin addResource to accept the old rebalancing types

Updated Branches:
  refs/heads/helix-logical-model 9b48782d9 -> 5e2fc9352


[HELIX-216] Allow HelixAdmin addResource to accept the old rebalancing types


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

Branch: refs/heads/helix-logical-model
Commit: b0c1cb0f6c594d35299941c3278d7ced00d61073
Parents: 9b48782
Author: Kanak Biscuitwala <ka...@apache.org>
Authored: Mon Sep 30 09:44:38 2013 -0700
Committer: Kanak Biscuitwala <ka...@apache.org>
Committed: Mon Sep 30 09:44:38 2013 -0700

----------------------------------------------------------------------
 .../apache/helix/manager/zk/ZKHelixAdmin.java   |  8 ++------
 .../java/org/apache/helix/model/IdealState.java | 21 ++++++++++++++++++++
 2 files changed, 23 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/b0c1cb0f/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
index 3c5502d..75d564f 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
@@ -625,15 +625,11 @@ public class ZKHelixAdmin implements HelixAdmin {
       throw new HelixException("cluster " + clusterName + " is not setup yet");
     }
 
-    RebalanceMode mode = RebalanceMode.SEMI_AUTO;
-    try {
-      mode = RebalanceMode.valueOf(rebalancerMode);
-    } catch (Exception e) {
-      logger.error("", e);
-    }
     IdealState idealState = new IdealState(resourceName);
     idealState.setNumPartitions(partitions);
     idealState.setStateModelDefId(StateModelDefId.from(stateModelRef));
+    RebalanceMode mode =
+        idealState.rebalanceModeFromString(rebalancerMode, RebalanceMode.SEMI_AUTO);
     idealState.setRebalanceMode(mode);
     idealState.setReplicas("" + 0);
     idealState.setStateModelFactoryId(StateModelFactoryId

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/b0c1cb0f/helix-core/src/main/java/org/apache/helix/model/IdealState.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/IdealState.java b/helix-core/src/main/java/org/apache/helix/model/IdealState.java
index 342acf2..5996391 100644
--- a/helix-core/src/main/java/org/apache/helix/model/IdealState.java
+++ b/helix-core/src/main/java/org/apache/helix/model/IdealState.java
@@ -725,6 +725,27 @@ public class IdealState extends HelixProperty {
   }
 
   /**
+   * Parse a rebalance mode from a string. It can also understand IdealStateModeProperty values
+   * @param mode string containing a RebalanceMode value
+   * @param defaultMode the mode to use if the string is not valid
+   * @return converted RebalanceMode value
+   */
+  public RebalanceMode rebalanceModeFromString(String mode, RebalanceMode defaultMode) {
+    RebalanceMode rebalanceMode = defaultMode;
+    try {
+      rebalanceMode = RebalanceMode.valueOf(mode);
+    } catch (Exception rebalanceModeException) {
+      try {
+        IdealStateModeProperty oldMode = IdealStateModeProperty.valueOf(mode);
+        rebalanceMode = normalizeRebalanceMode(oldMode);
+      } catch (Exception e) {
+        logger.error(e);
+      }
+    }
+    return rebalanceMode;
+  }
+
+  /**
    * Convert a preference list of strings into a preference list of participants
    * @param rawPreferenceList the list of strings representing participant names
    * @return converted list


[2/2] git commit: [HELIX-100] IdealState compatibility with RebalancerContext

Posted by ka...@apache.org.
[HELIX-100] IdealState compatibility with RebalancerContext


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

Branch: refs/heads/helix-logical-model
Commit: 5e2fc9352f63758f6bfda12200e71931ba72feaa
Parents: b0c1cb0
Author: Kanak Biscuitwala <ka...@apache.org>
Authored: Mon Sep 30 10:37:13 2013 -0700
Committer: Kanak Biscuitwala <ka...@apache.org>
Committed: Mon Sep 30 10:37:13 2013 -0700

----------------------------------------------------------------------
 .../main/java/org/apache/helix/api/Resource.java    | 16 +---------------
 .../apache/helix/api/accessor/ClusterAccessor.java  |  6 +++++-
 .../apache/helix/api/accessor/ResourceAccessor.java | 13 +++++++++++++
 .../context/PartitionedRebalancerContext.java       |  9 +++++++--
 4 files changed, 26 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/5e2fc935/helix-core/src/main/java/org/apache/helix/api/Resource.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/api/Resource.java b/helix-core/src/main/java/org/apache/helix/api/Resource.java
index e9d07bd..589c8a6 100644
--- a/helix-core/src/main/java/org/apache/helix/api/Resource.java
+++ b/helix-core/src/main/java/org/apache/helix/api/Resource.java
@@ -20,14 +20,13 @@ package org.apache.helix.api;
  */
 
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
 import org.apache.helix.api.config.ResourceConfig;
+import org.apache.helix.api.config.ResourceConfig.ResourceType;
 import org.apache.helix.api.config.SchedulerTaskConfig;
 import org.apache.helix.api.config.UserConfig;
-import org.apache.helix.api.config.ResourceConfig.ResourceType;
 import org.apache.helix.api.id.PartitionId;
 import org.apache.helix.api.id.ResourceId;
 import org.apache.helix.api.id.StateModelDefId;
@@ -62,19 +61,6 @@ public class Resource {
       ResourceAssignment resourceAssignment, ExternalView externalView,
       RebalancerContext rebalancerContext, UserConfig userConfig, int bucketSize,
       boolean batchMessageMode) {
-    Map<PartitionId, Partition> partitionMap = new HashMap<PartitionId, Partition>();
-    new HashMap<PartitionId, Map<String, String>>();
-    Set<PartitionId> partitionSet = idealState.getPartitionSet();
-    if (partitionSet.isEmpty() && idealState.getNumPartitions() > 0) {
-      partitionSet = new HashSet<PartitionId>();
-      for (int i = 0; i < idealState.getNumPartitions(); i++) {
-        partitionSet.add(PartitionId.from(id, Integer.toString(i)));
-      }
-    }
-    for (PartitionId partitionId : partitionSet) {
-      partitionMap.put(partitionId, new Partition(partitionId));
-    }
-
     SchedulerTaskConfig schedulerTaskConfig = schedulerTaskConfig(idealState);
     RebalancerConfig rebalancerConfig = new RebalancerConfig(rebalancerContext);
 

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/5e2fc935/helix-core/src/main/java/org/apache/helix/api/accessor/ClusterAccessor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/api/accessor/ClusterAccessor.java b/helix-core/src/main/java/org/apache/helix/api/accessor/ClusterAccessor.java
index 5a5400e..3047c34 100644
--- a/helix-core/src/main/java/org/apache/helix/api/accessor/ClusterAccessor.java
+++ b/helix-core/src/main/java/org/apache/helix/api/accessor/ClusterAccessor.java
@@ -61,6 +61,7 @@ import org.apache.helix.model.ResourceAssignment;
 import org.apache.helix.model.ResourceConfiguration;
 import org.apache.helix.model.StateModelDefinition;
 import org.apache.log4j.Logger;
+import org.testng.internal.annotations.Sets;
 
 public class ClusterAccessor {
   private static Logger LOG = Logger.getLogger(ClusterAccessor.class);
@@ -244,8 +245,11 @@ public class ClusterAccessor {
         _accessor.getChildValuesMap(_keyBuilder.resourceAssignments());
 
     // read all the resources
+    Set<String> allResources = Sets.newHashSet();
+    allResources.addAll(idealStateMap.keySet());
+    allResources.addAll(resourceConfigMap.keySet());
     Map<ResourceId, Resource> resourceMap = new HashMap<ResourceId, Resource>();
-    for (String resourceName : idealStateMap.keySet()) {
+    for (String resourceName : allResources) {
       ResourceId resourceId = ResourceId.from(resourceName);
       resourceMap.put(resourceId, ResourceAccessor.createResource(resourceId,
           resourceConfigMap.get(resourceName), idealStateMap.get(resourceName),

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/5e2fc935/helix-core/src/main/java/org/apache/helix/api/accessor/ResourceAccessor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/api/accessor/ResourceAccessor.java b/helix-core/src/main/java/org/apache/helix/api/accessor/ResourceAccessor.java
index de38453..7fd901f 100644
--- a/helix-core/src/main/java/org/apache/helix/api/accessor/ResourceAccessor.java
+++ b/helix-core/src/main/java/org/apache/helix/api/accessor/ResourceAccessor.java
@@ -19,14 +19,20 @@ package org.apache.helix.api.accessor;
  * under the License.
  */
 
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
 import org.apache.helix.HelixConstants.StateModelToken;
 import org.apache.helix.HelixDataAccessor;
 import org.apache.helix.PropertyKey;
 import org.apache.helix.api.Resource;
 import org.apache.helix.api.Scope;
+import org.apache.helix.api.State;
 import org.apache.helix.api.config.ResourceConfig;
 import org.apache.helix.api.config.ResourceConfig.ResourceType;
 import org.apache.helix.api.config.UserConfig;
+import org.apache.helix.api.id.ParticipantId;
 import org.apache.helix.api.id.PartitionId;
 import org.apache.helix.api.id.ResourceId;
 import org.apache.helix.controller.rebalancer.context.CustomRebalancerContext;
@@ -278,6 +284,13 @@ public class ResourceAccessor {
           idealState.setParticipantStateMap(partitionId,
               customContext.getPreferenceMap(partitionId));
         }
+      } else {
+        for (PartitionId partitionId : partitionedContext.getPartitionSet()) {
+          List<ParticipantId> preferenceList = Collections.emptyList();
+          idealState.setPreferenceList(partitionId, preferenceList);
+          Map<ParticipantId, State> participantStateMap = Collections.emptyMap();
+          idealState.setParticipantStateMap(partitionId, participantStateMap);
+        }
       }
       return idealState;
     }

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/5e2fc935/helix-core/src/main/java/org/apache/helix/controller/rebalancer/context/PartitionedRebalancerContext.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/context/PartitionedRebalancerContext.java b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/context/PartitionedRebalancerContext.java
index b24125c..d428a5e 100644
--- a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/context/PartitionedRebalancerContext.java
+++ b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/context/PartitionedRebalancerContext.java
@@ -206,8 +206,13 @@ public class PartitionedRebalancerContext extends BasicRebalancerContext impleme
     } else {
       replicaCount = Integer.parseInt(replicas);
     }
-    for (PartitionId partitionId : idealState.getPartitionSet()) {
-      builder.addPartition(new Partition(partitionId));
+    if (idealState.getNumPartitions() > 0 && idealState.getPartitionSet().size() == 0) {
+      // backwards compatibility: partition sets were based on pref lists/maps previously
+      builder.addPartitions(idealState.getNumPartitions());
+    } else {
+      for (PartitionId partitionId : idealState.getPartitionSet()) {
+        builder.addPartition(new Partition(partitionId));
+      }
     }
     builder.anyLiveParticipant(anyLiveParticipant).replicaCount(replicaCount)
         .maxPartitionsPerParticipant(idealState.getMaxPartitionsPerInstance())