-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make GetSnapshotsAction Cancellable #72644
Merged
original-brownbear
merged 3 commits into
elastic:master
from
original-brownbear:make-get-snapshots-cancellable
May 4, 2021
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dispatching to
EsExecutors.DIRECT_EXECUTOR_SERVICE
seems a bit weird. Is this becauseRestToXContentListener
doesn't check for cancellation before callingtoXContent()
? If so, can we address that inRestToXContentListener
instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea that was because we didn't have that check in the general listener. Should we maybe make that move in a separate PR? Even though it seems like "nothing could go wrong" by doing that, might be better having it in isolation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, sounds like a good plan.