Skip to content

Commit

Permalink
[7.13] Delete mounted indices after test case in ESRestTestCase (#73649)
Browse files Browse the repository at this point in the history
This commit adds some clean up logic to ESRestTestCase so 
that searchable snapshots indices are deleted after test case 
executions, before the snapshot and repositories are wipe out.

Backport of #73555
  • Loading branch information
tlrx committed Jun 2, 2021
1 parent 10cb774 commit 5b8bb7f
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,15 @@ protected boolean preserveAutoFollowPatternsUponCompletion() {
return false;
}

/**
* Returns whether to preserve searchable snapshots indices. Defaults to not
* preserving them. Only runs at all if xpack is installed on the cluster
* being tested.
*/
protected boolean preserveSearchableSnapshotsIndicesUponCompletion() {
return false;
}

/**
* Returns whether to wait to make absolutely certain that all snapshots
* have been deleted.
Expand All @@ -591,6 +600,11 @@ private void wipeCluster() throws Exception {
}
}

// Clean up searchable snapshots indices before deleting snapshots and repositories
if (hasXPack() && nodeVersions.first().onOrAfter(Version.V_7_8_0) && preserveSearchableSnapshotsIndicesUponCompletion() == false) {
wipeSearchableSnapshotsIndices();
}

SetOnce<Map<String, List<Map<?,?>>>> inProgressSnapshots = new SetOnce<>();
if (waitForAllSnapshotsWiped()) {
AtomicReference<Map<String, List<Map<?,?>>>> snapshots = new AtomicReference<>();
Expand Down Expand Up @@ -796,6 +810,22 @@ protected static void wipeDataStreams() throws IOException {
}
}

protected void wipeSearchableSnapshotsIndices() throws IOException {
// retrieves all indices with a type of store equals to "snapshot"
final Request request = new Request("GET", "_cluster/state/metadata");
request.addParameter("filter_path", "metadata.indices.*.settings.index.store.snapshot");

final Response response = adminClient().performRequest(request);
@SuppressWarnings("unchecked")
Map<String, ?> indices = (Map<String, ?>) XContentMapValues.extractValue("metadata.indices", entityAsMap(response));
if (indices != null) {
for (String index : indices.keySet()) {
assertAcked("Failed to delete searchable snapshot index [" + index + ']',
adminClient().performRequest(new Request("DELETE", index)));
}
}
}

/**
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,6 @@ setup:
indices.delete:
index: docs

---
teardown:

- do:
snapshot.delete:
repository: repository-fs
snapshot: snapshot
ignore: 404

- do:
snapshot.delete_repository:
repository: repository-fs

---
"Clear searchable snapshots cache":
- skip:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,6 @@ setup:
- do:
indices.delete:
index: docs
---
teardown:

- do:
snapshot.delete:
repository: repository-fs
snapshot: snapshot
ignore: 404

- do:
snapshot.delete_repository:
repository: repository-fs

---
"Tests Indices Stats API for snapshot backed indices":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,6 @@ setup:
- do:
indices.delete:
index: docs
---
teardown:

- do:
snapshot.delete:
repository: repository-fs
snapshot: snapshot
ignore: 404

- do:
snapshot.delete_repository:
repository: repository-fs

---
"Tests searches vs default-storage index":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,6 @@ setup:
- do:
indices.delete:
index: docs
---
teardown:

- do:
snapshot.delete:
repository: repository-fs
snapshot: snapshot
ignore: 404

- do:
snapshot.delete_repository:
repository: repository-fs

---
"Node Cache Stats API with Frozen Indices":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,6 @@ setup:
- do:
indices.delete:
index: docs
---
teardown:

- do:
snapshot.delete:
repository: repository-fs
snapshot: snapshot
ignore: 404

- do:
snapshot.delete_repository:
repository: repository-fs

---
"Tests searchable snapshots stats":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ protected boolean preserveDataStreamsUponCompletion() {
return true;
}

@Override
protected boolean preserveSearchableSnapshotsIndicesUponCompletion() {
return true;
}

enum ClusterType {
OLD,
MIXED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ protected boolean preserveSnapshotsUponCompletion() {
return true;
}

@Override
protected boolean preserveSearchableSnapshotsIndicesUponCompletion() {
return true;
}

public UpgradeClusterClientYamlTestSuiteIT(ClientYamlTestCandidate testCandidate) {
super(testCandidate);
}
Expand Down

0 comments on commit 5b8bb7f

Please sign in to comment.