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 Details

    • CLUSTER_TASKS_ALLOCATION_RECHECK_INTERVAL_SETTING

      public static final Setting<TimeValue> CLUSTER_TASKS_ALLOCATION_RECHECK_INTERVAL_SETTING
  • Constructor Details

  • Method Details

    • setRecheckInterval

      public void setRecheckInterval(TimeValue recheckInterval)
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • 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 created
      taskId - the task's id
      taskName - the task's name
      taskParams - the task's parameters
      listener - 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 id
      taskName - the task's name
      taskParams - the task's parameters
      listener - 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 a null 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, the PersistentTasksClusterService 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 also maybeNullProjectIdForClusterTask(org.elasticsearch.cluster.ClusterState, org.elasticsearch.cluster.metadata.ProjectId, java.lang.String)
      taskId - the id of a persistent task
      taskAllocationId - the expected allocation id of the persistent task
      reason - the reason for unassigning the task from any node
      listener - the listener that will be called when task is unassigned
    • clusterChanged

      public void clusterChanged(ClusterChangedEvent event)
      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 interface ClusterStateListener
    • 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