Skip to content

Commit

Permalink
Speedup HealthNodeTaskExecutor CS listener
Browse files Browse the repository at this point in the history
This method was quite slow in tests because there's an expensive
assertion in `ClusterApplierService.state()` that we run when calling
`ClusterService.localNode()`
  • Loading branch information
original-brownbear committed Sep 24, 2024
1 parent 3b5572d commit 62a4677
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ void startTask(ClusterChangedEvent event) {

// visible for testing
void shuttingDown(ClusterChangedEvent event) {
DiscoveryNode node = clusterService.localNode();
if (isNodeShuttingDown(event, node.getId())) {
if (isNodeShuttingDown(event)) {
var node = event.state().getNodes().getLocalNode();
abortTaskIfApplicable("node [{" + node.getName() + "}{" + node.getId() + "}] shutting down");
}
}
Expand All @@ -202,9 +202,18 @@ void abortTaskIfApplicable(String reason) {
}
}

private static boolean isNodeShuttingDown(ClusterChangedEvent event, String nodeId) {
return event.previousState().metadata().nodeShutdowns().contains(nodeId) == false
&& event.state().metadata().nodeShutdowns().contains(nodeId);
private static boolean isNodeShuttingDown(ClusterChangedEvent event) {
if (event.metadataChanged() == false) {
return false;
}
var shutdownsOld = event.previousState().metadata().nodeShutdowns();
var shutdownsNew = event.state().metadata().nodeShutdowns();
if (shutdownsNew == shutdownsOld) {
return false;
}
String nodeId = event.state().nodes().getLocalNodeId();
return shutdownsOld.contains(nodeId) == false && shutdownsNew.contains(nodeId);

}

public static List<NamedXContentRegistry.Entry> getNamedXContentParsers() {
Expand Down

0 comments on commit 62a4677

Please sign in to comment.