Class MasterService
- java.lang.Object
-
- org.elasticsearch.common.component.AbstractLifecycleComponent
-
- org.elasticsearch.cluster.service.MasterService
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,LifecycleComponent,Releasable
public class MasterService extends AbstractLifecycleComponent
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classMasterService.TaskInputsRepresents a set of tasks to be processed together with their executorprotected classMasterService.TaskOutputsOutput created by executing a set of tasks provided as TaskInputs
-
Field Summary
Fields Modifier and Type Field Description protected ClusterStatePublisherclusterStatePublisherstatic java.lang.StringMASTER_UPDATE_THREAD_NAMEprotected ThreadPoolthreadPool-
Fields inherited from class org.elasticsearch.common.component.AbstractLifecycleComponent
lifecycle
-
-
Constructor Summary
Constructors Constructor Description MasterService(java.lang.String nodeName, Settings settings, ThreadPool threadPool)
-
Method Summary
Modifier and Type Method Description static booleanassertMasterUpdateThread()static booleanassertNotMasterUpdateThread(java.lang.String reason)MasterService.TaskOutputscalculateTaskOutputs(MasterService.TaskInputs taskInputs, ClusterState previousClusterState, long startTimeNS)protected PrioritizedEsThreadPoolExecutorcreateThreadPoolExecutor()protected longcurrentTimeInNanos()protected voiddoClose()protected voiddoStart()protected voiddoStop()protected ClusterStateTaskExecutor.ClusterTasksResult<java.lang.Object>executeTasks(MasterService.TaskInputs taskInputs, long startTimeNS, ClusterState previousClusterState)TimeValuegetMaxTaskWaitTime()Returns the maximum wait time for tasks in the queuejava.util.List<org.elasticsearch.cluster.service.MasterService.Batcher.UpdateTask>getNonFailedTasks(MasterService.TaskInputs taskInputs, ClusterStateTaskExecutor.ClusterTasksResult<java.lang.Object> clusterTasksResult)ClusterState.BuilderincrementVersion(ClusterState clusterState)intnumberOfPendingTasks()Returns the number of currently pending tasks.protected voidonPublicationFailed(ClusterChangedEvent clusterChangedEvent, MasterService.TaskOutputs taskOutputs, long startTimeNS, java.lang.Exception exception)protected voidonPublicationSuccess(ClusterChangedEvent clusterChangedEvent, MasterService.TaskOutputs taskOutputs, long startTimeNS)java.util.List<PendingClusterTask>pendingTasks()Returns the tasks that are pending.protected voidpublish(ClusterChangedEvent clusterChangedEvent, MasterService.TaskOutputs taskOutputs, long startTimeNS)protected voidrunTasks(MasterService.TaskInputs taskInputs)voidsetClusterStatePublisher(ClusterStatePublisher publisher)voidsetClusterStateSupplier(java.util.function.Supplier<ClusterState> clusterStateSupplier)voidsetSlowTaskLoggingThreshold(TimeValue slowTaskLoggingThreshold)<T extends ClusterStateTaskConfig & ClusterStateTaskExecutor<T> & ClusterStateTaskListener>
voidsubmitStateUpdateTask(java.lang.String source, T updateTask)Submits a cluster state update task; unlikesubmitStateUpdateTask(String, Object, ClusterStateTaskConfig, ClusterStateTaskExecutor, ClusterStateTaskListener), submitted updates will not be batched.<T> voidsubmitStateUpdateTask(java.lang.String source, T task, ClusterStateTaskConfig config, ClusterStateTaskExecutor<T> executor, ClusterStateTaskListener listener)Submits a cluster state update task; submitted updates will be batched across the same instance of executor.<T> voidsubmitStateUpdateTasks(java.lang.String source, java.util.Map<T,ClusterStateTaskListener> tasks, ClusterStateTaskConfig config, ClusterStateTaskExecutor<T> executor)Submits a batch of cluster state update tasks; submitted updates are guaranteed to be processed together, potentially with more tasks of the same executor.protected voidwarnAboutSlowTaskIfNeeded(TimeValue executionTime, java.lang.String source)-
Methods inherited from class org.elasticsearch.common.component.AbstractLifecycleComponent
addLifecycleListener, close, lifecycleState, removeLifecycleListener, start, stop
-
-
-
-
Field Detail
-
MASTER_UPDATE_THREAD_NAME
public static final java.lang.String MASTER_UPDATE_THREAD_NAME
- See Also:
- Constant Field Values
-
clusterStatePublisher
protected ClusterStatePublisher clusterStatePublisher
-
threadPool
protected final ThreadPool threadPool
-
-
Constructor Detail
-
MasterService
public MasterService(java.lang.String nodeName, Settings settings, ThreadPool threadPool)
-
-
Method Detail
-
setSlowTaskLoggingThreshold
public void setSlowTaskLoggingThreshold(TimeValue slowTaskLoggingThreshold)
-
setClusterStatePublisher
public void setClusterStatePublisher(ClusterStatePublisher publisher)
-
setClusterStateSupplier
public void setClusterStateSupplier(java.util.function.Supplier<ClusterState> clusterStateSupplier)
-
doStart
protected void doStart()
- Specified by:
doStartin classAbstractLifecycleComponent
-
createThreadPoolExecutor
protected PrioritizedEsThreadPoolExecutor createThreadPoolExecutor()
-
doStop
protected void doStop()
- Specified by:
doStopin classAbstractLifecycleComponent
-
doClose
protected void doClose()
- Specified by:
doClosein classAbstractLifecycleComponent
-
assertMasterUpdateThread
public static boolean assertMasterUpdateThread()
-
assertNotMasterUpdateThread
public static boolean assertNotMasterUpdateThread(java.lang.String reason)
-
runTasks
protected void runTasks(MasterService.TaskInputs taskInputs)
-
publish
protected void publish(ClusterChangedEvent clusterChangedEvent, MasterService.TaskOutputs taskOutputs, long startTimeNS)
-
onPublicationSuccess
protected void onPublicationSuccess(ClusterChangedEvent clusterChangedEvent, MasterService.TaskOutputs taskOutputs, long startTimeNS)
-
onPublicationFailed
protected void onPublicationFailed(ClusterChangedEvent clusterChangedEvent, MasterService.TaskOutputs taskOutputs, long startTimeNS, java.lang.Exception exception)
-
calculateTaskOutputs
public MasterService.TaskOutputs calculateTaskOutputs(MasterService.TaskInputs taskInputs, ClusterState previousClusterState, long startTimeNS)
-
incrementVersion
public ClusterState.Builder incrementVersion(ClusterState clusterState)
-
submitStateUpdateTask
public <T extends ClusterStateTaskConfig & ClusterStateTaskExecutor<T> & ClusterStateTaskListener> void submitStateUpdateTask(java.lang.String source, T updateTask)
Submits a cluster state update task; unlikesubmitStateUpdateTask(String, Object, ClusterStateTaskConfig, ClusterStateTaskExecutor, ClusterStateTaskListener), submitted updates will not be batched.- Parameters:
source- the source of the cluster state update taskupdateTask- the full context for the cluster state update task
-
submitStateUpdateTask
public <T> void submitStateUpdateTask(java.lang.String source, T task, ClusterStateTaskConfig config, ClusterStateTaskExecutor<T> executor, ClusterStateTaskListener listener)Submits a cluster state update task; submitted updates will be batched across the same instance of executor. The exact batching semantics depend on the underlying implementation but a rough guideline is that if the update task is submitted while there are pending update tasks for the same executor, these update tasks will all be executed on the executor in a single batch- Type Parameters:
T- the type of the cluster state update task state- Parameters:
source- the source of the cluster state update tasktask- the state needed for the cluster state update taskconfig- the cluster state update task configurationexecutor- the cluster state update task executor; tasks that share the same executor will be executed batches on this executorlistener- callback after the cluster state update task completes
-
pendingTasks
public java.util.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
-
warnAboutSlowTaskIfNeeded
protected void warnAboutSlowTaskIfNeeded(TimeValue executionTime, java.lang.String source)
-
executeTasks
protected ClusterStateTaskExecutor.ClusterTasksResult<java.lang.Object> executeTasks(MasterService.TaskInputs taskInputs, long startTimeNS, ClusterState previousClusterState)
-
getNonFailedTasks
public java.util.List<org.elasticsearch.cluster.service.MasterService.Batcher.UpdateTask> getNonFailedTasks(MasterService.TaskInputs taskInputs, ClusterStateTaskExecutor.ClusterTasksResult<java.lang.Object> clusterTasksResult)
-
submitStateUpdateTasks
public <T> void submitStateUpdateTasks(java.lang.String source, java.util.Map<T,ClusterStateTaskListener> tasks, ClusterStateTaskConfig config, ClusterStateTaskExecutor<T> executor)Submits a batch of cluster state update tasks; submitted updates are guaranteed to be processed together, potentially with more tasks of the same executor.- Type Parameters:
T- the type of the cluster state update task state- Parameters:
source- the source of the cluster state update tasktasks- a map of update tasks and their corresponding listenersconfig- the cluster state update task configurationexecutor- the cluster state update task executor; tasks that share the same executor will be executed batches on this executor
-
currentTimeInNanos
protected long currentTimeInNanos()
-
-