当前位置: 首页>>代码示例>>Java>>正文


Java IdealState.setReplicas方法代码示例

本文整理汇总了Java中org.apache.helix.model.IdealState.setReplicas方法的典型用法代码示例。如果您正苦于以下问题:Java IdealState.setReplicas方法的具体用法?Java IdealState.setReplicas怎么用?Java IdealState.setReplicas使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.helix.model.IdealState的用法示例。


在下文中一共展示了IdealState.setReplicas方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doInitialAssignment

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
public IdealState doInitialAssignment(String clusterName, List<String> instanceNames,
    int replicationFactor) {
  IdealState idealState = new IdealState(MySQLConstants.MASTER_SLAVE_RESOURCE_NAME);
  idealState.setStateModelDefRef("MasterSlave");
  idealState.setRebalanceMode(RebalanceMode.CUSTOMIZED);
  if (instanceNames.size() % replicationFactor != 0) {
    LOG.error(String.format(
        "Number of instances (%s) in the cluster must be a multiple of replication factor (%s)",
        instanceNames.size(), replicationFactor));
    return null;
  }
  int numSlices = instanceNames.size() / replicationFactor;
  idealState.setNumPartitions(numSlices);
  idealState.setReplicas(String.valueOf(replicationFactor));
  Collections.sort(instanceNames);
  for (int i = 0; i < numSlices; i++) {
    for (int j = 0; j < replicationFactor; j++) {
      idealState.setPartitionState(MySQLConstants.MASTER_SLAVE_RESOURCE_NAME + "_" + i,
          instanceNames.get(i * replicationFactor + j), (j == 0) ? "MASTER" : "SLAVE");
    }
  }
  LOG.info("Creating initial assignment \n" + idealState);
  _helixAdmin.setResourceIdealState(clusterName, MySQLConstants.MASTER_SLAVE_RESOURCE_NAME,
      idealState);
  return idealState;
}
 
开发者ID:kishoreg,项目名称:fullmatix,代码行数:27,代码来源:ClusterAdmin.java

示例2: addResource

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
@Override
public void addResource(String clusterName, String resourceName, int partitions,
    String stateModelRef, String rebalancerMode, String rebalanceStrategy, int bucketSize,
    int maxPartitionsPerInstance) {
  if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
    throw new HelixException("cluster " + clusterName + " is not setup yet");
  }

  IdealState idealState = new IdealState(resourceName);
  idealState.setNumPartitions(partitions);
  idealState.setStateModelDefRef(stateModelRef);
  RebalanceMode mode =
      idealState.rebalanceModeFromString(rebalancerMode, RebalanceMode.SEMI_AUTO);
  idealState.setRebalanceMode(mode);
  idealState.setRebalanceStrategy(rebalanceStrategy);
  idealState.setReplicas("" + 0);
  idealState.setStateModelFactoryName(HelixConstants.DEFAULT_STATE_MODEL_FACTORY);
  if (maxPartitionsPerInstance > 0 && maxPartitionsPerInstance < Integer.MAX_VALUE) {
    idealState.setMaxPartitionsPerInstance(maxPartitionsPerInstance);
  }
  if (bucketSize > 0) {
    idealState.setBucketSize(bucketSize);
  }
  addResource(clusterName, resourceName, idealState);
}
 
开发者ID:apache,项目名称:helix,代码行数:26,代码来源:ZKHelixAdmin.java

示例3: updateIdealState

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
private IdealState updateIdealState(IdealState idealState, int newNumReplicas) {
  idealState.setReplicas(Integer.toString(newNumReplicas));
  Set<String> segmentIds = idealState.getPartitionSet();
  for (String segmentId : segmentIds) {
    Map<String, String> instanceStateMap = idealState.getInstanceStateMap(segmentId);
    if (instanceStateMap.size() > newNumReplicas) {
      Set<String> keys = instanceStateMap.keySet();
      while (instanceStateMap.size() > newNumReplicas) {
        instanceStateMap.remove(keys.iterator().next());
      }
    } else if (instanceStateMap.size() < newNumReplicas) {
      throw new RuntimeException("Segment " + segmentId + " has " + instanceStateMap.size() +
          " replicas but want changed to " + newNumReplicas);
    }
  }
  return idealState;
}
 
开发者ID:linkedin,项目名称:pinot,代码行数:18,代码来源:PinotNumReplicaChanger.java

示例4: createIdealStateForResourceGroup

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
/**
 * Create an IdealState for a resource that belongs to a resource group We use
 * "resourceGroupName$resourceInstanceTag" as the IdealState znode name to differetiate different
 * resources from the same resourceGroup.
 */
public IdealState createIdealStateForResourceGroup(String resourceGroupName,
    String resourceTag, int numPartition, int replica, String rebalanceMode, String stateModelDefName) {
  String idealStateId = genIdealStateNameWithResourceTag(resourceGroupName, resourceTag);
  IdealState idealState = new IdealState(idealStateId);
  idealState.setNumPartitions(numPartition);
  idealState.setStateModelDefRef(stateModelDefName);
  IdealState.RebalanceMode mode =
      idealState.rebalanceModeFromString(rebalanceMode, IdealState.RebalanceMode.SEMI_AUTO);
  idealState.setRebalanceMode(mode);
  idealState.setReplicas("" + replica);
  idealState.setStateModelFactoryName(HelixConstants.DEFAULT_STATE_MODEL_FACTORY);
  idealState.setResourceGroupName(resourceGroupName);
  idealState.setInstanceGroupTag(resourceTag);
  idealState.enableGroupRouting(true);

  return idealState;
}
 
开发者ID:apache,项目名称:helix,代码行数:23,代码来源:ClusterSetup.java

示例5: setupCluster

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
private void setupCluster(String clusterName, List<String> instanceNames, String dbName,
    int replica, int partitions, int bucketSize) {
  _gSetupTool.addCluster(clusterName, true);
  _gSetupTool.addInstancesToCluster(clusterName,
      instanceNames.toArray(new String[instanceNames.size()]));

  // add a bucketized resource
  ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, _baseAccessor);
  PropertyKey.Builder keyBuilder = accessor.keyBuilder();
  ZNRecord idealStateRec =
      DefaultIdealStateCalculator.calculateIdealState(instanceNames, partitions, replica - 1,
          dbName,
          "MASTER", "SLAVE");
  IdealState idealState = new IdealState(idealStateRec);
  idealState.setBucketSize(bucketSize);
  idealState.setStateModelDefRef("MasterSlave");
  idealState.setRebalanceMode(IdealState.RebalanceMode.CUSTOMIZED);
  idealState.setReplicas(Integer.toString(replica));
  accessor.setProperty(keyBuilder.idealStates(dbName), idealState);

}
 
开发者ID:apache,项目名称:helix,代码行数:22,代码来源:TestBucketizedResource.java

示例6: computeNewIdealState

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
@Override
public IdealState computeNewIdealState(String resourceName, IdealState currentIdealState,
    CurrentStateOutput currentStateOutput, ClusterDataCache clusterData) {
  testRebalancerInvoked = true;
  List<String> liveNodes = Lists.newArrayList(clusterData.getLiveInstances().keySet());
  int i = 0;
  for (String partition : currentIdealState.getPartitionSet()) {
    int index = i++ % liveNodes.size();
    String instance = liveNodes.get(index);
    currentIdealState.getPreferenceList(partition).clear();
    currentIdealState.getPreferenceList(partition).add(instance);

    currentIdealState.getInstanceStateMap(partition).clear();
    currentIdealState.getInstanceStateMap(partition).put(instance, "MASTER");
  }
  currentIdealState.setReplicas("1");
  return currentIdealState;
}
 
开发者ID:apache,项目名称:helix,代码行数:19,代码来源:TestCustomizedIdealStateRebalancer.java

示例7: setupIdealState

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
protected List<IdealState> setupIdealState(String clusterName, int[] nodes, String[] resources,
    int partitions, int replicas) {
  ZKHelixDataAccessor accessor =
      new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
  Builder keyBuilder = accessor.keyBuilder();

  List<IdealState> idealStates = new ArrayList<IdealState>();
  List<String> instances = new ArrayList<String>();
  for (int i : nodes) {
    instances.add("localhost_" + i);
  }

  for (String resourceName : resources) {
    IdealState idealState = new IdealState(resourceName);
    for (int p = 0; p < partitions; p++) {
      List<String> value = new ArrayList<String>();
      for (int r = 0; r < replicas; r++) {
        int n = nodes[(p + r) % nodes.length];
        value.add("localhost_" + n);
      }
      idealState.getRecord().setListField(resourceName + "_" + p, value);
    }

    idealState.setReplicas(Integer.toString(replicas));
    idealState.setStateModelDefRef("MasterSlave");
    idealState.setRebalanceMode(RebalanceMode.SEMI_AUTO);
    idealState.setNumPartitions(partitions);
    idealStates.add(idealState);

    // System.out.println(idealState);
    accessor.setProperty(keyBuilder.idealStates(resourceName), idealState);
  }
  return idealStates;
}
 
开发者ID:apache,项目名称:helix,代码行数:35,代码来源:ZkUnitTestBase.java

示例8: createIS

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
private void createIS(HelixDataAccessor accessor, String resourceId, String stateModelDefRef,
    RebalanceMode rebalanceMode) {
  IdealState idealState = new IdealState(resourceId);
  idealState.setRebalanceMode(rebalanceMode);
  idealState.setStateModelDefRef(stateModelDefRef);
  idealState.setNumPartitions(1);
  idealState.setReplicas("1");
  idealState.getRecord().setListField(resourceId + "_0", ImmutableList.of(PARTICIPANT));
  idealState.getRecord().setMapField(resourceId + "_0", ImmutableMap.of(PARTICIPANT, STATE));
  accessor.setProperty(accessor.keyBuilder().idealStates(resourceId), idealState);
}
 
开发者ID:apache,项目名称:helix,代码行数:12,代码来源:TestResourceValidationStage.java

示例9: testResourceSubset

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
@Test
public void testResourceSubset() throws InterruptedException {
  String testDB = "resource-testDB";
  _setupTool.addResourceToCluster(_clusterName, testDB, 1,
      BuiltInStateModelDefinitions.MasterSlave.name(), RebalanceMode.SEMI_AUTO.toString());

  IdealState idealState = _admin.getResourceIdealState(_clusterName, testDB);
  idealState.setReplicas(Integer.toString(2));
  idealState.getRecord().setListField(testDB + "_0",
      Arrays.asList(_participants[1].getInstanceName(), _participants[2].getInstanceName()));
  _admin.setResourceIdealState(_clusterName, testDB, idealState);

  // Ensure that this passes even when one resource is down
  _admin.enableInstance(_clusterName, "localhost_12918", false);
  Thread.sleep(1000);
  _admin.enableCluster(_clusterName, false);
  _admin.enableInstance(_clusterName, "localhost_12918", true);

  HelixClusterVerifier verifier =
      new BestPossibleExternalViewVerifier.Builder(_clusterName).setZkClient(_gZkClient)
          .setResources(Sets.newHashSet(testDB)).build();
  Assert.assertTrue(verifier.verify());

  verifier = new StrictMatchExternalViewVerifier.Builder(_clusterName).setZkClient(_gZkClient)
      .setResources(Sets.newHashSet(testDB)).build();
  Assert.assertTrue(verifier.verify());

  // But the full cluster verification should fail
  verifier =
      new BestPossibleExternalViewVerifier.Builder(_clusterName).setZkClient(_gZkClient).build();
  Assert.assertFalse(verifier.verify(3000));

  verifier =
      new StrictMatchExternalViewVerifier.Builder(_clusterName).setZkClient(_gZkClient).build();
  Assert.assertFalse(verifier.verify(3000));

  _admin.enableCluster(_clusterName, true);
}
 
开发者ID:apache,项目名称:helix,代码行数:39,代码来源:TestClusterVerifier.java

示例10: rebalance

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
void rebalance(String clusterName, String resourceName, int replica, String keyPrefix,
    List<String> instanceNames, String groupId) {
  // ensure we get the same idealState with the same set of instances
  Collections.sort(instanceNames);

  IdealState idealState = getResourceIdealState(clusterName, resourceName);
  if (idealState == null) {
    throw new HelixException("Resource: " + resourceName + " has NOT been added yet");
  }

  if (groupId != null && groupId.length() > 0) {
    idealState.setInstanceGroupTag(groupId);
  }
  idealState.setReplicas(Integer.toString(replica));
  int partitions = idealState.getNumPartitions();
  String stateModelName = idealState.getStateModelDefRef();
  StateModelDefinition stateModDef = getStateModelDef(clusterName, stateModelName);

  if (stateModDef == null) {
    throw new HelixException("cannot find state model: " + stateModelName);
  }
  // StateModelDefinition def = new StateModelDefinition(stateModDef);

  List<String> statePriorityList = stateModDef.getStatesPriorityList();

  String masterStateValue = null;
  String slaveStateValue = null;
  replica--;

  for (String state : statePriorityList) {
    String count = stateModDef.getNumInstancesPerState(state);
    if (count.equals("1")) {
      if (masterStateValue != null) {
        throw new HelixException("Invalid or unsupported state model definition");
      }
      masterStateValue = state;
    } else if (count.equalsIgnoreCase("R")) {
      if (slaveStateValue != null) {
        throw new HelixException("Invalid or unsupported state model definition");
      }
      slaveStateValue = state;
    } else if (count.equalsIgnoreCase("N")) {
      if (!(masterStateValue == null && slaveStateValue == null)) {
        throw new HelixException("Invalid or unsupported state model definition");
      }
      replica = instanceNames.size() - 1;
      masterStateValue = slaveStateValue = state;
    }
  }
  if (masterStateValue == null && slaveStateValue == null) {
    throw new HelixException("Invalid or unsupported state model definition");
  }

  if (masterStateValue == null) {
    masterStateValue = slaveStateValue;
  }
  if (idealState.getRebalanceMode() != RebalanceMode.FULL_AUTO
      && idealState.getRebalanceMode() != RebalanceMode.USER_DEFINED) {
    ZNRecord newIdealState = DefaultIdealStateCalculator
        .calculateIdealState(instanceNames, partitions, replica, keyPrefix, masterStateValue,
            slaveStateValue);

    // for now keep mapField in SEMI_AUTO mode and remove listField in CUSTOMIZED mode
    if (idealState.getRebalanceMode() == RebalanceMode.SEMI_AUTO) {
      idealState.getRecord().setListFields(newIdealState.getListFields());
      // TODO: need consider to remove this.
      idealState.getRecord().setMapFields(newIdealState.getMapFields());
    }
    if (idealState.getRebalanceMode() == RebalanceMode.CUSTOMIZED) {
      idealState.getRecord().setMapFields(newIdealState.getMapFields());
    }
  } else {
    for (int i = 0; i < partitions; i++) {
      String partitionName = keyPrefix + "_" + i;
      idealState.getRecord().setMapField(partitionName, new HashMap<String, String>());
      idealState.getRecord().setListField(partitionName, new ArrayList<String>());
    }
  }
  setResourceIdealState(clusterName, resourceName, idealState);
}
 
开发者ID:apache,项目名称:helix,代码行数:81,代码来源:ZKHelixAdmin.java

示例11: build

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
/**
 * @return
 */
public IdealState build() {
  IdealState idealstate = new IdealState(_record);
  idealstate.setNumPartitions(numPartitions);
  idealstate.setStateModelDefRef(stateModel);
  idealstate.setStateModelFactoryName(stateModelFactoryName);
  idealstate.setRebalanceMode(rebalancerMode);
  idealstate.setReplicas("" + numReplica);

  if (minActiveReplica >= 0) {
    idealstate.setMinActiveReplicas(minActiveReplica);
  }

  if (rebalancerClassName != null) {
    idealstate.setRebalancerClassName(rebalancerClassName);
  }

  if (rebalanceStrategy != null) {
    idealstate.setRebalanceStrategy(rebalanceStrategy);
  }

  if (maxPartitionsPerNode > 0) {
    idealstate.setMaxPartitionsPerInstance(maxPartitionsPerNode);
  }

  if (disableExternalView != null) {
    idealstate.setDisableExternalView(disableExternalView);
  }

  if (enableGroupRouting != null) {
    idealstate.enableGroupRouting(enableGroupRouting);
  }

  if (resourceGroupName != null) {
    idealstate.setResourceGroupName(resourceGroupName);
  }

  if (resourceType != null) {
    idealstate.setResourceType(resourceType);
  }

  if (rebalanceDelayInMs >= 0) {
    idealstate.setRebalanceDelay(rebalanceDelayInMs);
  }

  if (delayRebalanceEnabled != null) {
    idealstate.setDelayRebalanceEnabled(delayRebalanceEnabled);
  }

  if (!idealstate.isValid()) {
    throw new HelixException("invalid ideal-state: " + idealstate);
  }
  return idealstate;
}
 
开发者ID:apache,项目名称:helix,代码行数:57,代码来源:IdealStateBuilder.java

示例12: calculateRelayIdealState

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
public static IdealState calculateRelayIdealState(List<String> partitions,
    List<String> instances, String resultRecordName, int replica, String firstValue,
    String restValue, String stateModelName) {
  Collections.sort(partitions);
  Collections.sort(instances);
  if (instances.size() % replica != 0) {
    throw new HelixException("Instances must be divided by replica");
  }

  IdealState result = new IdealState(resultRecordName);
  result.setNumPartitions(partitions.size());
  result.setReplicas("" + replica);
  result.setStateModelDefRef(stateModelName);

  int groups = instances.size() / replica;
  int remainder = instances.size() % replica;

  int remainder2 = partitions.size() % groups;
  int storageNodeGroupSize = partitions.size() / groups;

  for (int i = 0; i < groups; i++) {
    int relayStart = 0, relayEnd = 0, storageNodeStart = 0, storageNodeEnd = 0;
    if (i < remainder) {
      relayStart = (replica + 1) * i;
      relayEnd = (replica + 1) * (i + 1);
    } else {
      relayStart = (replica + 1) * remainder + replica * (i - remainder);
      relayEnd = relayStart + replica;
    }
    // System.out.println("relay start :" + relayStart + " relayEnd:" + relayEnd);
    if (i < remainder2) {
      storageNodeStart = (storageNodeGroupSize + 1) * i;
      storageNodeEnd = (storageNodeGroupSize + 1) * (i + 1);
    } else {
      storageNodeStart =
          (storageNodeGroupSize + 1) * remainder2 + storageNodeGroupSize * (i - remainder2);
      storageNodeEnd = storageNodeStart + storageNodeGroupSize;
    }

    // System.out.println("storageNodeStart :" + storageNodeStart + " storageNodeEnd:" +
    // storageNodeEnd);
    List<String> snBatch = partitions.subList(storageNodeStart, storageNodeEnd);
    List<String> relayBatch = instances.subList(relayStart, relayEnd);

    Map<String, List<String>> sublistFields =
        calculateSubIdealState(snBatch, relayBatch, replica);

    result.getRecord().getListFields().putAll(sublistFields);
  }

  for (String snName : result.getRecord().getListFields().keySet()) {
    Map<String, String> mapField = new TreeMap<String, String>();
    List<String> relayCandidates = result.getRecord().getListField(snName);
    mapField.put(relayCandidates.get(0), firstValue);
    for (int i = 1; i < relayCandidates.size(); i++) {
      mapField.put(relayCandidates.get(i), restValue);
    }
    result.getRecord().getMapFields().put(snName, mapField);
  }
  System.out.println();
  return result;
}
 
开发者ID:apache,项目名称:helix,代码行数:63,代码来源:IdealStateCalculatorForEspressoRelay.java

示例13: testListenerOnBucketizedResource

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
@Test
public void testListenerOnBucketizedResource() throws Exception {
  String className = TestHelper.getTestClassName();
  String methodName = TestHelper.getTestMethodName();
  String clusterName = className + "_" + methodName;
  String dbName = "TestDB0";
  List<String> instanceNames =
      Arrays.asList("localhost_0", "localhost_1", "localhost_2", "localhost_3", "localhost_4");
  int n = instanceNames.size();

  System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));

  ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, _baseAccessor);
  PropertyKey.Builder keyBuilder = accessor.keyBuilder();

  setupCluster(clusterName, instanceNames, dbName, 3, 10, 2);

  // start controller
  ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName);
  controller.syncStart();

  // start participants
  MockParticipantManager[] participants = new MockParticipantManager[n];
  for (int i = 0; i < n; i++) {
    participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceNames.get(i));
    participants[i].syncStart();
  }

  HelixClusterVerifier _clusterVerifier =
      new BestPossibleExternalViewVerifier.Builder(clusterName).setZkAddr(ZK_ADDR).build();
  Assert.assertTrue(_clusterVerifier.verify());

  // add an external view listener
  TestExternalViewListener listener = new TestExternalViewListener();
  controller.addExternalViewChangeListener(listener);

  // remove "TestDB0"
  _gSetupTool.dropResourceFromCluster(clusterName, dbName);
  Assert.assertTrue(_clusterVerifier.verify());

  // wait callback to finish
  int waitTime =0;
  do {
    Thread.sleep(100);
    waitTime += 100;
    if (waitTime > 30000) {
      break;
    }
  } while (listener.cbCnt == 0);
  listener.cbCnt = 0;

  // add a new db
  String newDbName = "TestDB1";
  int r = 3;
  ZNRecord idealStateRec =
      DefaultIdealStateCalculator.calculateIdealState(instanceNames, 10, r - 1, newDbName,
          "MASTER", "SLAVE");
  IdealState idealState = new IdealState(idealStateRec);
  idealState.setBucketSize(2);
  idealState.setStateModelDefRef("MasterSlave");
  idealState.setRebalanceMode(IdealState.RebalanceMode.CUSTOMIZED);
  idealState.setReplicas(Integer.toString(r));
  accessor.setProperty(keyBuilder.idealStates(newDbName), idealState);

  Assert.assertTrue(_clusterVerifier.verify());

  Thread.sleep(200);
  Assert.assertTrue(listener.cbCnt > 0);

  // clean up
  controller.syncStop();
  for (MockParticipantManager participant : participants) {
    participant.syncStop();
  }
  System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));

}
 
开发者ID:apache,项目名称:helix,代码行数:78,代码来源:TestBucketizedResource.java

示例14: testResourceThrottleWithDelayRebalancer

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
@Test (dependsOnMethods = {"testResourceThrottle"})
public void testResourceThrottleWithDelayRebalancer() throws Exception {
  // start a few participants
  for (int i = 0; i < NODE_NR - 2; i++) {
    _participants[i].syncStart();
  }

  int partition = 10;
  int replica = 3;
  int minActiveReplica = 2;
  int delay = 100;

  for (int i = 0; i < 5; i++) {
    String dbName = "TestDB-" + i;
    IdealState is =
        _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, dbName);
    if (is != null) {
      System.err.println(dbName + "exists!");
      is.setReplicas(String.valueOf(replica));
      is.setMinActiveReplicas(minActiveReplica);
      if (delay > 0) {
        is.setRebalanceDelay(delay);
      }
      is.setRebalancerClassName(DelayedAutoRebalancer.class.getName());
      _setupTool.getClusterManagementTool().setResourceIdealState(CLUSTER_NAME, dbName, is);
    } else {
      createResourceWithDelayedRebalance(CLUSTER_NAME, dbName, STATE_MODEL, partition, replica,
          minActiveReplica, delay);
    }
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, dbName, _replica);
    _dbs.add(dbName);
  }

  HelixClusterVerifier _clusterVerifier =
      new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR).build();
  Assert.assertTrue(_clusterVerifier.verify());


  DelayedTransition.setDelay(20);
  DelayedTransition.enableThrottleRecord();

  // add 2 nodes
  for (int i = NODE_NR - 2; i < NODE_NR; i++) {
    _participants[i].syncStart();
  }

  Assert.assertTrue(_clusterVerifier.verify());

  for (String db : _dbs) {
    validateThrottle(DelayedTransition.getResourcePatitionTransitionTimes(), db, 2);
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:53,代码来源:TestPartitionMovementThrottle.java

示例15: testRenamePartitionCustomIS

import org.apache.helix.model.IdealState; //导入方法依赖的package包/类
@Test()
public void testRenamePartitionCustomIS() throws Exception {

  String clusterName = "CLUSTER_" + getShortClassName() + "_custom";
  System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));

  TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant start port
      "localhost", // participant name prefix
      "TestDB", // resource name prefix
      1, // resources
      10, // partitions per resource
      5, // number of nodes
      3, // replicas
      "MasterSlave", false); // do rebalance

  // calculate idealState
  List<String> instanceNames =
      Arrays.asList("localhost_12918", "localhost_12919", "localhost_12920", "localhost_12921",
          "localhost_12922");
  ZNRecord destIS =
      DefaultIdealStateCalculator.calculateIdealState(instanceNames, 10, 3 - 1, "TestDB0",
          "MASTER", "SLAVE");
  IdealState idealState = new IdealState(destIS);
  idealState.setRebalanceMode(RebalanceMode.CUSTOMIZED);
  idealState.setReplicas("3");
  idealState.setStateModelDefRef("MasterSlave");

  ZKHelixDataAccessor accessor =
      new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
  Builder keyBuilder = accessor.keyBuilder();

  accessor.setProperty(keyBuilder.idealStates("TestDB0"), idealState);

  startAndVerify(clusterName);

  Map<String, String> stateMap = idealState.getRecord().getMapFields().remove("TestDB0_0");
  idealState.getRecord().getMapFields().put("TestDB0_100", stateMap);
  accessor.setProperty(keyBuilder.idealStates("TestDB0"), idealState);

  boolean result =
      ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(
          ZK_ADDR, clusterName));
  Assert.assertTrue(result);

  stop(clusterName);
  System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));

}
 
开发者ID:apache,项目名称:helix,代码行数:49,代码来源:TestRenamePartition.java


注:本文中的org.apache.helix.model.IdealState.setReplicas方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。