Search in sources :

Example 11 with InstanceConfig

use of org.apache.helix.model.InstanceConfig in project pinot by linkedin.

the class LargeClusterRoutingTableBuilderTest method createInstanceConfigs.

private List<InstanceConfig> createInstanceConfigs(int instanceCount) {
    List<InstanceConfig> instanceConfigs = new ArrayList<>();
    for (int i = 0; i < instanceCount; i++) {
        InstanceConfig instanceConfig = new InstanceConfig(buildInstanceName(i));
        instanceConfig.setInstanceEnabled(true);
        instanceConfigs.add(instanceConfig);
    }
    return instanceConfigs;
}
Also used : InstanceConfig(org.apache.helix.model.InstanceConfig) ArrayList(java.util.ArrayList)

Example 12 with InstanceConfig

use of org.apache.helix.model.InstanceConfig in project pinot by linkedin.

the class RoutingTableInstancePruner method isInactive.

/**
   * Returns True iff:
   * - The given instance is disabled in Helix.
   * - The instance is being shutdown.
   * False otherwise
   *
   * @param instanceName Name of instance to check.
   * @return True if instance is disabled in helix, or is being shutdown, False otherwise.
   */
public boolean isInactive(String instanceName) {
    if (!instanceConfigMap.containsKey(instanceName)) {
        return true;
    }
    // If the instance is not enabled, return false.
    InstanceConfig instanceConfig = instanceConfigMap.get(instanceName);
    if (!instanceConfig.getInstanceEnabled()) {
        LOGGER.info("Instance '{}' is disabled in the config map.", instanceName);
        return true;
    }
    boolean status = false;
    if (instanceConfig.getRecord().getSimpleField(CommonConstants.Helix.IS_SHUTDOWN_IN_PROGRESS) != null) {
        try {
            if (instanceConfig.getRecord() == null) {
                LOGGER.info("Config record not found for instance '{}'.", instanceName);
                return true;
            }
            if (instanceConfig.getRecord().getSimpleField(CommonConstants.Helix.IS_SHUTDOWN_IN_PROGRESS) != null) {
                status = Boolean.valueOf(instanceConfig.getRecord().getSimpleField(CommonConstants.Helix.IS_SHUTDOWN_IN_PROGRESS));
                if (status == true) {
                    LOGGER.info("found an instance : '{}' in shutting down state", instanceName);
                }
            }
        } catch (Exception e) {
            LOGGER.error("unknown value found while parsing boolean isShuttingDownField ", e);
        }
    }
    return status;
}
Also used : InstanceConfig(org.apache.helix.model.InstanceConfig)

Example 13 with InstanceConfig

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

the class HelixBootstrapUpgradeUtil method updatePartitionInfoIfChanged.

/**
 * Goes through each existing partition and updates the {@link PartitionState} and capacity information for the
 * replicas in each of the instances that hosts a replica for this partition, if it has changed and is different from
 * the current information in the static cluster map.
 * @param partition the partition whose {@link PartitionState} and/or capacity may have to be updated.
 */
private void updatePartitionInfoIfChanged(Partition partition) {
    for (Map.Entry<String, HelixAdmin> entry : adminForDc.entrySet()) {
        String dcName = entry.getKey();
        HelixAdmin dcAdmin = entry.getValue();
        String partitionName = Long.toString(partition.getId());
        long replicaCapacityInStatic = partition.getReplicaCapacityInBytes();
        boolean isSealed = partition.getPartitionState().equals(PartitionState.READ_ONLY);
        List<ReplicaId> replicaList = getReplicasInDc(partition, dcName);
        for (ReplicaId replicaId : replicaList) {
            DataNodeId node = replicaId.getDataNodeId();
            String instanceName = getInstanceName(node);
            InstanceConfig instanceConfig = dcAdmin.getInstanceConfig(clusterName, instanceName);
            boolean shouldSetInstanceConfig = false;
            if (updateSealedStateIfRequired(partitionName, instanceConfig, isSealed)) {
                System.out.println("Sealed state change of partition " + partitionName + " will be updated for instance " + instanceName);
                shouldSetInstanceConfig = true;
            }
            if (updateReplicaCapacityIfRequired(partitionName, instanceConfig, replicaId.getMountPath(), replicaCapacityInStatic)) {
                System.out.println("Replica capacity change of partition " + partitionName + " will be updated for instance" + instanceName);
                shouldSetInstanceConfig = true;
            }
            if (shouldSetInstanceConfig) {
                dcAdmin.setInstanceConfig(clusterName, instanceName, instanceConfig);
                System.out.println("Successfully updated InstanceConfig for instance " + instanceName);
            }
        }
    }
}
Also used : InstanceConfig(org.apache.helix.model.InstanceConfig) HelixAdmin(org.apache.helix.HelixAdmin) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with InstanceConfig

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

the class HelixParticipant method setSealedReplicas.

/**
 * Set the list of sealed replicas in the HelixAdmin
 * @param sealedReplicas list of sealed replicas to be set in the HelixAdmin
 * @return whether the operation succeeded or not
 */
private boolean setSealedReplicas(List<String> sealedReplicas) {
    HelixAdmin helixAdmin = manager.getClusterManagmentTool();
    InstanceConfig instanceConfig = helixAdmin.getInstanceConfig(clusterName, instanceName);
    if (instanceConfig == null) {
        throw new IllegalStateException("No instance config found for cluster: \"" + clusterName + "\", instance: \"" + instanceName + "\"");
    }
    instanceConfig.getRecord().setListField(ClusterMapUtils.SEALED_STR, sealedReplicas);
    return helixAdmin.setInstanceConfig(clusterName, instanceName, instanceConfig);
}
Also used : InstanceConfig(org.apache.helix.model.InstanceConfig) HelixAdmin(org.apache.helix.HelixAdmin)

Example 15 with InstanceConfig

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

the class HelixParticipant method getSealedReplicas.

/**
 * Get the list of sealed replicas from the HelixAdmin
 * @return list of sealed replicas from HelixAdmin
 */
private List<String> getSealedReplicas() {
    HelixAdmin helixAdmin = manager.getClusterManagmentTool();
    InstanceConfig instanceConfig = helixAdmin.getInstanceConfig(clusterName, instanceName);
    if (instanceConfig == null) {
        throw new IllegalStateException("No instance config found for cluster: \"" + clusterName + "\", instance: \"" + instanceName + "\"");
    }
    return ClusterMapUtils.getSealedReplicas(instanceConfig);
}
Also used : InstanceConfig(org.apache.helix.model.InstanceConfig) HelixAdmin(org.apache.helix.HelixAdmin)

Aggregations

InstanceConfig (org.apache.helix.model.InstanceConfig)149 ArrayList (java.util.ArrayList)40 Test (org.testng.annotations.Test)35 HashMap (java.util.HashMap)32 HashSet (java.util.HashSet)28 ZNRecord (org.apache.helix.ZNRecord)26 IdealState (org.apache.helix.model.IdealState)24 ExternalView (org.apache.helix.model.ExternalView)23 Map (java.util.Map)21 HelixException (org.apache.helix.HelixException)21 HelixAdmin (org.apache.helix.HelixAdmin)20 List (java.util.List)19 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)19 HelixDataAccessor (org.apache.helix.HelixDataAccessor)17 ClusterMapConfig (com.github.ambry.config.ClusterMapConfig)15 Test (org.junit.Test)15 Set (java.util.Set)13 VerifiableProperties (com.github.ambry.config.VerifiableProperties)12 IOException (java.io.IOException)12 ZNRecord (org.apache.helix.zookeeper.datamodel.ZNRecord)12