-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make cluster health API cancellable (#96990)
This API can be quite heavy in large clusters, and might spam the `MANAGEMENT` threadpool queue with work for clients that have long-since given up. This commit adds some basic cancellability checks to reduce the problem. Backport of #96551 to 7.17
- Loading branch information
1 parent
e1995a7
commit eeedb98
Showing
7 changed files
with
163 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 96551 | ||
summary: Make cluster health API cancellable | ||
area: Distributed | ||
type: bug | ||
issues: [] |
71 changes: 71 additions & 0 deletions
71
...st-http/src/javaRestTest/java/org/elasticsearch/http/ClusterHealthRestCancellationIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.http; | ||
|
||
import org.apache.http.client.methods.HttpGet; | ||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthAction; | ||
import org.elasticsearch.action.support.PlainActionFuture; | ||
import org.elasticsearch.client.Cancellable; | ||
import org.elasticsearch.client.Request; | ||
import org.elasticsearch.client.Response; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.ClusterStateUpdateTask; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.Priority; | ||
|
||
import java.util.concurrent.CancellationException; | ||
import java.util.concurrent.CyclicBarrier; | ||
|
||
import static org.elasticsearch.action.support.ActionTestUtils.wrapAsRestResponseListener; | ||
import static org.elasticsearch.test.TaskAssertions.assertAllCancellableTasksAreCancelled; | ||
import static org.elasticsearch.test.TaskAssertions.awaitTaskWithPrefixOnMaster; | ||
|
||
public class ClusterHealthRestCancellationIT extends HttpSmokeTestCase { | ||
|
||
public void testClusterHealthRestCancellation() throws Exception { | ||
|
||
final CyclicBarrier barrier = new CyclicBarrier(2); | ||
|
||
internalCluster().getCurrentMasterNodeInstance(ClusterService.class) | ||
.submitStateUpdateTask("blocking", new ClusterStateUpdateTask() { | ||
@Override | ||
public ClusterState execute(ClusterState currentState) { | ||
safeAwait(barrier); | ||
safeAwait(barrier); | ||
return currentState; | ||
} | ||
|
||
@Override | ||
public void onFailure(String source, Exception e) { | ||
throw new AssertionError(e); | ||
} | ||
}); | ||
|
||
final Request clusterHealthRequest = new Request(HttpGet.METHOD_NAME, "/_cluster/health"); | ||
clusterHealthRequest.addParameter("wait_for_events", Priority.LANGUID.toString()); | ||
|
||
final PlainActionFuture<Response> future = new PlainActionFuture<>(); | ||
logger.info("--> sending cluster state request"); | ||
final Cancellable cancellable = getRestClient().performRequestAsync(clusterHealthRequest, wrapAsRestResponseListener(future)); | ||
|
||
safeAwait(barrier); | ||
|
||
awaitTaskWithPrefixOnMaster(ClusterHealthAction.NAME); | ||
|
||
logger.info("--> cancelling cluster health request"); | ||
cancellable.cancel(); | ||
expectThrows(CancellationException.class, future::actionGet); | ||
|
||
logger.info("--> checking cluster health task cancelled"); | ||
assertAllCancellableTasksAreCancelled(ClusterHealthAction.NAME); | ||
|
||
safeAwait(barrier); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters