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 TypeMethodDescriptionvoid
close()
void
Called 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 boolean
needsReassignment
(PersistentTasksCustomMetadata.Assignment assignment, DiscoveryNodes nodes) Returns true if the task is not assigned or is assigned to a non-existing nodevoid
setRecheckInterval
(TimeValue recheckInterval) void
unassignPersistentTask
(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:
close
in interfaceAutoCloseable
- Specified by:
close
in 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 anull
node 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, thePersistentTasksClusterService
will attempt to reassign it to a valid node quickly.- Parameters:
projectIdHint
- hint of the project for which the task should be unassigned,null
for 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:ClusterStateListener
Called 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:
clusterChanged
in interfaceClusterStateListener
-
needsReassignment
public static boolean needsReassignment(PersistentTasksCustomMetadata.Assignment assignment, DiscoveryNodes nodes) Returns true if the task is not assigned or is assigned to a non-existing node
-