helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ka...@apache.org
Subject [1/2] git commit: [HELIX-290] Prefer ideal state for 0.7.0 rebalancer if not user defined, rb=15381
Date Mon, 11 Nov 2013 22:12:11 GMT
Updated Branches:
  refs/heads/master ebd37fed4 -> 00ff8c06c


[HELIX-290] Prefer ideal state for 0.7.0 rebalancer if not user defined, rb=15381


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

Branch: refs/heads/master
Commit: 0cb3775564cb53c4129b9afcaecc0876a33a120f
Parents: ea8c61d
Author: Kanak Biscuitwala <kanak@apache.org>
Authored: Fri Nov 8 16:03:24 2013 -0800
Committer: Kanak Biscuitwala <kanak@apache.org>
Committed: Mon Nov 11 14:09:17 2013 -0800

----------------------------------------------------------------------
 .../helix/api/accessor/ResourceAccessor.java    |  8 ++++--
 .../context/CustomRebalancerContext.java        |  3 +-
 .../context/FullAutoRebalancerContext.java      |  3 +-
 .../context/PartitionedRebalancerContext.java   | 30 ++++++++++++++++----
 .../context/SemiAutoRebalancerContext.java      |  8 +++---
 5 files changed, 38 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/0cb37755/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 0dfceca..e5ac57c 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
@@ -436,12 +436,14 @@ public class ResourceAccessor {
     int bucketSize = 0;
     boolean batchMessageMode = false;
     if (idealState != null) {
-      if (resourceConfiguration != null) {
+      if (resourceConfiguration != null
+          && idealState.getRebalanceMode() != RebalanceMode.USER_DEFINED) {
+        // prefer rebalancer context for non-user_defined data rebalancing
         rebalancerContext =
             resourceConfiguration.getRebalancerContext(PartitionedRebalancerContext.class);
       }
       if (rebalancerContext == null) {
-        // fallback: get rebalancer context from ideal state
+        // prefer ideal state for non-user_defined data rebalancing
         rebalancerContext = PartitionedRebalancerContext.from(idealState);
       }
       bucketSize = idealState.getBucketSize();
@@ -454,7 +456,7 @@ public class ResourceAccessor {
       rebalancerContext = rebalancerConfig.getRebalancerContext(RebalancerContext.class);
     }
     if (rebalancerContext == null) {
-      rebalancerContext = new PartitionedRebalancerContext(RebalanceMode.NONE);
+      rebalancerContext = new PartitionedRebalancerContext();
     }
     return new Resource(resourceId, type, idealState, resourceAssignment, externalView,
         rebalancerContext, userConfig, bucketSize, batchMessageMode);

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/0cb37755/helix-core/src/main/java/org/apache/helix/controller/rebalancer/context/CustomRebalancerContext.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/context/CustomRebalancerContext.java
b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/context/CustomRebalancerContext.java
index 1fc1cda..0d2c1f2 100644
--- a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/context/CustomRebalancerContext.java
+++ b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/context/CustomRebalancerContext.java
@@ -53,7 +53,7 @@ public class CustomRebalancerContext extends PartitionedRebalancerContext
{
    * Instantiate a CustomRebalancerContext
    */
   public CustomRebalancerContext() {
-    super(RebalanceMode.CUSTOMIZED);
+    setRebalanceMode(RebalanceMode.CUSTOMIZED);
     setRebalancerRef(RebalancerRef.from(CustomRebalancer.class));
     _preferenceMaps = Maps.newHashMap();
   }
@@ -133,6 +133,7 @@ public class CustomRebalancerContext extends PartitionedRebalancerContext
{
     public Builder(ResourceId resourceId) {
       super(resourceId);
       super.rebalancerRef(RebalancerRef.from(CustomRebalancer.class));
+      super.rebalanceMode(RebalanceMode.CUSTOMIZED);
       _preferenceMaps = Maps.newHashMap();
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/0cb37755/helix-core/src/main/java/org/apache/helix/controller/rebalancer/context/FullAutoRebalancerContext.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/context/FullAutoRebalancerContext.java
b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/context/FullAutoRebalancerContext.java
index 2db9ac6..2400707 100644
--- a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/context/FullAutoRebalancerContext.java
+++ b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/context/FullAutoRebalancerContext.java
@@ -30,7 +30,7 @@ import org.apache.helix.model.IdealState.RebalanceMode;
  */
 public class FullAutoRebalancerContext extends PartitionedRebalancerContext {
   public FullAutoRebalancerContext() {
-    super(RebalanceMode.FULL_AUTO);
+    setRebalanceMode(RebalanceMode.FULL_AUTO);
     setRebalancerRef(RebalancerRef.from(FullAutoRebalancer.class));
   }
 
@@ -46,6 +46,7 @@ public class FullAutoRebalancerContext extends PartitionedRebalancerContext
{
     public Builder(ResourceId resourceId) {
       super(resourceId);
       super.rebalancerRef(RebalancerRef.from(FullAutoRebalancer.class));
+      super.rebalanceMode(RebalanceMode.FULL_AUTO);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/0cb37755/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 9d24e68..15fcf9c 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
@@ -49,17 +49,17 @@ public class PartitionedRebalancerContext extends BasicRebalancerContext
impleme
   private boolean _anyLiveParticipant;
   private int _replicaCount;
   private int _maxPartitionsPerParticipant;
-  private final RebalanceMode _rebalanceMode;
+  private RebalanceMode _rebalanceMode;
 
   /**
    * Instantiate a DataRebalancerContext
    */
-  public PartitionedRebalancerContext(RebalanceMode rebalanceMode) {
+  public PartitionedRebalancerContext() {
     _partitionMap = Collections.emptyMap();
     _replicaCount = 1;
     _anyLiveParticipant = false;
     _maxPartitionsPerParticipant = Integer.MAX_VALUE;
-    _rebalanceMode = rebalanceMode;
+    _rebalanceMode = RebalanceMode.USER_DEFINED;
   }
 
   /**
@@ -140,6 +140,14 @@ public class PartitionedRebalancerContext extends BasicRebalancerContext
impleme
   }
 
   /**
+   * Set the rebalancer mode of the partitioned resource
+   * @param rebalanceMode {@link RebalanceMode} enum value
+   */
+  public void setRebalanceMode(RebalanceMode rebalanceMode) {
+    _rebalanceMode = rebalanceMode;
+  }
+
+  /**
    * Get the rebalancer mode of the resource
    * @return RebalanceMode
    */
@@ -258,8 +266,7 @@ public class PartitionedRebalancerContext extends BasicRebalancerContext
impleme
 
     @Override
     public PartitionedRebalancerContext build() {
-      PartitionedRebalancerContext context =
-          new PartitionedRebalancerContext(RebalanceMode.USER_DEFINED);
+      PartitionedRebalancerContext context = new PartitionedRebalancerContext();
       super.update(context);
       return context;
     }
@@ -272,6 +279,7 @@ public class PartitionedRebalancerContext extends BasicRebalancerContext
impleme
       extends BasicRebalancerContext.AbstractBuilder<T> {
     private final ResourceId _resourceId;
     private final Map<PartitionId, Partition> _partitionMap;
+    private RebalanceMode _rebalanceMode;
     private boolean _anyLiveParticipant;
     private int _replicaCount;
     private int _maxPartitionsPerParticipant;
@@ -284,12 +292,23 @@ public class PartitionedRebalancerContext extends BasicRebalancerContext
impleme
       super(resourceId);
       _resourceId = resourceId;
       _partitionMap = Maps.newHashMap();
+      _rebalanceMode = RebalanceMode.USER_DEFINED;
       _anyLiveParticipant = false;
       _replicaCount = 1;
       _maxPartitionsPerParticipant = Integer.MAX_VALUE;
     }
 
     /**
+     * Set the rebalance mode for a partitioned rebalancer context
+     * @param rebalanceMode {@link RebalanceMode} enum value
+     * @return Builder
+     */
+    public T rebalanceMode(RebalanceMode rebalanceMode) {
+      _rebalanceMode = rebalanceMode;
+      return self();
+    }
+
+    /**
      * Add a partition that the resource serves
      * @param partition fully-qualified partition
      * @return Builder
@@ -364,6 +383,7 @@ public class PartitionedRebalancerContext extends BasicRebalancerContext
impleme
       if (_partitionMap.isEmpty()) {
         addPartitions(1);
       }
+      context.setRebalanceMode(_rebalanceMode);
       context.setPartitionMap(_partitionMap);
       context.setAnyLiveParticipant(_anyLiveParticipant);
       context.setMaxPartitionsPerParticipant(_maxPartitionsPerParticipant);

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/0cb37755/helix-core/src/main/java/org/apache/helix/controller/rebalancer/context/SemiAutoRebalancerContext.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/context/SemiAutoRebalancerContext.java
b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/context/SemiAutoRebalancerContext.java
index f574a62..afa81e2 100644
--- a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/context/SemiAutoRebalancerContext.java
+++ b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/context/SemiAutoRebalancerContext.java
@@ -56,7 +56,7 @@ public final class SemiAutoRebalancerContext extends PartitionedRebalancerContex
    * Instantiate a SemiAutoRebalancerContext
    */
   public SemiAutoRebalancerContext() {
-    super(RebalanceMode.SEMI_AUTO);
+    setRebalanceMode(RebalanceMode.SEMI_AUTO);
     setRebalancerRef(RebalancerRef.from(SemiAutoRebalancer.class));
     _preferenceLists = Maps.newHashMap();
   }
@@ -110,9 +110,8 @@ public final class SemiAutoRebalancerContext extends PartitionedRebalancerContex
         Set<ParticipantId> disabledParticipants = Collections.emptySet();
         Map<ParticipantId, State> emptyCurrentState = Collections.emptyMap();
         Map<ParticipantId, State> initialMap =
-            ConstraintBasedAssignment.computeAutoBestStateForPartition(upperBounds,
-                participantSet, stateModelDef, preferenceList, emptyCurrentState,
-                disabledParticipants);
+            ConstraintBasedAssignment.computeAutoBestStateForPartition(upperBounds, participantSet,
+                stateModelDef, preferenceList, emptyCurrentState, disabledParticipants);
         currentMapping.put(partitionId, initialMap);
       }
     }
@@ -148,6 +147,7 @@ public final class SemiAutoRebalancerContext extends PartitionedRebalancerContex
     public Builder(ResourceId resourceId) {
       super(resourceId);
       super.rebalancerRef(RebalancerRef.from(SemiAutoRebalancer.class));
+      super.rebalanceMode(RebalanceMode.SEMI_AUTO);
       _preferenceLists = Maps.newHashMap();
     }
 


Mime
View raw message