Skip to content
Permalink
Browse files
HELIX-166: Rename modes to auto, semi-auto, and custom, rb=13444
  • Loading branch information
zzhang5 committed Aug 15, 2013
1 parent f38b3da commit 13d19e914e7deec29c5cd665e75df12eafbce1b1
Show file tree
Hide file tree
Showing 41 changed files with 458 additions and 179 deletions.
@@ -25,7 +25,7 @@
import org.apache.helix.HelixException;
import org.apache.helix.ZNRecord;
import org.apache.helix.manager.zk.ZkClient;
import org.apache.helix.model.IdealState.IdealStateModeProperty;
import org.apache.helix.model.IdealState.RebalanceMode;
import org.apache.helix.tools.ClusterSetup;
import org.apache.helix.webapp.RestAdminApplication;
import org.apache.log4j.Logger;
@@ -140,7 +140,7 @@ public void acceptRepresentation(Representation entity)
jsonParameters.getParameter(JsonParameters.STATE_MODEL_DEF_REF);
int partitions =
Integer.parseInt(jsonParameters.getParameter(JsonParameters.PARTITIONS));
String mode = IdealStateModeProperty.AUTO.toString();
String mode = RebalanceMode.SEMI_AUTO.toString();
if (jsonParameters.getParameter(JsonParameters.IDEAL_STATE_MODE) != null)
{
mode = jsonParameters.getParameter(JsonParameters.IDEAL_STATE_MODE);
@@ -115,13 +115,13 @@ void addResource(String clusterName,
* @param resourceName
* @param numPartitions
* @param stateModelRef
* @param idealStateMode
* @param rebalancerMode
*/
void addResource(String clusterName,
String resourceName,
int numPartitions,
String stateModelRef,
String idealStateMode);
String rebalancerMode);

/**
* Add a resource to a cluster, using a bucket size > 1
@@ -130,14 +130,14 @@ void addResource(String clusterName,
* @param resourceName
* @param numPartitions
* @param stateModelRef
* @param idealStateMode
* @param rebalancerMode
* @param bucketSize
*/
void addResource(String clusterName,
String resourceName,
int numPartitions,
String stateModelRef,
String idealStateMode,
String rebalancerMode,
int bucketSize);

/**
@@ -147,15 +147,15 @@ void addResource(String clusterName,
* @param resourceName
* @param numPartitions
* @param stateModelRef
* @param idealStateMode
* @param rebalancerMode
* @param bucketSize
* @param maxPartitionsPerInstance
*/
void addResource(String clusterName,
String resourceName,
int numPartitions,
String stateModelRef,
String idealStateMode,
String rebalancerMode,
int bucketSize,
int maxPartitionsPerInstance);

@@ -41,11 +41,11 @@
import org.apache.helix.controller.strategy.AutoRebalanceStrategy.ReplicaPlacementScheme;
import org.apache.helix.model.CurrentState;
import org.apache.helix.model.IdealState;
import org.apache.helix.model.IdealState.RebalanceMode;
import org.apache.helix.model.LiveInstance;
import org.apache.helix.model.Partition;
import org.apache.helix.model.Resource;
import org.apache.helix.model.StateModelDefinition;
import org.apache.helix.model.IdealState.IdealStateModeProperty;
import org.apache.log4j.Logger;

/**
@@ -112,7 +112,7 @@ public IdealState computeNewIdealState(String resourceName,

IdealState newIdealState = new IdealState(resourceName);
newIdealState.getRecord().setSimpleFields(currentIdealState.getRecord().getSimpleFields());
newIdealState.setIdealStateMode(IdealStateModeProperty.AUTO_REBALANCE.toString());
newIdealState.setRebalanceMode(RebalanceMode.FULL_AUTO);
newIdealState.getRecord().setListFields(newMapping.getListFields());
return newIdealState;
}
@@ -20,6 +20,7 @@
*/

import java.util.Map;

import org.apache.helix.controller.pipeline.AbstractBaseStage;
import org.apache.helix.controller.pipeline.StageException;
import org.apache.helix.controller.rebalancer.AutoRebalancer;
@@ -29,8 +30,8 @@
import org.apache.helix.model.IdealState;
import org.apache.helix.model.Partition;
import org.apache.helix.model.Resource;
import org.apache.helix.model.IdealState.IdealStateModeProperty;
import org.apache.helix.model.IdealState.IdealStateProperty;
import org.apache.helix.model.IdealState.RebalanceMode;
import org.apache.helix.util.HelixUtil;
import org.apache.log4j.Logger;

@@ -120,11 +121,11 @@ private BestPossibleStateOutput compute(ClusterEvent event,
}
if (rebalancer == null)
{
if (idealState.getIdealStateMode() == IdealStateModeProperty.AUTO_REBALANCE)
if (idealState.getRebalanceMode() == RebalanceMode.FULL_AUTO)
{
rebalancer = new AutoRebalancer();
}
else if (idealState.getIdealStateMode() == IdealStateModeProperty.AUTO)
else if (idealState.getRebalanceMode() == RebalanceMode.SEMI_AUTO)
{
rebalancer = new SemiAutoRebalancer();
}
@@ -54,7 +54,8 @@ public void process(ClusterEvent event) throws Exception
for(String resourceName : idealStateMap.keySet())
{
IdealState currentIdealState = idealStateMap.get(resourceName);
if(currentIdealState.getRecord().getSimpleFields().containsKey(IdealStateProperty.REBALANCER_CLASS_NAME.toString()))
if(currentIdealState.getRecord().getSimpleFields().containsKey(
IdealStateProperty.REBALANCER_CLASS_NAME.toString()))
{
String rebalancerClassName = currentIdealState.getRebalancerClassName();
LOG.info("resource " + resourceName + " use idealStateRebalancer " + rebalancerClassName);
@@ -24,9 +24,9 @@
import org.apache.helix.manager.zk.ZNRecordSerializer;
import org.apache.helix.manager.zk.ZkClient;
import org.apache.helix.model.IdealState;
import org.apache.helix.model.IdealState.RebalanceMode;
import org.apache.helix.model.InstanceConfig;
import org.apache.helix.model.StateModelDefinition;
import org.apache.helix.model.IdealState.IdealStateModeProperty;
import org.apache.helix.model.builder.AutoModeISBuilder;
import org.apache.helix.model.builder.AutoRebalanceModeISBuilder;
import org.apache.helix.model.builder.CustomModeISBuilder;
@@ -41,13 +41,14 @@ private static String buildPartitionName(String resourceName, int partitionNum)
public static void main(String[] args) {

if (args.length < 3) {
System.err.println("USAGE: java IdealStateBuilderExample zkAddress clusterName idealStateMode (AUTO, AUTO_REBALANCE, or CUSTOMIZED)");
System.err.println("USAGE: java IdealStateBuilderExample zkAddress clusterName idealStateMode" +
" (FULL_AUTO, SEMI_AUTO, CUSTOMIZED, or USER_DEFINED)");
System.exit(1);
}

final String zkAddr = args[0];
final String clusterName = args[1];
IdealStateModeProperty idealStateMode = IdealStateModeProperty.valueOf(args[2].toUpperCase());
RebalanceMode idealStateMode = RebalanceMode.valueOf(args[2].toUpperCase());

ZkClient zkclient =
new ZkClient(zkAddr,
@@ -79,7 +80,7 @@ public static void main(String[] args) {
String resourceName = "TestDB";
IdealState idealState = null;
switch (idealStateMode) {
case AUTO: {
case SEMI_AUTO: {
AutoModeISBuilder builder = new AutoModeISBuilder(resourceName);
builder.setStateModel("MasterSlave")
.setNumPartitions(2)
@@ -90,7 +91,7 @@ public static void main(String[] args) {
idealState = builder.build();
break;
}
case AUTO_REBALANCE: {
case FULL_AUTO: {
AutoRebalanceModeISBuilder builder = new AutoRebalanceModeISBuilder(resourceName);
builder.setStateModel("MasterSlave")
.setNumPartitions(2)
@@ -23,7 +23,7 @@
import org.apache.helix.manager.zk.ZKHelixAdmin;
import org.apache.helix.manager.zk.ZNRecordSerializer;
import org.apache.helix.manager.zk.ZkClient;
import org.apache.helix.model.IdealState.IdealStateModeProperty;
import org.apache.helix.model.IdealState.RebalanceMode;
import org.apache.helix.model.InstanceConfig;
import org.apache.helix.model.StateModelDefinition;
import org.apache.helix.tools.StateModelConfigGenerator;
@@ -78,17 +78,17 @@ public static void main(String[] args) throws Exception
{
if (args.length < 3)
{
System.err.println("USAGE: IdealStateExample zkAddress clusterName idealStateMode (AUTO, AUTO_REBALANCE, or CUSTOMIZED) idealStateJsonFile (required for CUSTOMIZED mode)");
System.err.println("USAGE: IdealStateExample zkAddress clusterName idealStateMode (FULL_AUTO, SEMI_AUTO, or CUSTOMIZED) idealStateJsonFile (required for CUSTOMIZED mode)");
System.exit(1);
}

final String zkAddr = args[0];
final String clusterName = args[1];
final String idealStateModeStr = args[2].toUpperCase();
final String idealStateRebalancerModeStr = args[2].toUpperCase();
String idealStateJsonFile = null;
IdealStateModeProperty idealStateMode =
IdealStateModeProperty.valueOf(idealStateModeStr);
if (idealStateMode == IdealStateModeProperty.CUSTOMIZED)
RebalanceMode idealStateRebalancerMode =
RebalanceMode.valueOf(idealStateRebalancerModeStr);
if (idealStateRebalancerMode == RebalanceMode.CUSTOMIZED)
{
if (args.length < 4)
{
@@ -126,15 +126,15 @@ public static void main(String[] args) throws Exception

// add resource "TestDB" which has 4 partitions and uses MasterSlave state model
String resourceName = "TestDB";
if (idealStateMode == IdealStateModeProperty.AUTO
|| idealStateMode == IdealStateModeProperty.AUTO_REBALANCE)
if (idealStateRebalancerMode == RebalanceMode.SEMI_AUTO
|| idealStateRebalancerMode == RebalanceMode.FULL_AUTO)
{
admin.addResource(clusterName, resourceName, 4, "MasterSlave", idealStateModeStr);
admin.addResource(clusterName, resourceName, 4, "MasterSlave", idealStateRebalancerModeStr);

// rebalance resource "TestDB" using 3 replicas
admin.rebalance(clusterName, resourceName, 3);
}
else if (idealStateMode == IdealStateModeProperty.CUSTOMIZED)
else if (idealStateRebalancerMode == RebalanceMode.CUSTOMIZED)
{
admin.addIdealState(clusterName, resourceName, idealStateJsonFile);
}
@@ -64,7 +64,7 @@
import org.apache.helix.model.HelixConfigScope;
import org.apache.helix.model.HelixConfigScope.ConfigScopeProperty;
import org.apache.helix.model.IdealState;
import org.apache.helix.model.IdealState.IdealStateModeProperty;
import org.apache.helix.model.IdealState.RebalanceMode;
import org.apache.helix.model.InstanceConfig;
import org.apache.helix.model.InstanceConfig.InstanceConfigProperty;
import org.apache.helix.model.LiveInstance;
@@ -274,8 +274,10 @@ public void enablePartition(final boolean enabled,
IdealState idealState = new IdealState(idealStateRecord);
for (String partitionName : partitionNames)
{
if ((idealState.getIdealStateMode() == IdealStateModeProperty.AUTO && idealState.getPreferenceList(partitionName) == null)
|| (idealState.getIdealStateMode() == IdealStateModeProperty.CUSTOMIZED && idealState.getInstanceStateMap(partitionName) == null))
if ((idealState.getRebalanceMode() == RebalanceMode.SEMI_AUTO
&& idealState.getPreferenceList(partitionName) == null)
|| (idealState.getRebalanceMode() == RebalanceMode.CUSTOMIZED
&& idealState.getInstanceStateMap(partitionName) == null))
{
logger.warn("Cluster: " + clusterName + ", resource: " + resourceName
+ ", partition: " + partitionName
@@ -373,7 +375,7 @@ public void resetPartition(String clusterName,

// check partition exists in resource group
Set<String> resetPartitionNames = new HashSet<String>(partitionNames);
if (idealState.getIdealStateMode() == IdealStateModeProperty.CUSTOMIZED)
if (idealState.getRebalanceMode() == RebalanceMode.CUSTOMIZED)
{
Set<String> partitions =
new HashSet<String>(idealState.getRecord().getMapFields().keySet());
@@ -700,7 +702,7 @@ public void addResource(String clusterName,
resourceName,
partitions,
stateModelRef,
IdealStateModeProperty.AUTO.toString(),
RebalanceMode.SEMI_AUTO.toString(),
0);
}

@@ -709,9 +711,9 @@ public void addResource(String clusterName,
String resourceName,
int partitions,
String stateModelRef,
String idealStateMode)
String rebalancerMode)
{
addResource(clusterName, resourceName, partitions, stateModelRef, idealStateMode, 0);
addResource(clusterName, resourceName, partitions, stateModelRef, rebalancerMode, 0);
}

@Override
@@ -746,28 +748,28 @@ public void addResource(String clusterName,
String resourceName,
int partitions,
String stateModelRef,
String idealStateMode,
String rebalancerMode,
int bucketSize)
{
addResource(clusterName, resourceName, partitions, stateModelRef, idealStateMode,
addResource(clusterName, resourceName, partitions, stateModelRef, rebalancerMode,
bucketSize, -1);

}

@Override
public void addResource(String clusterName, String resourceName,
int partitions, String stateModelRef, String idealStateMode,
int partitions, String stateModelRef, String rebalancerMode,
int bucketSize, int maxPartitionsPerInstance)
{
if (!ZKUtil.isClusterSetup(clusterName, _zkClient))
{
throw new HelixException("cluster " + clusterName + " is not setup yet");
}

IdealStateModeProperty mode = IdealStateModeProperty.AUTO;
RebalanceMode mode = RebalanceMode.SEMI_AUTO;
try
{
mode = IdealStateModeProperty.valueOf(idealStateMode);
mode = RebalanceMode.valueOf(rebalancerMode);
}
catch (Exception e)
{
@@ -776,7 +778,7 @@ public void addResource(String clusterName, String resourceName,
IdealState idealState = new IdealState(resourceName);
idealState.setNumPartitions(partitions);
idealState.setStateModelDefRef(stateModelRef);
idealState.setIdealStateMode(mode.toString());
idealState.setRebalanceMode(mode);
idealState.setReplicas("" + 0);
idealState.setStateModelFactoryName(HelixConstants.DEFAULT_STATE_MODEL_FACTORY);
if(maxPartitionsPerInstance > 0 && maxPartitionsPerInstance < Integer.MAX_VALUE)
@@ -1256,7 +1258,7 @@ else if (count.equalsIgnoreCase("N"))
{
masterStateValue = slaveStateValue;
}
if (idealState.getIdealStateMode() != IdealStateModeProperty.AUTO_REBALANCE)
if (idealState.getRebalanceMode() != RebalanceMode.FULL_AUTO)
{
ZNRecord newIdealState =
DefaultIdealStateCalculator.calculateIdealState(instanceNames,
@@ -1267,12 +1269,12 @@ else if (count.equalsIgnoreCase("N"))
slaveStateValue);

// for now keep mapField in AUTO mode and remove listField in CUSTOMIZED mode
if (idealState.getIdealStateMode() == IdealStateModeProperty.AUTO)
if (idealState.getRebalanceMode() == RebalanceMode.SEMI_AUTO)
{
idealState.getRecord().setListFields(newIdealState.getListFields());
idealState.getRecord().setMapFields(newIdealState.getMapFields());
}
if (idealState.getIdealStateMode() == IdealStateModeProperty.CUSTOMIZED)
if (idealState.getRebalanceMode() == RebalanceMode.CUSTOMIZED)
{
idealState.getRecord().setMapFields(newIdealState.getMapFields());
}

0 comments on commit 13d19e9

Please sign in to comment.