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
    • isUnassignedOrMisassigned

      @Deprecated public static boolean isUnassignedOrMisassigned(PersistentTasksCustomMetadata.Assignment assignment, DiscoveryNodes nodes)
      Deprecated.
      prefer PersistentTasksExecutor.automaticReassignmentOnShutdown() returning true over manual reassignment handling. Executors that opt in to automatic reassignment should use needsReassignment(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.
      Returns true if 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 evaluate
      nodes - the current set of nodes in the cluster
      Returns:
      true if the task is unassigned or its assigned node is missing
    • needsReassignment

      public boolean needsReassignment(PersistentTasksCustomMetadata.PersistentTask<?> task, DiscoveryNodes nodes, @Nullable Metadata metadata)
      Returns true if 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 has PersistentTasksExecutor.automaticReassignmentOnShutdown() set to true.
      Parameters:
      task - the persistent task to evaluate
      nodes - the current set of nodes in the cluster
      metadata - cluster metadata, or null when the task does not opt in to automatic reassignment