Interface ClusterStateTaskExecutor<T extends ClusterStateTaskListener>
- Type Parameters:
T- The type of tasks to execute.
- All Known Implementing Classes:
NodeJoinExecutor,NodeLeftExecutor,ReservedStateUpdateTaskExecutor,SequentialAckingBatchedTaskExecutor,ShardStateAction.ShardFailedClusterStateTaskExecutor,ShardStateAction.ShardStartedClusterStateTaskExecutor,SimpleBatchedAckListenerTaskExecutor,SimpleBatchedExecutor
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordEncapsulates the context in which a batch of tasks executes.static interfaceA task to be executed, along with callbacks for the executor to record the outcome of this task's execution. -
Method Summary
Modifier and TypeMethodDescriptiondefault voidclusterStatePublished(ClusterState newClusterState) Callback invoked after new cluster state is published.default StringdescribeTasks(List<T> tasks) Builds a concise description of a list of tasks (to be used in logging etc.).execute(ClusterStateTaskExecutor.BatchExecutionContext<T> batchExecutionContext) Update the cluster state based on the current state and the given tasks.default boolean
-
Method Details
-
execute
ClusterState execute(ClusterStateTaskExecutor.BatchExecutionContext<T> batchExecutionContext) throws Exception Update the cluster state based on the current state and the given tasks. ReturnbatchExecutionContext.initialState()to avoid publishing any update.If this method throws an exception then the cluster state is unchanged and every task's
ClusterStateTaskListener.onFailure(java.lang.Exception)method is called.A common implementation pattern is to iterate through the tasks, constructing a new and updated
ClusterStatefor each one. This works ok but beware that constructing a whole newClusterStatecan be somewhat expensive, and there may sometimes be surprisingly many tasks to process in the batch. If it's possible to accumulate the effects of the tasks at a lower level then you should do that instead.Returning
batchExecutionContext.initialState()is an important and useful optimisation in most cases, but note that this fast-path exposes APIs to the risk of stale reads in the vicinity of a master failover: a nodeNthat handles such a no-op task batch does not verify with its peers that it's still the master, and if it's not the master then another nodeMmay already have become master and updated the state in a way that would be inconsistent with the response thatNsends back to clients.- Returns:
- The resulting cluster state after executing all the tasks. If
batchExecutionContext.initialState()is returned then no update is published. - Throws:
Exception
-
runOnlyOnMaster
default boolean runOnlyOnMaster()- Returns:
trueiff this executor should only run on the elected master.
-
clusterStatePublished
Callback invoked after new cluster state is published. Note that this method is not invoked if the cluster state was not updated. Note that this method will be executed using system context.- Parameters:
newClusterState- The new state which was published.
-
describeTasks
Builds a concise description of a list of tasks (to be used in logging etc.). Note that the tasks given are not necessarily the same as those that will be passed toexecute(org.elasticsearch.cluster.ClusterStateTaskExecutor.BatchExecutionContext<T>)but are guaranteed to be a subset of them. This method can be called multiple times with different lists before execution.- Parameters:
tasks- the tasks to describe.- Returns:
- A string which describes the batch of tasks.
-