Package org.elasticsearch.tasks
Class TaskManager
java.lang.Object
org.elasticsearch.tasks.TaskManager
- All Implemented Interfaces:
ClusterStateApplier
public class TaskManager extends java.lang.Object implements ClusterStateApplier
Task Manager service for keeping track of currently running tasks on the nodes
-
Constructor Summary
Constructors Constructor Description TaskManager(Settings settings, ThreadPool threadPool, java.util.Set<java.lang.String> taskHeaders)
-
Method Summary
Modifier and Type Method Description void
applyClusterState(ClusterChangedEvent event)
Called when a new cluster state (ClusterChangedEvent.state()
needs to be applied.void
cancel(CancellableTask task, java.lang.String reason, java.lang.Runnable listener)
Cancels a taskint
getBanCount()
Returns the number of currently banned tasks.java.util.Set<TaskId>
getBannedTaskIds()
CancellableTask
getCancellableTask(long id)
Returns a cancellable task with given id, or null if the task is not found.java.util.Map<java.lang.Long,CancellableTask>
getCancellableTasks()
Returns the list of currently running tasks on the node that can be cancelledTask
getTask(long id)
Returns a task with given id, or null if the task is not found.java.util.Map<java.lang.Long,Task>
getTasks()
Returns the list of currently running tasks on the nodeDiscoveryNode
localNode()
Task
register(java.lang.String type, java.lang.String action, TaskAwareRequest request)
Registers a task without parent taskReleasable
registerChildNode(long taskId, DiscoveryNode node)
Register a node on which a child task will execute.void
removeBan(TaskId parentTaskId)
Removes the ban for the specified parent task.java.util.List<CancellableTask>
setBan(TaskId parentTaskId, java.lang.String reason)
Bans all tasks with the specified parent task from execution, cancels all tasks that are currently executing.void
setTaskResultsService(TaskResultsService taskResultsService)
java.util.Collection<DiscoveryNode>
startBanOnChildrenNodes(long taskId, java.lang.Runnable onChildTasksCompleted)
Start rejecting new child requests as the parent task was cancelled.<Response extends ActionResponse>
voidstoreResult(Task task, java.lang.Exception error, ActionListener<Response> listener)
Stores the task failure<Response extends ActionResponse>
voidstoreResult(Task task, Response response, ActionListener<Response> listener)
Stores the task resultTask
unregister(Task task)
Unregister the taskvoid
waitForTaskCompletion(Task task, long untilInNanos)
Blocks the calling thread, waiting for the task to vanish from the TaskManager.
-
Constructor Details
-
TaskManager
public TaskManager(Settings settings, ThreadPool threadPool, java.util.Set<java.lang.String> taskHeaders)
-
-
Method Details
-
setTaskResultsService
-
register
Registers a task without parent task -
cancel
Cancels a taskAfter starting cancellation on the parent task, the task manager tries to cancel all children tasks of the current task. Once cancellation of the children tasks is done, the listener is triggered. If the task is completed or unregistered from TaskManager, then the listener is called immediately.
-
unregister
Unregister the task -
registerChildNode
Register a node on which a child task will execute. The returnedReleasable
must be called to unregister the child node once the child task is completed or failed. -
localNode
-
storeResult
public <Response extends ActionResponse> void storeResult(Task task, java.lang.Exception error, ActionListener<Response> listener)Stores the task failure -
storeResult
public <Response extends ActionResponse> void storeResult(Task task, Response response, ActionListener<Response> listener)Stores the task result -
getTasks
Returns the list of currently running tasks on the node -
getCancellableTasks
Returns the list of currently running tasks on the node that can be cancelled -
getTask
Returns a task with given id, or null if the task is not found. -
getCancellableTask
Returns a cancellable task with given id, or null if the task is not found. -
getBanCount
public int getBanCount()Returns the number of currently banned tasks.Will be used in task manager stats and for debugging.
-
setBan
Bans all tasks with the specified parent task from execution, cancels all tasks that are currently executing.This method is called when a parent task that has children is cancelled.
- Returns:
- a list of pending cancellable child tasks
-
removeBan
Removes the ban for the specified parent task.This method is called when a previously banned task finally cancelled
-
getBannedTaskIds
-
startBanOnChildrenNodes
public java.util.Collection<DiscoveryNode> startBanOnChildrenNodes(long taskId, java.lang.Runnable onChildTasksCompleted)Start rejecting new child requests as the parent task was cancelled.- Parameters:
taskId
- the parent task idonChildTasksCompleted
- called when all child tasks are completed or failed- Returns:
- the set of current nodes that have outstanding child tasks
-
applyClusterState
Description copied from interface:ClusterStateApplier
Called when a new cluster state (ClusterChangedEvent.state()
needs to be applied. The cluster state to be applied is already committed when this method is called, so an applier must therefore be prepared to deal with any state it receives without throwing an exception. Throwing an exception from an applier is very bad because it will stop the application of this state before it has reached all the other appliers, and will likely result in another attempt to apply the same (or very similar) cluster state which might continue until this node is removed from the cluster.- Specified by:
applyClusterState
in interfaceClusterStateApplier
-
waitForTaskCompletion
Blocks the calling thread, waiting for the task to vanish from the TaskManager.
-