Class PersistentTasksExecutor<Params extends PersistentTaskParams>
- Direct Known Subclasses:
HealthNodeTaskExecutor
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedPersistentTasksExecutor(String taskName, Executor executor) -
Method Summary
Modifier and TypeMethodDescriptionbooleanWhether this task should proactively be reassigned when its executing node is marked for shutdown.protected AllocatedPersistentTaskcreateTask(long id, String type, String action, TaskId parentTaskId, PersistentTasksCustomMetadata.PersistentTask<Params> taskInProgress, Map<String, String> headers) Creates a AllocatedPersistentTask for communicating with task managerprotected PersistentTasksCustomMetadata.AssignmentdoGetAssignment(Params params, Collection<DiscoveryNode> candidateNodes, ClusterState clusterState, ProjectId projectId) Returns the node id where the params has to be executed,getAssignment(Params params, Collection<DiscoveryNode> candidateNodes, ClusterState clusterState, ProjectId projectId) Returns the node id where the params has to be executed,protected StringgetDescription(PersistentTasksCustomMetadata.PersistentTask<Params> taskInProgress) Returns task description that will be available via task managerprotected abstract voidnodeOperation(AllocatedPersistentTask task, Params params, PersistentTaskState state) This operation will be executed on the executor node.scope()protected DiscoveryNodeselectLeastLoadedNode(ClusterState clusterState, Collection<DiscoveryNode> candidateNodes, Predicate<DiscoveryNode> selector) Finds the least loaded node from amongs the candidate node collection that satisfies the selector criteriavoidvalidate(Params params, ClusterState clusterState, ProjectId projectId) Checks the current cluster state for compatibility with the params
-
Field Details
-
NO_NODE_FOUND
-
-
Constructor Details
-
PersistentTasksExecutor
-
-
Method Details
-
getTaskName
-
scope
-
getAssignment
public final PersistentTasksCustomMetadata.Assignment getAssignment(Params params, Collection<DiscoveryNode> candidateNodes, ClusterState clusterState, @Nullable ProjectId projectId) Returns the node id where the params has to be executed,The default implementation returns the least loaded data node from amongst the collection of candidate nodes
-
doGetAssignment
protected PersistentTasksCustomMetadata.Assignment doGetAssignment(Params params, Collection<DiscoveryNode> candidateNodes, ClusterState clusterState, @Nullable ProjectId projectId) -
selectLeastLoadedNode
protected DiscoveryNode selectLeastLoadedNode(ClusterState clusterState, Collection<DiscoveryNode> candidateNodes, Predicate<DiscoveryNode> selector) Finds the least loaded node from amongs the candidate node collection that satisfies the selector criteria -
automaticReassignmentOnShutdown
public boolean automaticReassignmentOnShutdown()Whether this task should proactively be reassigned when its executing node is marked for shutdown. Automated reassignment allows for gap-free reassignment on a node (single cluster state update).Returns
trueby default. Executors that manage their own shutdown handling must override this method to returnfalseto preserve their existing behavior.Migration requirement: before removing a
return falseoverride, ensure that neither the executor nor any associated plugin or cluster-state listener independently handles node shutdown for this task (for example, by callingAllocatedPersistentTask.markAsLocallyAborted(java.lang.String)). Such bespoke handlers would race with the framework-level reassignment. If the handler fires first it will unassign the task and trigger a two-step unassign-then-reassign cycle, which is exactly the gap this mechanism is designed to eliminate. -
validate
Checks the current cluster state for compatibility with the paramsThrows an exception if the supplied params cannot be executed on the cluster in the current state.
-
createTask
protected AllocatedPersistentTask createTask(long id, String type, String action, TaskId parentTaskId, PersistentTasksCustomMetadata.PersistentTask<Params> taskInProgress, Map<String, String> headers) Creates a AllocatedPersistentTask for communicating with task manager -
getDescription
protected String getDescription(PersistentTasksCustomMetadata.PersistentTask<Params> taskInProgress) Returns task description that will be available via task manager -
nodeOperation
protected abstract void nodeOperation(AllocatedPersistentTask task, Params params, @Nullable PersistentTaskState state) This operation will be executed on the executor node.NOTE: The nodeOperation has to throw an exception, trigger task.markAsCompleted() or task.completeAndNotifyIfNeeded() methods to indicate that the persistent task has finished.
-
getExecutor
-