Class HelixHelper
- java.lang.Object
-
- org.apache.pinot.common.utils.helix.HelixHelper
-
public class HelixHelper extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHelixHelper.PermanentUpdaterExceptionException to be thrown by updater function to exit from retry in {@link HelixHelper::updatedIdealState}
-
Field Summary
Fields Modifier and Type Field Description static StringBROKER_RESOURCE
-
Method Summary
Modifier and Type Method Description static booleanaddDefaultTags(org.apache.helix.model.InstanceConfig instanceConfig, Supplier<List<String>> defaultTagsSupplier)Adds default tags to the instance config if no tag exists, returnstrueif the default tags are added,falseotherwise.static org.apache.helix.model.IdealStatecloneIdealState(org.apache.helix.model.IdealState idealState)static voiddeleteResourcePropertyFromHelix(org.apache.helix.HelixAdmin admin, String clusterName, String resourceName, String configKey)static List<String>getAllInstances(org.apache.helix.HelixAdmin helixAdmin, String clusterName)Returns all instances for the given cluster.static Set<String>getAllInstancesForResource(org.apache.helix.model.IdealState idealState)Returns all instances for the given resource.static org.apache.helix.model.IdealStategetBrokerIdealStates(org.apache.helix.HelixAdmin admin, String clusterName)static Set<org.apache.helix.model.InstanceConfig>getBrokerInstanceConfigsForTenant(List<org.apache.helix.model.InstanceConfig> instanceConfigs, String tenant)static Set<String>getBrokerInstancesForTenant(List<org.apache.helix.model.InstanceConfig> instanceConfigs, String tenant)Returns the broker instances in the cluster for the given tenant.static Map<String,String>getBrokerResourceConfig(org.apache.helix.HelixAdmin admin, String clusterName)static List<String>getEnabledInstancesWithTag(List<org.apache.helix.model.InstanceConfig> instanceConfigs, String tag)Returns the enabled instances in the cluster with the given tag.static List<String>getEnabledInstancesWithTag(org.apache.helix.HelixManager helixManager, String tag)Returns the enabled instances in the cluster with the given tag.static org.apache.helix.model.ExternalViewgetExternalViewForResource(org.apache.helix.HelixAdmin admin, String clusterName, String resourceName)static org.apache.helix.model.InstanceConfiggetInstanceConfig(org.apache.helix.HelixManager helixManager, String instanceId)Returns the instance config for a specific instance.static List<org.apache.helix.model.InstanceConfig>getInstanceConfigs(org.apache.helix.HelixManager helixManager)Returns the config for all the instances in the cluster.static Map<String,String>getInstanceConfigsMapFor(String instanceName, String clusterName, org.apache.helix.HelixAdmin admin)static List<org.apache.helix.model.InstanceConfig>getInstancesConfigsWithTag(List<org.apache.helix.model.InstanceConfig> instanceConfigs, String tag)static org.apache.helix.model.HelixConfigScopegetInstanceScopefor(String clusterName, String instanceName)static List<String>getInstancesWithTag(List<org.apache.helix.model.InstanceConfig> instanceConfigs, String tag)Returns the instances in the cluster with the given tag.static List<String>getInstancesWithTag(org.apache.helix.HelixManager helixManager, String tag)Returns the instances in the cluster with the given tag.static Set<String>getOfflineInstanceFromExternalView(org.apache.helix.model.ExternalView resourceExternalView)Get a set of offline instance from the external view of the resource.static Set<String>getOnlineInstanceFromExternalView(org.apache.helix.model.ExternalView resourceExternalView)Returns the set of online instances from external view.static Map<String,String>getResourceConfigsFor(String clusterName, String resourceName, org.apache.helix.HelixAdmin admin)static org.apache.helix.model.HelixConfigScopegetResourceScopeFor(String clusterName, String resourceName)static Set<String>getServerInstancesForTenant(List<org.apache.helix.model.InstanceConfig> instanceConfigs, String tenant)Returns the server instances in the cluster for the given tenant.static Set<String>getServerInstancesForTenant(org.apache.helix.HelixManager helixManager, String tenant)Returns the server instances in the cluster for the given tenant.static Set<String>getServerInstancesForTenantWithType(List<org.apache.helix.model.InstanceConfig> instanceConfigs, String tenant, TableType tableType)Returns the server instances in the cluster for the given tenant name and tenant type.static org.apache.helix.model.IdealStategetTableIdealState(org.apache.helix.HelixManager manager, String resourceName)static Set<String>getTablesForBrokerTag(org.apache.helix.HelixManager helixManager, String brokerTag)static Set<String>getTablesForBrokerTags(org.apache.helix.HelixManager helixManager, List<String> brokerTags)static booleanremoveDisabledPartitions(org.apache.helix.model.InstanceConfig instanceConfig)Removes the disabled partitions from the instance config.static voidremoveResourceFromBrokerIdealState(org.apache.helix.HelixManager helixManager, String resourceTag)Remove a resource (offline/realtime table) from the Broker's ideal state.static voidremoveSegmentFromIdealState(org.apache.helix.HelixManager helixManager, String tableName, String segmentName)Remove the segment from the cluster.static voidremoveSegmentsFromIdealState(org.apache.helix.HelixManager helixManager, String tableName, List<String> segments)static voidsetInstanceState(String instanceName, String clusterName, org.apache.helix.HelixAdmin admin, boolean enable)Toggle the state of the instance between OFFLINE and ONLINE.static voidsetStateForInstanceList(List<String> instances, String clusterName, org.apache.helix.HelixAdmin admin, boolean enable)static voidsetStateForInstanceSet(Set<String> instances, String clusterName, org.apache.helix.HelixAdmin admin, boolean enable)static voidupdateBrokerConfig(Map<String,String> brokerResourceConfig, org.apache.helix.HelixAdmin admin, String clusterName)static voidupdateBrokerResource(org.apache.helix.HelixManager helixManager, String brokerId, List<String> brokerTags, List<String> tablesAdded, List<String> tablesRemoved)Updates broker resource ideal state for the given broker with the given broker tags.static booleanupdateHostnamePort(org.apache.helix.model.InstanceConfig instanceConfig, String hostname, int port)Updates hostname and port in the instance config, returnstrueif the value is updated,falseotherwise.static org.apache.helix.model.IdealStateupdateIdealState(org.apache.helix.HelixManager helixManager, String resourceName, com.google.common.base.Function<org.apache.helix.model.IdealState,org.apache.helix.model.IdealState> updater)static org.apache.helix.model.IdealStateupdateIdealState(org.apache.helix.HelixManager helixManager, String resourceName, com.google.common.base.Function<org.apache.helix.model.IdealState,org.apache.helix.model.IdealState> updater, RetryPolicy policy)static org.apache.helix.model.IdealStateupdateIdealState(org.apache.helix.HelixManager helixManager, String resourceName, com.google.common.base.Function<org.apache.helix.model.IdealState,org.apache.helix.model.IdealState> updater, RetryPolicy policy, boolean noChangeOk)Updates the ideal state, retrying if necessary in case of concurrent updates to the ideal state.static voidupdateInstanceConfig(org.apache.helix.HelixManager helixManager, org.apache.helix.model.InstanceConfig instanceConfig)Updates instance config to the Helix property store.static voidupdateResourceConfigsFor(Map<String,String> newConfigs, String resourceName, String clusterName, org.apache.helix.HelixAdmin admin)static booleanupdateTlsPort(org.apache.helix.model.InstanceConfig instanceConfig, int tlsPort)Updates a tlsPort value into Pinot instance config so it can be retrieved later
-
-
-
Field Detail
-
BROKER_RESOURCE
public static final String BROKER_RESOURCE
- See Also:
- Constant Field Values
-
-
Method Detail
-
cloneIdealState
public static org.apache.helix.model.IdealState cloneIdealState(org.apache.helix.model.IdealState idealState)
-
updateIdealState
public static org.apache.helix.model.IdealState updateIdealState(org.apache.helix.HelixManager helixManager, String resourceName, com.google.common.base.Function<org.apache.helix.model.IdealState,org.apache.helix.model.IdealState> updater, RetryPolicy policy, boolean noChangeOk)Updates the ideal state, retrying if necessary in case of concurrent updates to the ideal state.- Parameters:
helixManager- The HelixManager used to interact with the Helix clusterresourceName- The resource for which to update the ideal stateupdater- A function that returns an updated ideal state given an input ideal state- Returns:
- updated ideal state if successful, null if not
-
updateIdealState
public static org.apache.helix.model.IdealState updateIdealState(org.apache.helix.HelixManager helixManager, String resourceName, com.google.common.base.Function<org.apache.helix.model.IdealState,org.apache.helix.model.IdealState> updater)
-
updateIdealState
public static org.apache.helix.model.IdealState updateIdealState(org.apache.helix.HelixManager helixManager, String resourceName, com.google.common.base.Function<org.apache.helix.model.IdealState,org.apache.helix.model.IdealState> updater, RetryPolicy policy)
-
updateBrokerResource
public static void updateBrokerResource(org.apache.helix.HelixManager helixManager, String brokerId, List<String> brokerTags, @Nullable List<String> tablesAdded, @Nullable List<String> tablesRemoved)Updates broker resource ideal state for the given broker with the given broker tags. OptionaltablesAddedandtablesRemovedcan be provided to track the tables added/removed during the update.
-
getAllInstances
public static List<String> getAllInstances(org.apache.helix.HelixAdmin helixAdmin, String clusterName)
Returns all instances for the given cluster.- Parameters:
helixAdmin- The HelixAdmin object used to interact with the Helix clusterclusterName- Name of the cluster for which to get all the instances for.- Returns:
- Returns a List of strings containing the instance names for the given cluster.
-
getAllInstancesForResource
public static Set<String> getAllInstancesForResource(org.apache.helix.model.IdealState idealState)
Returns all instances for the given resource.- Parameters:
idealState- IdealState of the resource for which to return the instances of.- Returns:
- Returns a Set of strings containing the instance names for the given cluster.
-
setInstanceState
public static void setInstanceState(String instanceName, String clusterName, org.apache.helix.HelixAdmin admin, boolean enable)
Toggle the state of the instance between OFFLINE and ONLINE.- Parameters:
instanceName- Name of the instance for which to toggle the state.clusterName- Name of the cluster to which the instance belongs.admin- HelixAdmin to access the cluster.enable- Set enable to true for ONLINE and FALSE for OFFLINE.
-
setStateForInstanceList
public static void setStateForInstanceList(List<String> instances, String clusterName, org.apache.helix.HelixAdmin admin, boolean enable)
-
setStateForInstanceSet
public static void setStateForInstanceSet(Set<String> instances, String clusterName, org.apache.helix.HelixAdmin admin, boolean enable)
-
getInstanceConfigsMapFor
public static Map<String,String> getInstanceConfigsMapFor(String instanceName, String clusterName, org.apache.helix.HelixAdmin admin)
-
getInstanceScopefor
public static org.apache.helix.model.HelixConfigScope getInstanceScopefor(String clusterName, String instanceName)
-
getResourceScopeFor
public static org.apache.helix.model.HelixConfigScope getResourceScopeFor(String clusterName, String resourceName)
-
getResourceConfigsFor
public static Map<String,String> getResourceConfigsFor(String clusterName, String resourceName, org.apache.helix.HelixAdmin admin)
-
updateResourceConfigsFor
public static void updateResourceConfigsFor(Map<String,String> newConfigs, String resourceName, String clusterName, org.apache.helix.HelixAdmin admin)
-
deleteResourcePropertyFromHelix
public static void deleteResourcePropertyFromHelix(org.apache.helix.HelixAdmin admin, String clusterName, String resourceName, String configKey)
-
getTableIdealState
public static org.apache.helix.model.IdealState getTableIdealState(org.apache.helix.HelixManager manager, String resourceName)
-
getExternalViewForResource
public static org.apache.helix.model.ExternalView getExternalViewForResource(org.apache.helix.HelixAdmin admin, String clusterName, String resourceName)
-
getBrokerResourceConfig
public static Map<String,String> getBrokerResourceConfig(org.apache.helix.HelixAdmin admin, String clusterName)
-
updateBrokerConfig
public static void updateBrokerConfig(Map<String,String> brokerResourceConfig, org.apache.helix.HelixAdmin admin, String clusterName)
-
getBrokerIdealStates
public static org.apache.helix.model.IdealState getBrokerIdealStates(org.apache.helix.HelixAdmin admin, String clusterName)
-
removeResourceFromBrokerIdealState
public static void removeResourceFromBrokerIdealState(org.apache.helix.HelixManager helixManager, String resourceTag)Remove a resource (offline/realtime table) from the Broker's ideal state.- Parameters:
helixManager- The HelixManager object for accessing helix cluster.resourceTag- Name of the resource that needs to be removed from Broker ideal state.
-
getOnlineInstanceFromExternalView
public static Set<String> getOnlineInstanceFromExternalView(org.apache.helix.model.ExternalView resourceExternalView)
Returns the set of online instances from external view.- Parameters:
resourceExternalView- External view for the resource.- Returns:
- Set<String> of online instances in the external view for the resource.
-
getOfflineInstanceFromExternalView
public static Set<String> getOfflineInstanceFromExternalView(org.apache.helix.model.ExternalView resourceExternalView)
Get a set of offline instance from the external view of the resource.- Parameters:
resourceExternalView- External view of the resource- Returns:
- Set of string instance names of the offline instances in the external view.
-
removeSegmentFromIdealState
public static void removeSegmentFromIdealState(org.apache.helix.HelixManager helixManager, String tableName, String segmentName)Remove the segment from the cluster.- Parameters:
helixManager- The HelixManager object to access the helix cluster.tableName- Name of the table to which the new segment is to be added.segmentName- Name of the new segment to be added
-
removeSegmentsFromIdealState
public static void removeSegmentsFromIdealState(org.apache.helix.HelixManager helixManager, String tableName, List<String> segments)
-
getInstanceConfigs
public static List<org.apache.helix.model.InstanceConfig> getInstanceConfigs(org.apache.helix.HelixManager helixManager)
Returns the config for all the instances in the cluster.
-
getInstancesWithTag
public static List<String> getInstancesWithTag(org.apache.helix.HelixManager helixManager, String tag)
Returns the instances in the cluster with the given tag.
-
getInstancesWithTag
public static List<String> getInstancesWithTag(List<org.apache.helix.model.InstanceConfig> instanceConfigs, String tag)
Returns the instances in the cluster with the given tag. TODO: refactor code to use this method overgetInstancesWithTag(HelixManager, String)if applicable to reuse instance configs in order to reduce ZK accesses
-
getInstancesConfigsWithTag
public static List<org.apache.helix.model.InstanceConfig> getInstancesConfigsWithTag(List<org.apache.helix.model.InstanceConfig> instanceConfigs, String tag)
-
getEnabledInstancesWithTag
public static List<String> getEnabledInstancesWithTag(org.apache.helix.HelixManager helixManager, String tag)
Returns the enabled instances in the cluster with the given tag.
-
getEnabledInstancesWithTag
public static List<String> getEnabledInstancesWithTag(List<org.apache.helix.model.InstanceConfig> instanceConfigs, String tag)
Returns the enabled instances in the cluster with the given tag. TODO: refactor code to use this method overgetEnabledInstancesWithTag(HelixManager, String)if applicable to reuse instance configs in order to reduce ZK accesses
-
getServerInstancesForTenant
public static Set<String> getServerInstancesForTenant(org.apache.helix.HelixManager helixManager, String tenant)
Returns the server instances in the cluster for the given tenant.
-
getServerInstancesForTenant
public static Set<String> getServerInstancesForTenant(List<org.apache.helix.model.InstanceConfig> instanceConfigs, String tenant)
Returns the server instances in the cluster for the given tenant. TODO: refactor code to use this method if applicable to reuse instance configs in order to reduce ZK accesses
-
getServerInstancesForTenantWithType
public static Set<String> getServerInstancesForTenantWithType(List<org.apache.helix.model.InstanceConfig> instanceConfigs, String tenant, TableType tableType)
Returns the server instances in the cluster for the given tenant name and tenant type. TODO: refactor code to use this method if applicable to reuse instance configs in order to reduce ZK accesses
-
getBrokerInstancesForTenant
public static Set<String> getBrokerInstancesForTenant(List<org.apache.helix.model.InstanceConfig> instanceConfigs, String tenant)
Returns the broker instances in the cluster for the given tenant. TODO: refactor code to use this method if applicable to reuse instance configs in order to reduce ZK accesses
-
getBrokerInstanceConfigsForTenant
public static Set<org.apache.helix.model.InstanceConfig> getBrokerInstanceConfigsForTenant(List<org.apache.helix.model.InstanceConfig> instanceConfigs, String tenant)
-
getTablesForBrokerTag
public static Set<String> getTablesForBrokerTag(org.apache.helix.HelixManager helixManager, String brokerTag)
-
getTablesForBrokerTags
public static Set<String> getTablesForBrokerTags(org.apache.helix.HelixManager helixManager, List<String> brokerTags)
-
getInstanceConfig
public static org.apache.helix.model.InstanceConfig getInstanceConfig(org.apache.helix.HelixManager helixManager, String instanceId)Returns the instance config for a specific instance.
-
updateInstanceConfig
public static void updateInstanceConfig(org.apache.helix.HelixManager helixManager, org.apache.helix.model.InstanceConfig instanceConfig)Updates instance config to the Helix property store.
-
updateHostnamePort
public static boolean updateHostnamePort(org.apache.helix.model.InstanceConfig instanceConfig, String hostname, int port)Updates hostname and port in the instance config, returnstrueif the value is updated,falseotherwise.
-
updateTlsPort
public static boolean updateTlsPort(org.apache.helix.model.InstanceConfig instanceConfig, int tlsPort)Updates a tlsPort value into Pinot instance config so it can be retrieved later- Parameters:
instanceConfig- the instance config to updatetlsPort- the tlsPort number- Returns:
- true if updated
-
addDefaultTags
public static boolean addDefaultTags(org.apache.helix.model.InstanceConfig instanceConfig, Supplier<List<String>> defaultTagsSupplier)Adds default tags to the instance config if no tag exists, returnstrueif the default tags are added,falseotherwise.The
defaultTagsSupplieris a function which is only invoked when the instance does not have any tag. E.g. () -> Collections.singletonList("DefaultTenant_BROKER").
-
removeDisabledPartitions
public static boolean removeDisabledPartitions(org.apache.helix.model.InstanceConfig instanceConfig)
Removes the disabled partitions from the instance config. Sometimes a partition can be accidentally disabled, and not re-enabled for some reason. When an instance is restarted, we should remove these disabled partitions so that they can be processed.
-
-