Package org.elasticsearch.tasks
Class TaskManager
java.lang.Object
org.elasticsearch.tasks.TaskManager
- All Implemented Interfaces:
ClusterStateApplier
Task Manager service for keeping track of currently running tasks on the nodes
-
Constructor Summary
ConstructorDescriptionTaskManager
(Settings settings, ThreadPool threadPool, Set<String> taskHeaders) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Called when a new cluster state (ClusterChangedEvent.state()
needs to be applied.boolean
void
cancel
(CancellableTask task, String reason, Runnable listener) Cancels a taskvoid
cancelTaskAndDescendants
(CancellableTask task, String reason, boolean waitForCompletion, ActionListener<Void> listener) getCancellableTask
(long id) Returns a cancellable task with given id, or null if the task is not found.Returns the list of currently running tasks on the node that can be cancelledgetTask
(long id) Returns a task with given id, or null if the task is not found.getTasks()
Returns the list of currently running tasks on the noderegister
(String type, String action, TaskAwareRequest request) Registers a task without parent task<Request extends ActionRequest,
Response extends ActionResponse>
TaskregisterAndExecute
(String type, TransportAction<Request, Response> action, Request request, Transport.Connection localConnection, BiConsumer<Task, Response> onResponse, BiConsumer<Task, Exception> onFailure) org.elasticsearch.core.Releasable
registerChildConnection
(long taskId, Transport.Connection childConnection) Register a connection on which a child task will execute on the target connection.void
Removes the ban for the specified parent task.setBan
(TaskId parentTaskId, String reason, TransportChannel channel) Bans all tasks with the specified parent task from execution, cancels all tasks that are currently executing.void
setTaskCancellationService
(TaskCancellationService taskCancellationService) void
setTaskResultsService
(TaskResultsService taskResultsService) startBanOnChildTasks
(long taskId, String reason, Runnable onChildTasksCompleted) Start rejecting new child requests as the parent task was cancelled.org.elasticsearch.core.Releasable
startTrackingCancellableChannelTask
(TcpChannel channel, CancellableTask task) Start tracking a cancellable task with its tcp channel, so if the channel gets closed we can get a set of pending tasks associated that channel and cancel them as these results won't be retrieved by the parent task.<Response extends ActionResponse>
voidstoreResult
(Task task, Exception error, ActionListener<Response> listener) Stores the task failure<Response extends ActionResponse>
voidstoreResult
(Task task, Response response, ActionListener<Response> listener) Stores the task resultunregister
(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
-
-
Method Details
-
setTaskResultsService
-
setTaskCancellationService
-
register
Registers a task without parent task -
registerAndExecute
public <Request extends ActionRequest,Response extends ActionResponse> Task registerAndExecute(String type, TransportAction<Request, Response> action, Request request, Transport.Connection localConnection, BiConsumer<Task, Response> onResponse, BiConsumer<Task, Exception> onFailure) -
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 -
registerChildConnection
public org.elasticsearch.core.Releasable registerChildConnection(long taskId, Transport.Connection childConnection) Register a connection on which a child task will execute on the target connection. The returnedReleasable
must be called to unregister the child connection once the child task is completed or failed. -
storeResult
public <Response extends ActionResponse> void storeResult(Task task, 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. -
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
-
assertCancellableTaskConsistency
public boolean assertCancellableTaskConsistency() -
startBanOnChildTasks
public Collection<Transport.Connection> startBanOnChildTasks(long taskId, String reason, 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:
- a set of current connections 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. -
startTrackingCancellableChannelTask
public org.elasticsearch.core.Releasable startTrackingCancellableChannelTask(TcpChannel channel, CancellableTask task) Start tracking a cancellable task with its tcp channel, so if the channel gets closed we can get a set of pending tasks associated that channel and cancel them as these results won't be retrieved by the parent task.- Returns:
- a releasable that should be called when this pending task is completed
-
cancelTaskAndDescendants
public void cancelTaskAndDescendants(CancellableTask task, String reason, boolean waitForCompletion, ActionListener<Void> listener)
-