Module org.elasticsearch.server
Package org.elasticsearch.persistent
Class PersistentTasksClusterService
java.lang.Object
org.elasticsearch.persistent.PersistentTasksClusterService
- All Implemented Interfaces:
Closeable,AutoCloseable,ClusterStateListener
public final class PersistentTasksClusterService
extends Object
implements ClusterStateListener, Closeable
Component that runs only on the master node and is responsible for assigning running tasks to nodes
-
Field Summary
FieldsModifier and TypeFieldDescription -
Constructor Summary
ConstructorsConstructorDescriptionPersistentTasksClusterService(Settings settings, PersistentTasksExecutorRegistry registry, ClusterService clusterService, ThreadPool threadPool) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidCalled when cluster state changes.<Params extends PersistentTaskParams>
voidcreateClusterPersistentTask(String taskId, String taskName, Params taskParams, ActionListener<PersistentTasksCustomMetadata.PersistentTask<?>> listener) Creates a new cluster-scoped persistent task on master node<Params extends PersistentTaskParams>
voidcreateProjectPersistentTask(ProjectId projectId, String taskId, String taskName, Params taskParams, ActionListener<PersistentTasksCustomMetadata.PersistentTask<?>> listener) Creates a new project-scoped persistent task on master nodestatic booleanisUnassignedOrMisassigned(PersistentTasksCustomMetadata.Assignment assignment, DiscoveryNodes nodes) Deprecated.booleanneedsReassignment(PersistentTasksCustomMetadata.PersistentTask<?> task, DiscoveryNodes nodes, Metadata metadata) Returnstrueif the task needs reassignment, either because it is unassigned or its node no longer exists, or because it is assigned to a node that is marked for shutdown and the corresponding task executor hasPersistentTasksExecutor.automaticReassignmentOnShutdown()set totrue.voidsetRecheckInterval(TimeValue recheckInterval) voidunassignPersistentTask(ProjectId projectIdHint, String taskId, long taskAllocationId, String reason, ActionListener<PersistentTasksCustomMetadata.PersistentTask<?>> listener) This unassigns task from any node, i.e.
-
Field Details
-
CLUSTER_TASKS_ALLOCATION_RECHECK_INTERVAL_SETTING
-
-
Constructor Details
-
PersistentTasksClusterService
public PersistentTasksClusterService(Settings settings, PersistentTasksExecutorRegistry registry, ClusterService clusterService, ThreadPool threadPool)
-
-
Method Details
-
setRecheckInterval
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
createProjectPersistentTask
public <Params extends PersistentTaskParams> void createProjectPersistentTask(ProjectId projectId, String taskId, String taskName, Params taskParams, ActionListener<PersistentTasksCustomMetadata.PersistentTask<?>> listener) Creates a new project-scoped persistent task on master node- Parameters:
projectId- the project for which the task should be createdtaskId- the task's idtaskName- the task's nametaskParams- the task's parameterslistener- the listener that will be called when task is started
-
createClusterPersistentTask
public <Params extends PersistentTaskParams> void createClusterPersistentTask(String taskId, String taskName, Params taskParams, ActionListener<PersistentTasksCustomMetadata.PersistentTask<?>> listener) Creates a new cluster-scoped persistent task on master node- Parameters:
taskId- the task's idtaskName- the task's nametaskParams- the task's parameterslistener- the listener that will be called when task is started
-
unassignPersistentTask
public void unassignPersistentTask(@Nullable ProjectId projectIdHint, String taskId, long taskAllocationId, String reason, ActionListener<PersistentTasksCustomMetadata.PersistentTask<?>> listener) This unassigns task from any node, i.e. it is assigned to anullnode with the provided reason. The task may be either cluster-scope or project-scope. This is determined by the projectIdHint and the taskId against the cluster state. Since the assignment executor node is null, thePersistentTasksClusterServicewill attempt to reassign it to a valid node quickly.- Parameters:
projectIdHint- hint of the project for which the task should be unassigned,nullfor cluster-scope tasks See alsomaybeNullProjectIdForClusterTask(org.elasticsearch.cluster.ClusterState, org.elasticsearch.cluster.metadata.ProjectId, java.lang.String)taskId- the id of a persistent tasktaskAllocationId- the expected allocation id of the persistent taskreason- the reason for unassigning the task from any nodelistener- the listener that will be called when task is unassigned
-
clusterChanged
Description copied from interface:ClusterStateListenerCalled when cluster state changes.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:
clusterChangedin interfaceClusterStateListener
-
isUnassignedOrMisassigned
@Deprecated public static boolean isUnassignedOrMisassigned(PersistentTasksCustomMetadata.Assignment assignment, DiscoveryNodes nodes) Deprecated.preferPersistentTasksExecutor.automaticReassignmentOnShutdown()returningtrueover manual reassignment handling. Executors that opt in to automatic reassignment should useneedsReassignment(org.elasticsearch.persistent.PersistentTasksCustomMetadata.PersistentTask<?>, org.elasticsearch.cluster.node.DiscoveryNodes, org.elasticsearch.cluster.metadata.Metadata)for cluster-service-level reassignment decisions, which additionally accounts for nodes marked for shutdown.Returnstrueif the given assignment has no executor node, or if the assigned node no longer exists in the cluster.- Parameters:
assignment- the current task assignment to evaluatenodes- the current set of nodes in the cluster- Returns:
trueif the task is unassigned or its assigned node is missing
-
needsReassignment
public boolean needsReassignment(PersistentTasksCustomMetadata.PersistentTask<?> task, DiscoveryNodes nodes, @Nullable Metadata metadata) Returnstrueif the task needs reassignment, either because it is unassigned or its node no longer exists, or because it is assigned to a node that is marked for shutdown and the corresponding task executor hasPersistentTasksExecutor.automaticReassignmentOnShutdown()set totrue.- Parameters:
task- the persistent task to evaluatenodes- the current set of nodes in the clustermetadata- cluster metadata, ornullwhen the task does not opt in to automatic reassignment
-
PersistentTasksExecutor.automaticReassignmentOnShutdown()returningtrueover manual reassignment handling.