Class PersistentTasksClusterService

java.lang.Object
org.elasticsearch.persistent.PersistentTasksClusterService
All Implemented Interfaces:
Closeable, AutoCloseable, ClusterStateListener

public 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<org.elasticsearch.core.TimeValue> CLUSTER_TASKS_ALLOCATION_RECHECK_INTERVAL_SETTING
  • Constructor Details

  • Method Details

    • setRecheckInterval

      public void setRecheckInterval(org.elasticsearch.core.TimeValue recheckInterval)
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • createPersistentTask

      public <Params extends PersistentTaskParams> void createPersistentTask(String taskId, String taskName, Params taskParams, ActionListener<PersistentTasksCustomMetadata.PersistentTask<?>> listener)
      Creates a new 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
    • completePersistentTask

      public void completePersistentTask(String id, long allocationId, Exception failure, ActionListener<PersistentTasksCustomMetadata.PersistentTask<?>> listener)
      Restarts a record about a running persistent task from cluster state
      Parameters:
      id - the id of the persistent task
      allocationId - the allocation id of the persistent task
      failure - the reason for restarting the task or null if the task completed successfully
      listener - the listener that will be called when task is removed
    • removePersistentTask

      public void removePersistentTask(String id, ActionListener<PersistentTasksCustomMetadata.PersistentTask<?>> listener)
      Removes the persistent task
      Parameters:
      id - the id of a persistent task
      listener - the listener that will be called when task is removed
    • updatePersistentTaskState

      public void updatePersistentTaskState(String taskId, long taskAllocationId, PersistentTaskState taskState, ActionListener<PersistentTasksCustomMetadata.PersistentTask<?>> listener)
      Update the state of a persistent task
      Parameters:
      taskId - the id of a persistent task
      taskAllocationId - the expected allocation id of the persistent task
      taskState - new state
      listener - the listener that will be called when task is removed
    • unassignPersistentTask

      public void unassignPersistentTask(String taskId, long taskAllocationId, String reason, ActionListener<PersistentTasksCustomMetadata.PersistentTask<?>> listener)
      This unassigns a task from any node, i.e. it is assigned to a null node with the provided reason. Since the assignment executor node is null, the PersistentTasksClusterService will attempt to reassign it to a valid node quickly.
      Parameters:
      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.
      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