-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make GetSnapshotsAction Cancellable (#72644)
If this runs needlessly for large repositories (especially in timeout/retry situations) it's a significant memory+cpu hit => made it cancellable like we recently did for many other endpoints.
- Loading branch information
1 parent
98db349
commit 70f1e8c
Showing
5 changed files
with
140 additions
and
13 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
qa/smoke-test-http/src/test/java/org/elasticsearch/http/RestGetSnapshotsCancellationIT.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,90 @@ | ||
/* | ||
* 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.snapshots.get.GetSnapshotsAction; | ||
import org.elasticsearch.action.support.PlainActionFuture; | ||
import org.elasticsearch.client.Cancellable; | ||
import org.elasticsearch.client.Request; | ||
import org.elasticsearch.client.Response; | ||
import org.elasticsearch.client.ResponseListener; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.util.CollectionUtils; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.snapshots.AbstractSnapshotIntegTestCase; | ||
import org.elasticsearch.snapshots.SnapshotState; | ||
import org.elasticsearch.snapshots.mockstore.MockRepository; | ||
import org.elasticsearch.test.ESIntegTestCase; | ||
|
||
import java.util.Collection; | ||
import java.util.concurrent.CancellationException; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.elasticsearch.test.TaskAssertions.assertAllCancellableTasksAreCancelled; | ||
import static org.elasticsearch.test.TaskAssertions.assertAllTasksHaveFinished; | ||
import static org.elasticsearch.test.TaskAssertions.awaitTaskWithPrefix; | ||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
import static org.hamcrest.core.IsEqual.equalTo; | ||
|
||
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, numClientNodes = 0) | ||
public class RestGetSnapshotsCancellationIT extends HttpSmokeTestCase { | ||
|
||
@Override | ||
protected Collection<Class<? extends Plugin>> nodePlugins() { | ||
return CollectionUtils.appendToCopy(super.nodePlugins(), MockRepository.Plugin.class); | ||
} | ||
|
||
public void testGetSnapshotsCancellation() throws Exception { | ||
internalCluster().startMasterOnlyNode(); | ||
internalCluster().startDataOnlyNode(); | ||
ensureStableCluster(2); | ||
|
||
final String repoName = "test-repo"; | ||
assertAcked( | ||
client().admin().cluster().preparePutRepository(repoName) | ||
.setType("mock").setSettings(Settings.builder().put("location", randomRepoPath()))); | ||
|
||
final int snapshotCount = randomIntBetween(1, 5); | ||
for (int i = 0; i < snapshotCount; i++) { | ||
assertEquals( | ||
SnapshotState.SUCCESS, | ||
client().admin().cluster().prepareCreateSnapshot(repoName, "snapshot-" + i).setWaitForCompletion(true) | ||
.get().getSnapshotInfo().state() | ||
); | ||
} | ||
|
||
final MockRepository repository = AbstractSnapshotIntegTestCase.getRepositoryOnMaster(repoName); | ||
repository.setBlockOnAnyFiles(); | ||
|
||
final Request request = new Request(HttpGet.METHOD_NAME, "/_snapshot/" + repoName + "/*"); | ||
final PlainActionFuture<Void> future = new PlainActionFuture<>(); | ||
final Cancellable cancellable = getRestClient().performRequestAsync(request, new ResponseListener() { | ||
@Override | ||
public void onSuccess(Response response) { | ||
future.onResponse(null); | ||
} | ||
|
||
@Override | ||
public void onFailure(Exception exception) { | ||
future.onFailure(exception); | ||
} | ||
}); | ||
|
||
assertThat(future.isDone(), equalTo(false)); | ||
awaitTaskWithPrefix(GetSnapshotsAction.NAME); | ||
assertBusy(() -> assertTrue(repository.blocked()), 30L, TimeUnit.SECONDS); | ||
cancellable.cancel(); | ||
assertAllCancellableTasksAreCancelled(GetSnapshotsAction.NAME); | ||
repository.unblock(); | ||
expectThrows(CancellationException.class, future::actionGet); | ||
|
||
assertAllTasksHaveFinished(GetSnapshotsAction.NAME); | ||
} | ||
} |
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