Skip to content

Commit

Permalink
Dispatch ClusterStateAction#buildResponse to executor (#103435)
Browse files Browse the repository at this point in the history
If waiting for a particular cluster state (e.g. on the CCR leader) we
will compute the resulting cluster state and serialize it on the cluster
applier thread, which can be too expensive in a large cluster for this
thread. With this commit we dispatch the final action back to the
original executor.
  • Loading branch information
DaveCTurner committed Dec 14, 2023
1 parent 0d6d21c commit 92babbb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/changelog/103435.yaml
@@ -0,0 +1,5 @@
pr: 103435
summary: Dispatch `ClusterStateAction#buildResponse` to executor
area: Distributed
type: bug
issues: []
Expand Up @@ -11,6 +11,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRunnable;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.master.TransportMasterNodeReadAction;
import org.elasticsearch.cluster.ClusterState;
Expand Down Expand Up @@ -112,7 +113,7 @@ public void onNewClusterState(ClusterState newState) {
}

if (acceptableClusterStatePredicate.test(newState)) {
ActionListener.completeWith(listener, () -> buildResponse(request, newState));
executor.execute(ActionRunnable.supply(listener, () -> buildResponse(request, newState)));
} else {
listener.onFailure(
new NotMasterException(
Expand Down Expand Up @@ -150,6 +151,8 @@ private static Map<String, Set<String>> getClusterFeatures(ClusterState clusterS
}

private ClusterStateResponse buildResponse(final ClusterStateRequest request, final ClusterState currentState) {
ThreadPool.assertCurrentThreadPool(ThreadPool.Names.MANAGEMENT); // too heavy to construct & serialize cluster state without forking

logger.trace("Serving cluster state request using version {}", currentState.version());
ClusterState.Builder builder = ClusterState.builder(currentState.getClusterName());
builder.version(currentState.version());
Expand Down

0 comments on commit 92babbb

Please sign in to comment.