helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ka...@apache.org
Subject [2/2] git commit: [HELIX-100] IdealState compatibility with RebalancerContext
Date Mon, 30 Sep 2013 17:38:18 GMT
[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 <kanak@apache.org>
Authored: Mon Sep 30 10:37:13 2013 -0700
Committer: Kanak Biscuitwala <kanak@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())


Mime
View raw message