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) TaskManager
(Settings settings, ThreadPool threadPool, Set<String> taskHeaders, Tracer tracer) -
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
cancelChildLocal
(TaskId parentTaskId, long childRequestId, String reason) Cancels children tasks of the specified parent, with the request ID specified, as long as the request ID is positive.void
cancelChildRemote
(TaskId parentTask, long childRequestId, Transport.Connection childConnection, String reason) Send an Action to cancel children tasks of the specified parent, with the request ID specified.void
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 taskregister
(String type, String action, TaskAwareRequest request, boolean traceRequest) Registers a task without a parent task, and specifies whether to trace the request.<Request extends ActionRequest,
Response extends ActionResponse>
TaskregisterAndExecute
(String type, TransportAction<Request, Response> action, Request request, Transport.Connection localConnection, ActionListener<Response> taskListener) registerChildConnection
(long taskId, Transport.Connection childConnection) Register a connection on which a child task will execute on the target connection.void
registerRemovedTaskListener
(RemovedTaskListener removedTaskListener) 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.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
unregisterRemovedTaskListener
(RemovedTaskListener removedTaskListener)
-
Constructor Details
-
TaskManager
-
TaskManager
public TaskManager(Settings settings, ThreadPool threadPool, Set<String> taskHeaders, Tracer tracer)
-
-
Method Details
-
setTaskResultsService
-
setTaskCancellationService
-
register
Registers a task without parent task -
register
Registers a task without a parent task, and specifies whether to trace the request. You should prefer to callregister(String, String, TaskAwareRequest)
, since it is rare to want to avoid tracing a task. -
registerAndExecute
public <Request extends ActionRequest,Response extends ActionResponse> Task registerAndExecute(String type, TransportAction<Request, Response> action, Request request, Transport.Connection localConnection, ActionListener<Response> taskListener) -
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.
-
cancelChildLocal
Cancels children tasks of the specified parent, with the request ID specified, as long as the request ID is positive. Note: There may be multiple children for the same request ID. In this edge case all these multiple children are cancelled. -
cancelChildRemote
public void cancelChildRemote(TaskId parentTask, long childRequestId, Transport.Connection childConnection, String reason) Send an Action to cancel children tasks of the specified parent, with the request ID specified. Note: There may be multiple children for the same request ID. In this edge case all these multiple children are cancelled. -
unregister
Unregister the task -
registerRemovedTaskListener
-
unregisterRemovedTaskListener
-
registerChildConnection
@Nullable public 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.- Returns:
- Releasable that must be closed once the child task completes or
null
if no cancellable task for the given id exists
-
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.Cluster states are applied one-by-one which means they can be a performance bottleneck. Implementations of this method should therefore be fast, so please consider forking work into the background rather than doing everything inline.
- Specified by:
applyClusterState
in interfaceClusterStateApplier
-
startTrackingCancellableChannelTask
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) -
getTaskHeaders
-