public abstract class

TaskRebalancer

extends Object
implements HelixRebalancer
java.lang.Object
   ↳ org.apache.helix.task.TaskRebalancer
Known Direct Subclasses

Class Overview

Custom rebalancer implementation for the Task state model.

Summary

Public Constructors
TaskRebalancer()
Public Methods
ResourceAssignment computeResourceMapping(IdealState taskIs, RebalancerConfig rebalancerConfig, ResourceAssignment prevAssignment, Cluster cluster, ResourceCurrentState currentState)
Given an ideal state for a resource and liveness of participants, compute a assignment of instances and states to each partition of a resource.
abstract Set<Integer> getAllTaskPartitions(JobConfig jobCfg, JobContext jobCtx, WorkflowConfig workflowCfg, WorkflowContext workflowCtx, Cluster cache)
Get all the partitions that should be created by this task
abstract Map<ParticipantIdSortedSet<Integer>> getTaskAssignment(ResourceCurrentState currStateOutput, ResourceAssignment prevAssignment, Collection<ParticipantId> instanceList, JobConfig jobCfg, JobContext jobContext, WorkflowConfig workflowCfg, WorkflowContext workflowCtx, Set<Integer> partitionSet, Cluster cache)
Compute an assignment of tasks to instances
void init(HelixManager manager, ControllerContextProvider contextProvider)
Initialize the rebalancer with a HelixManager and ControllerContextProvider if necessary
Protected Methods
static int pId(String pName)
Extracts the partition id from the given partition name.
static String pName(String resource, int pId)
Computes the partition name given the resource name and partition id.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.apache.helix.controller.rebalancer.HelixRebalancer

Public Constructors

public TaskRebalancer ()

Public Methods

public ResourceAssignment computeResourceMapping (IdealState taskIs, RebalancerConfig rebalancerConfig, ResourceAssignment prevAssignment, Cluster cluster, ResourceCurrentState currentState)

Given an ideal state for a resource and liveness of participants, compute a assignment of instances and states to each partition of a resource. This method provides all the relevant information needed to rebalance a resource. If you need additional information use manager.getAccessor to read and write the cluster data. This allows one to compute the ResourceAssignment according to app-specific requirements.

Say that you have:

 class MyRebalancerConfig implements RebalancerConfig
 
as your rebalancer config. To get a typed version, you can do the following:
 MyRebalancerConfig config = BasicRebalancerConfig.convert(rebalancerConfig,
     MyRebalancerConfig.class);
 

Parameters
taskIs the ideal state that defines how a resource should be rebalanced
rebalancerConfig the properties of the resource for which a mapping will be computed
prevAssignment the previous ResourceAssignment of this cluster, or null if none
cluster complete snapshot of the cluster
currentState the current states of all partitions

public abstract Set<Integer> getAllTaskPartitions (JobConfig jobCfg, JobContext jobCtx, WorkflowConfig workflowCfg, WorkflowContext workflowCtx, Cluster cache)

Get all the partitions that should be created by this task

Parameters
jobCfg the task configuration
jobCtx the task context
workflowCfg the workflow configuration
workflowCtx the workflow context
cache cluster snapshot
Returns
  • set of partition numbers

public abstract Map<ParticipantIdSortedSet<Integer>> getTaskAssignment (ResourceCurrentState currStateOutput, ResourceAssignment prevAssignment, Collection<ParticipantId> instanceList, JobConfig jobCfg, JobContext jobContext, WorkflowConfig workflowCfg, WorkflowContext workflowCtx, Set<Integer> partitionSet, Cluster cache)

Compute an assignment of tasks to instances

Parameters
currStateOutput the current state of the instances
prevAssignment the previous task partition assignment
jobCfg the task configuration
workflowCfg the workflow configuration
workflowCtx the workflow context
partitionSet the partitions to assign
cache cluster snapshot
Returns
  • map of instances to set of partition numbers

public void init (HelixManager manager, ControllerContextProvider contextProvider)

Initialize the rebalancer with a HelixManager and ControllerContextProvider if necessary

Parameters
contextProvider An object that supports getting and setting context across pipeline runs

Protected Methods

protected static int pId (String pName)

Extracts the partition id from the given partition name.

protected static String pName (String resource, int pId)

Computes the partition name given the resource name and partition id.