Class MasterService

All Implemented Interfaces:
Closeable, AutoCloseable, LifecycleComponent, Releasable

public class MasterService extends AbstractLifecycleComponent
  • Field Details

    • MASTER_SERVICE_SLOW_TASK_LOGGING_THRESHOLD_SETTING

      public static final Setting<TimeValue> MASTER_SERVICE_SLOW_TASK_LOGGING_THRESHOLD_SETTING
    • MASTER_SERVICE_STARVATION_LOGGING_THRESHOLD_SETTING

      public static final Setting<TimeValue> MASTER_SERVICE_STARVATION_LOGGING_THRESHOLD_SETTING
    • MASTER_UPDATE_THREAD_NAME

      public static final String MASTER_UPDATE_THREAD_NAME
      See Also:
    • STATE_UPDATE_ACTION_NAME

      public static final String STATE_UPDATE_ACTION_NAME
      See Also:
    • threadPool

      protected final ThreadPool threadPool
  • Constructor Details

  • Method Details

    • setClusterStatePublisher

      public void setClusterStatePublisher(ClusterStatePublisher publisher)
    • setClusterStateSupplier

      public void setClusterStateSupplier(Supplier<ClusterState> clusterStateSupplier)
    • doStart

      protected void doStart()
      Description copied from class: AbstractLifecycleComponent
      Start this component. Typically that means doing things like launching background processes and registering listeners on other components. Other components have been initialized by this point, but may not yet be started.

      If this method throws an exception then the startup process will fail, but this component will not be stopped before it is closed.

      This method is called while synchronized on AbstractLifecycleComponent.lifecycle. It is only called once in the lifetime of a component, although it may not be called at all if the startup process encountered some kind of fatal error, such as the failure of some other component to initialize or start.

      Specified by:
      doStart in class AbstractLifecycleComponent
    • createThreadPoolExecutor

      protected ExecutorService createThreadPoolExecutor()
    • getClusterStateUpdateStats

      public ClusterStateUpdateStats getClusterStateUpdateStats()
    • doStop

      protected void doStop()
      Description copied from class: AbstractLifecycleComponent
      Stop this component. Typically that means doing the reverse of whatever AbstractLifecycleComponent.doStart() does.

      This method is called while synchronized on AbstractLifecycleComponent.lifecycle. It is only called once in the lifetime of a component, after calling AbstractLifecycleComponent.doStart(), although it will not be called at all if this component did not successfully start.

      Specified by:
      doStop in class AbstractLifecycleComponent
    • doClose

      protected void doClose()
      Description copied from class: AbstractLifecycleComponent
      Close this component. Typically that means doing the reverse of whatever happened during initialization, such as releasing resources acquired there.

      This method is called while synchronized on AbstractLifecycleComponent.lifecycle. It is called once in the lifetime of a component. If the component was started then it will be stopped before it is closed, and once it is closed it will not be started or stopped.

      Specified by:
      doClose in class AbstractLifecycleComponent
    • isMasterUpdateThread

      public static boolean isMasterUpdateThread()
    • assertMasterUpdateOrTestThread

      public static boolean assertMasterUpdateOrTestThread()
    • assertNotMasterUpdateThread

      public static boolean assertNotMasterUpdateThread(String reason)
    • publicationMayFail

      protected boolean publicationMayFail()
    • publish

      protected void publish(ClusterStatePublicationEvent clusterStatePublicationEvent, ClusterStatePublisher.AckListener ackListener, ActionListener<Void> publicationListener)
    • incrementVersion

      public ClusterState.Builder incrementVersion(ClusterState clusterState)
    • submitUnbatchedStateUpdateTask

      @Deprecated public void submitUnbatchedStateUpdateTask(String source, ClusterStateUpdateTask updateTask)
      Deprecated.
      Submits an unbatched cluster state update task. This method exists for legacy reasons but is deprecated and forbidden in new production code because unbatched tasks are a source of performance and stability bugs. You should instead implement your update logic in a dedicated ClusterStateTaskExecutor which is reused across multiple task instances. The task itself is typically just a collection of parameters consumed by the executor, together with any listeners to be notified when execution completes.
      Parameters:
      source - the source of the cluster state update task
      updateTask - the full context for the cluster state update
    • pendingTasks

      public List<PendingClusterTask> pendingTasks()
      Returns the tasks that are pending.
    • numberOfPendingTasks

      public int numberOfPendingTasks()
      Returns the number of currently pending tasks.
    • getMaxTaskWaitTime

      public TimeValue getMaxTaskWaitTime()
      Returns the maximum wait time for tasks in the queue
      Returns:
      A zero time value if the queue is empty, otherwise the time value oldest task waiting in the queue
    • isPublishFailureException

      public static boolean isPublishFailureException(Exception e)
    • createTaskQueue

      public <T extends ClusterStateTaskListener> MasterServiceTaskQueue<T> createTaskQueue(String name, Priority priority, ClusterStateTaskExecutor<T> executor)
      Create a new task queue which can be used to submit tasks for execution by the master service. Tasks submitted to the same queue (while the master service is otherwise busy) will be batched together into a single cluster state update. You should therefore re-use each queue as much as possible.
      Type Parameters:
      T - The type of the tasks
      Parameters:
      name - The name of the queue, which is mostly useful for debugging.
      priority - The priority at which tasks submitted to the queue are executed. Avoid priorites other than Priority.NORMAL where possible. A stream of higher-priority tasks can starve lower-priority ones from running. Higher-priority tasks should definitely re-use the same MasterServiceTaskQueue so that they are executed in batches.
      executor - The executor which processes each batch of tasks.
      Returns:
      A new batching task queue.