-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Unblock blocked repositories after test execution #61703
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
Closed
fcofdez
wants to merge
13
commits into
elastic:main
from
fcofdez:unblock-blocked-repositories-after-test
Closed
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8010e3b
Unblock blocked repositories after test execution.
fcofdez 5e7e95b
Check for repository instance type
fcofdez bdfc369
Move repository unblock to ESIntegTestCase cluster cleanup
fcofdez fad2cf8
Don't unblock repositories on non internal clusters
fcofdez cba3bcd
Unblock repositories only when the cluster is open
fcofdez 388d261
Merge remote-tracking branch 'origin/master' into unblock-blocked-rep…
fcofdez 7207a56
Merge remote-tracking branch 'origin/master' into unblock-blocked-rep…
fcofdez 60db1e3
Rename awaitNoMoreRunningSnapshotOperations
fcofdez 9aee157
Merge remote-tracking branch 'origin/master' into unblock-blocked-rep…
fcofdez 3b3cf8f
Keep track of blocked repos on AbstractSnapshotIntegTestCase.
fcofdez 0d7a454
Merge remote-tracking branch 'origin/master' into unblock-blocked-rep…
fcofdez 2849021
Use a Set instead
fcofdez f858059
fix checkstyle
fcofdez 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
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -56,17 +56,22 @@ | |
import org.elasticsearch.action.search.SearchResponse; | ||
import org.elasticsearch.action.support.DefaultShardOperationFailedException; | ||
import org.elasticsearch.action.support.IndicesOptions; | ||
import org.elasticsearch.action.support.PlainActionFuture; | ||
import org.elasticsearch.client.AdminClient; | ||
import org.elasticsearch.client.Client; | ||
import org.elasticsearch.client.Requests; | ||
import org.elasticsearch.client.RestClient; | ||
import org.elasticsearch.client.RestClientBuilder; | ||
import org.elasticsearch.cluster.ClusterModule; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.ClusterStateObserver; | ||
import org.elasticsearch.cluster.SnapshotDeletionsInProgress; | ||
import org.elasticsearch.cluster.SnapshotsInProgress; | ||
import org.elasticsearch.cluster.coordination.ElasticsearchNodeCommand; | ||
import org.elasticsearch.cluster.health.ClusterHealthStatus; | ||
import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
import org.elasticsearch.cluster.metadata.Metadata; | ||
import org.elasticsearch.cluster.metadata.RepositoryMetadata; | ||
import org.elasticsearch.cluster.routing.IndexRoutingTable; | ||
import org.elasticsearch.cluster.routing.IndexShardRoutingTable; | ||
import org.elasticsearch.cluster.routing.ShardRouting; | ||
|
@@ -116,20 +121,26 @@ | |
import org.elasticsearch.indices.IndicesQueryCache; | ||
import org.elasticsearch.indices.IndicesRequestCache; | ||
import org.elasticsearch.indices.store.IndicesStore; | ||
import org.elasticsearch.node.NodeClosedException; | ||
import org.elasticsearch.node.NodeMocksPlugin; | ||
import org.elasticsearch.plugins.NetworkPlugin; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.repositories.RepositoriesService; | ||
import org.elasticsearch.repositories.Repository; | ||
import org.elasticsearch.repositories.RepositoryMissingException; | ||
import org.elasticsearch.rest.RestStatus; | ||
import org.elasticsearch.rest.action.RestCancellableNodeClient; | ||
import org.elasticsearch.script.MockScriptService; | ||
import org.elasticsearch.search.MockSearchService; | ||
import org.elasticsearch.search.SearchHit; | ||
import org.elasticsearch.search.SearchService; | ||
import org.elasticsearch.snapshots.mockstore.MockRepository; | ||
import org.elasticsearch.test.client.RandomizingClient; | ||
import org.elasticsearch.test.disruption.NetworkDisruption; | ||
import org.elasticsearch.test.disruption.ServiceDisruptionScheme; | ||
import org.elasticsearch.test.store.MockFSIndexStore; | ||
import org.elasticsearch.test.transport.MockTransportService; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.transport.TransportInterceptor; | ||
import org.elasticsearch.transport.TransportRequest; | ||
import org.elasticsearch.transport.TransportRequestHandler; | ||
|
@@ -168,8 +179,10 @@ | |
import java.util.concurrent.CopyOnWriteArrayList; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.function.Function; | ||
import java.util.function.Predicate; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS; | ||
|
@@ -547,6 +560,7 @@ private void afterInternal(boolean afterClass) throws Exception { | |
ensureClusterSizeConsistency(); | ||
ensureClusterStateConsistency(); | ||
ensureClusterStateCanBeReadByNodeTool(); | ||
unblockRepositories(); | ||
beforeIndexDeletion(); | ||
cluster().wipe(excludeTemplates()); // wipe after to make sure we fail in the test that didn't ack the delete | ||
if (afterClass || currentClusterScope == Scope.TEST) { | ||
|
@@ -569,6 +583,27 @@ private void afterInternal(boolean afterClass) throws Exception { | |
} | ||
} | ||
|
||
public void unblockRepositories() throws Exception { | ||
if (isInternalCluster() == false || cluster().size() == 0) { | ||
return; | ||
} | ||
List<RepositoryMetadata> repositories = admin().cluster().prepareGetRepositories().get().repositories(); | ||
for (RepositoriesService repositoriesService : internalCluster().getDataOrMasterNodeInstances(RepositoriesService.class)) { | ||
for (RepositoryMetadata repositoryMetadata : repositories) { | ||
try { | ||
Repository repository = repositoriesService.repository(repositoryMetadata.name()); | ||
if (repository instanceof MockRepository) { | ||
((MockRepository) repository).unblock(); | ||
} | ||
} catch (RepositoryMissingException e) { | ||
// ignore missing repositories | ||
} | ||
} | ||
} | ||
|
||
awaitNoMoreSnapshotRunningOperations(internalCluster().getMasterName()); | ||
} | ||
|
||
/** | ||
* @return An exclude set of index templates that will not be removed in between tests. | ||
*/ | ||
|
@@ -2205,4 +2240,36 @@ public static String resolveCustomDataPath(String index) { | |
public static boolean inFipsJvm() { | ||
return Boolean.parseBoolean(System.getProperty(FIPS_SYSPROP)); | ||
} | ||
|
||
protected void awaitNoMoreSnapshotRunningOperations(String viaNode) throws Exception { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: reorder this to natural word order |
||
logger.info("--> verify no more operations in the cluster state"); | ||
awaitClusterState(viaNode, state -> state.custom(SnapshotsInProgress.TYPE, SnapshotsInProgress.EMPTY).entries().isEmpty() && | ||
state.custom(SnapshotDeletionsInProgress.TYPE, SnapshotDeletionsInProgress.EMPTY).hasDeletionsInProgress() == false); | ||
} | ||
|
||
protected void awaitClusterState(String viaNode, Predicate<ClusterState> statePredicate) throws Exception { | ||
final ClusterService clusterService = internalCluster().getInstance(ClusterService.class, viaNode); | ||
final ThreadPool threadPool = internalCluster().getInstance(ThreadPool.class, viaNode); | ||
final ClusterStateObserver observer = new ClusterStateObserver(clusterService, logger, threadPool.getThreadContext()); | ||
if (statePredicate.test(observer.setAndGetObservedState()) == false) { | ||
final PlainActionFuture<Void> future = PlainActionFuture.newFuture(); | ||
observer.waitForNextChange(new ClusterStateObserver.Listener() { | ||
@Override | ||
public void onNewClusterState(ClusterState state) { | ||
future.onResponse(null); | ||
} | ||
|
||
@Override | ||
public void onClusterServiceClose() { | ||
future.onFailure(new NodeClosedException(clusterService.localNode())); | ||
} | ||
|
||
@Override | ||
public void onTimeout(TimeValue timeout) { | ||
future.onFailure(new TimeoutException()); | ||
} | ||
}, statePredicate); | ||
future.get(30L, TimeUnit.SECONDS); | ||
} | ||
} | ||
} |
This file contains hidden or 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.
I'm a little unsure about this. I think we should only run this if the original test failed shouldn't we? (this is what we do in REST tests)
Otherwise we can have tests leaking running/blocked snapshots in the background and are quietly cleaning them up here?
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.
Yes, that makes sense. do we have something like
getSuiteFailureMarker()
but for a single test? I cannot find any method like that onESTestCase
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.
Maybe
org.elasticsearch.test.ESTestCase#afterIfFailed
will work here (I haven't checked the exact order of things I must admit). If it's called too late maybe we can do something with a@Rule
? (I must admit I'm not an expert in JUnit so the latter is a bit of a guess).