You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by ji...@apache.org on 2021/01/12 22:52:55 UTC

[helix] branch master updated: Fix the IdealStateBuilder to set the correct instance group tag. (#1607)

This is an automated email from the ASF dual-hosted git repository.

jiajunwang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git


The following commit(s) were added to refs/heads/master by this push:
     new 862bee9  Fix the IdealStateBuilder to set the correct instance group tag. (#1607)
862bee9 is described below

commit 862bee9875f61609f0b31ba1250a3368245b379b
Author: Jiajun Wang <jj...@linkedin.com>
AuthorDate: Tue Jan 12 14:52:43 2021 -0800

    Fix the IdealStateBuilder to set the correct instance group tag. (#1607)
    
    This PR aims to simply fix the issue that IdealStateBuilder class ignores the input instance group tag.
---
 .../org/apache/helix/model/builder/IdealStateBuilder.java   | 13 +++++++++----
 .../apache/helix/model/builder/TestIdealStateBuilder.java   |  5 +++--
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/helix-core/src/main/java/org/apache/helix/model/builder/IdealStateBuilder.java b/helix-core/src/main/java/org/apache/helix/model/builder/IdealStateBuilder.java
index f841b13..a49d246 100644
--- a/helix-core/src/main/java/org/apache/helix/model/builder/IdealStateBuilder.java
+++ b/helix-core/src/main/java/org/apache/helix/model/builder/IdealStateBuilder.java
@@ -29,6 +29,7 @@ public abstract class IdealStateBuilder {
    * Resource name e.g. myDB,
    */
   private String resourceName;
+
   /**
    * Number of partitions/subresources
    */
@@ -39,7 +40,6 @@ public abstract class IdealStateBuilder {
    */
   private int numReplica;
 
-
   /**
    * Number of minimal active replicas for each partition
    */
@@ -59,6 +59,7 @@ public abstract class IdealStateBuilder {
    * State model that is applicable for this resource
    */
   private String stateModel;
+
   /**
    * The state model factory implementation in the participant. Allows
    * participants to plugin resource specific implementation, by default Helix
@@ -66,6 +67,7 @@ public abstract class IdealStateBuilder {
    * This is optional
    */
   private String stateModelFactoryName = HelixConstants.DEFAULT_STATE_MODEL_FACTORY;
+
   /**
    * Helix rebalancer strategies. AUTO, SEMI_AUTO, CUSTOMIZED
    */
@@ -85,12 +87,13 @@ public abstract class IdealStateBuilder {
    * A constraint that limits the maximum number of partitions per Node.
    */
   private int maxPartitionsPerNode;
+
   /**
    * Allocate the resource to nodes that are tagged with a specific "nodeGroup"
    * name. By default a resource will be allocated to all nodes registered to
    * the cluster.
    */
-  private String nodeGroup = "*";
+  private String nodeGroup = null;
 
   /**
    * Whether to disable external view for this resource
@@ -107,13 +110,11 @@ public abstract class IdealStateBuilder {
    */
   private Boolean enableGroupRouting = null;
 
-
   /**
    * Resource Type
    */
   private String resourceType;
 
-
   protected ZNRecord _record;
 
   /**
@@ -315,6 +316,10 @@ public abstract class IdealStateBuilder {
       idealstate.setDelayRebalanceEnabled(delayRebalanceEnabled);
     }
 
+    if (nodeGroup != null) {
+      idealstate.setInstanceGroupTag(nodeGroup);
+    }
+
     if (!idealstate.isValid()) {
       throw new HelixException("invalid ideal-state: " + idealstate);
     }
diff --git a/helix-core/src/test/java/org/apache/helix/model/builder/TestIdealStateBuilder.java b/helix-core/src/test/java/org/apache/helix/model/builder/TestIdealStateBuilder.java
index cc52799..3c1e44c 100644
--- a/helix-core/src/test/java/org/apache/helix/model/builder/TestIdealStateBuilder.java
+++ b/helix-core/src/test/java/org/apache/helix/model/builder/TestIdealStateBuilder.java
@@ -44,8 +44,9 @@ public class TestIdealStateBuilder {
 
   @Test
   public void testFullAutoModeISModeBuilder() {
+    String nodeGroup = "groupA";
     FullAutoModeISBuilder builder = new FullAutoModeISBuilder("test-db");
-    builder.setStateModel("MasterSlave").setNumPartitions(2).setNumReplica(2);
+    builder.setStateModel("MasterSlave").setNumPartitions(2).setNumReplica(2).setNodeGroup(nodeGroup);
     builder.add("test-db_0").add("test-db_1");
 
     IdealState idealState = null;
@@ -57,7 +58,7 @@ public class TestIdealStateBuilder {
     // System.out.println("ideal-state: " + idealState);
     Assert.assertEquals(idealState.getRebalanceMode(), IdealState.RebalanceMode.FULL_AUTO,
         "rebalancer mode should be auto");
-
+    Assert.assertEquals(idealState.getInstanceGroupTag(), nodeGroup);
   }
 
   @Test