public abstract class

TaskRebalancer

extends Object
implements Rebalancer MappingCalculator
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 computeBestPossiblePartitionState(ClusterDataCache clusterData, IdealState taskIs, Resource resource, CurrentStateOutput currStateOutput)
Given an ideal state for a resource and the liveness of instances, compute the best possible state assignment for each partition's replicas.
IdealState computeNewIdealState(String resourceName, IdealState currentIdealState, CurrentStateOutput currentStateOutput, ClusterDataCache clusterData)
This method provides all the relevant information needed to rebalance a resource.
abstract Set<Integer> getAllTaskPartitions(JobConfig jobCfg, JobContext jobCtx, WorkflowConfig workflowCfg, WorkflowContext workflowCtx, ClusterDataCache cache)
Get all the partitions that should be created by this task
abstract Map<StringSortedSet<Integer>> getTaskAssignment(CurrentStateOutput currStateOutput, ResourceAssignment prevAssignment, Collection<String> instances, JobConfig jobCfg, JobContext jobContext, WorkflowConfig workflowCfg, WorkflowContext workflowCtx, Set<Integer> partitionSet, ClusterDataCache cache)
Compute an assignment of tasks to instances
void init(HelixManager manager)
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.Rebalancer
From interface org.apache.helix.controller.rebalancer.internal.MappingCalculator

Public Constructors

public TaskRebalancer ()

Public Methods

public ResourceAssignment computeBestPossiblePartitionState (ClusterDataCache clusterData, IdealState taskIs, Resource resource, CurrentStateOutput currStateOutput)

Given an ideal state for a resource and the liveness of instances, compute the best possible state assignment for each partition's replicas.

Parameters
currStateOutput Provides the current state and pending state transitions for all partitions

public IdealState computeNewIdealState (String resourceName, IdealState currentIdealState, CurrentStateOutput currentStateOutput, ClusterDataCache clusterData)

This method provides all the relevant information needed to rebalance a resource. If you need additional information use manager.getAccessor to read the cluster data. This allows one to compute the newIdealState according to app specific requirement.

Parameters
resourceName Name of the resource to be rebalanced
currentStateOutput Provides the current state and pending state transition for all partitions
clusterData Provides additional methods to retrieve cluster data.

public abstract Set<Integer> getAllTaskPartitions (JobConfig jobCfg, JobContext jobCtx, WorkflowConfig workflowCfg, WorkflowContext workflowCtx, ClusterDataCache 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<StringSortedSet<Integer>> getTaskAssignment (CurrentStateOutput currStateOutput, ResourceAssignment prevAssignment, Collection<String> instances, JobConfig jobCfg, JobContext jobContext, WorkflowConfig workflowCfg, WorkflowContext workflowCtx, Set<Integer> partitionSet, ClusterDataCache cache)

Compute an assignment of tasks to instances

Parameters
currStateOutput the current state of the instances
prevAssignment the previous task partition assignment
instances the instances
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)

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.