Class ClusterStateUpdateTask

java.lang.Object
org.elasticsearch.cluster.ClusterStateUpdateTask
All Implemented Interfaces:
ClusterStateTaskConfig, ClusterStateTaskListener
Direct Known Subclasses:
AckedClusterStateUpdateTask, MigrationResultsUpdateTask, SystemIndexMetadataUpgradeService.SystemIndexMetadataUpdateTask

public abstract class ClusterStateUpdateTask extends Object implements ClusterStateTaskConfig, ClusterStateTaskListener
A task that can update the cluster state.
  • Constructor Details

    • ClusterStateUpdateTask

      public ClusterStateUpdateTask()
    • ClusterStateUpdateTask

      public ClusterStateUpdateTask(Priority priority)
    • ClusterStateUpdateTask

      public ClusterStateUpdateTask(TimeValue timeout)
    • ClusterStateUpdateTask

      public ClusterStateUpdateTask(Priority priority, TimeValue timeout)
  • Method Details

    • execute

      public abstract ClusterState execute(ClusterState currentState) throws Exception
      Computes the cluster state that results from executing this task on the given state. Returns the *same instance* if no change is required, which is an important and valuable optimisation since it short-circuits the whole publication process and saves a bunch of time and effort.
      Throws:
      Exception
    • onFailure

      public abstract void onFailure(Exception e)
      A callback for when task execution fails. May receive a NotMasterException if this node stopped being the master before this task was executed or a ProcessClusterEventTimeoutException if the task timed out before it was executed. If the task fails during execution then this method receives the corresponding exception. If the task executes successfully but the resulting cluster state publication fails then this method receives a FailedToCommitClusterStateException. If publication fails then a new master is elected and the update might or might not take effect, depending on whether or not the newly-elected master accepted the published state that failed to be committed.

      Use MasterService.isPublishFailureException(java.lang.Exception) to detect the "expected" master failure cases if needed.

      Implementations of this callback should not throw exceptions: an exception thrown here is logged by the master service at ERROR level and otherwise ignored. If log-and-ignore is the right behaviour then implementations should do so themselves, typically using a more specific logger and at a less dramatic log level.

      Specified by:
      onFailure in interface ClusterStateTaskListener
    • timeout

      @Nullable public final TimeValue timeout()
      If the cluster state update task wasn't processed by the provided timeout, call ClusterStateTaskListener.onFailure(Exception). May return null to indicate no timeout is needed (default).
      Specified by:
      timeout in interface ClusterStateTaskConfig
      Returns:
      the timeout, or null if one is not set
    • priority

      public final Priority priority()
      Description copied from interface: ClusterStateTaskConfig
      The Priority for this cluster state update task configuration. Avoid priorities other than Priority.NORMAL where possible. A stream of higher-priority tasks can starve lower-priority ones from running. Higher-priority tasks should definitely share a ClusterStateTaskExecutor instance so that they are executed in batches.
      Specified by:
      priority in interface ClusterStateTaskConfig
      Returns:
      the priority