Search in sources :

Example 1 with AutoModeISBuilder

use of org.apache.helix.model.builder.AutoModeISBuilder in project ambry by linkedin.

the class HelixBootstrapUpgradeUtil method addNewAmbryPartitions.

/**
 * Adds all partitions to every datacenter with replicas in nodes as specified in the static clustermap (unless it
 * was already added).
 *
 * The assumption is that in the static layout, every partition is contained in every colo. We make this assumption
 * to ensure that partitions are grouped under the same resource in all colos (since the resource id is not
 * something that is present today in the static cluster map). This is not a strict requirement though, but helps
 * ease the logic.
 *
 * Note: 1. We ensure that the partition names are unique in the Ambry cluster even across resources.
 *       2. New Ambry partitions will not be added to Helix resources that are already present before the call to this
 *          method.
 */
private void addNewAmbryPartitions(List<Partition> partitions, String resourceName) {
    // resources are created and partitions are grouped under these resources upto a maximum threshold.
    if (partitions.isEmpty()) {
        throw new IllegalArgumentException("Cannot add resource with zero partitions");
    }
    for (Map.Entry<String, HelixAdmin> entry : adminForDc.entrySet()) {
        String dcName = entry.getKey();
        HelixAdmin dcAdmin = entry.getValue();
        AutoModeISBuilder resourceISBuilder = new AutoModeISBuilder(resourceName);
        int numReplicas = 0;
        resourceISBuilder.setStateModel(LeaderStandbySMD.name);
        for (Partition partition : partitions) {
            String partitionName = Long.toString(partition.getId());
            boolean sealed = partition.getPartitionState().equals(PartitionState.READ_ONLY);
            List<ReplicaId> replicaList = getReplicasInDc(partition, dcName);
            numReplicas = replicaList.size();
            String[] instances = updateInstancesAndGetInstanceNames(dcAdmin, partitionName, replicaList, sealed);
            Collections.shuffle(Arrays.asList(instances));
            resourceISBuilder.assignPreferenceList(partitionName, instances);
        }
        resourceISBuilder.setNumPartitions(partitions.size());
        resourceISBuilder.setNumReplica(numReplicas);
        IdealState idealState = resourceISBuilder.build();
        dcAdmin.addResource(clusterName, resourceName, idealState);
        System.out.println("Added " + partitions.size() + " new partitions under resource " + resourceName + " in datacenter " + dcName);
    }
}
Also used : HelixAdmin(org.apache.helix.HelixAdmin) IdealState(org.apache.helix.model.IdealState) AutoModeISBuilder(org.apache.helix.model.builder.AutoModeISBuilder) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 HelixAdmin (org.apache.helix.HelixAdmin)1 IdealState (org.apache.helix.model.IdealState)1 AutoModeISBuilder (org.apache.helix.model.builder.AutoModeISBuilder)1