Skip to content
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

Wipe Snapshots Before Indices in RestTests (#39662) #39765

Merged
merged 1 commit into from
Mar 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.WarningsHandler;
import org.elasticsearch.cluster.SnapshotsInProgress;
import org.elasticsearch.common.CheckedRunnable;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.PathUtils;
Expand Down Expand Up @@ -72,6 +73,7 @@
import java.security.cert.CertificateException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -449,6 +451,8 @@ private void wipeCluster() throws Exception {
waitForPendingRollupTasks();
}

final Map<String, List<Map<?,?>>> inProgressSnapshots = wipeSnapshots();

if (preserveIndicesUponCompletion() == false) {
// wipe indices
try {
Expand Down Expand Up @@ -489,8 +493,6 @@ private void wipeCluster() throws Exception {
}
}

wipeSnapshots();

// wipe cluster settings
if (preserveClusterSettings() == false) {
wipeClusterSettings();
Expand All @@ -499,14 +501,18 @@ private void wipeCluster() throws Exception {
if (hasXPack && false == preserveILMPoliciesUponCompletion()) {
deleteAllPolicies();
}

assertTrue("Found in progress snapshots [" + inProgressSnapshots + "].", inProgressSnapshots.isEmpty());
}

/**
* Wipe fs snapshots we created one by one and all repositories so that the next test can create the repositories fresh and they'll
* start empty. There isn't an API to delete all snapshots. There is an API to delete all snapshot repositories but that leaves all of
* the snapshots intact in the repository.
* @return Map of repository name to list of snapshots found in unfinished state
*/
private void wipeSnapshots() throws IOException {
private Map<String, List<Map<?, ?>>> wipeSnapshots() throws IOException {
final Map<String, List<Map<?, ?>>> inProgressSnapshots = new HashMap<>();
for (Map.Entry<String, ?> repo : entityAsMap(adminClient.performRequest(new Request("GET", "/_snapshot/_all"))).entrySet()) {
String repoName = repo.getKey();
Map<?, ?> repoSpec = (Map<?, ?>) repo.getValue();
Expand All @@ -519,6 +525,9 @@ private void wipeSnapshots() throws IOException {
for (Object snapshot : snapshots) {
Map<?, ?> snapshotInfo = (Map<?, ?>) snapshot;
String name = (String) snapshotInfo.get("snapshot");
if (SnapshotsInProgress.State.valueOf((String) snapshotInfo.get("state")).completed() == false) {
inProgressSnapshots.computeIfAbsent(repoName, key -> new ArrayList<>()).add(snapshotInfo);
}
logger.debug("wiping snapshot [{}/{}]", repoName, name);
adminClient().performRequest(new Request("DELETE", "/_snapshot/" + repoName + "/" + name));
}
Expand All @@ -528,6 +537,7 @@ private void wipeSnapshots() throws IOException {
adminClient().performRequest(new Request("DELETE", "_snapshot/" + repoName));
}
}
return inProgressSnapshots;
}

/**
Expand Down