Skip to content

Commit 3eda530

Browse files
Fix X-Pack Indices Breaking Repository BwC Tests (#51120)
If some internal `.watcher` or so index gets created during these tests then the shard counts on snapshot restores and creates won't match up with expectations. Fixed by only creating the snapshot for the test index Closes #50819
1 parent bdd7bda commit 3eda530

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

qa/repository-multi-version/src/test/java/org/elasticsearch/upgrades/MultiVersionRepositoryAccessIT.java

+15-12
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,14 @@ public void testCreateAndRestoreSnapshot() throws IOException {
115115
final String repoName = getTestName();
116116
try (RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(adminClient().getNodes().toArray(new Node[0])))) {
117117
final int shards = 3;
118-
createIndex(client, "test-index", shards);
118+
final String index = "test-index";
119+
createIndex(client, index, shards);
119120
createRepository(client, repoName, false);
120-
createSnapshot(client, repoName, "snapshot-" + TEST_STEP);
121+
createSnapshot(client, repoName, "snapshot-" + TEST_STEP, index);
121122
final String snapshotToDeleteName = "snapshot-to-delete";
122123
// Create a snapshot and delete it right away again to test the impact of each version's cleanup functionality that is run
123124
// as part of the snapshot delete
124-
createSnapshot(client, repoName, snapshotToDeleteName);
125+
createSnapshot(client, repoName, snapshotToDeleteName, index);
125126
final List<Map<String, Object>> snapshotsIncludingToDelete = listSnapshots(repoName);
126127
// Every step creates one snapshot and we have to add one more for the temporary snapshot
127128
assertThat(snapshotsIncludingToDelete, hasSize(TEST_STEP.ordinal() + 1 + 1));
@@ -162,9 +163,10 @@ public void testReadOnlyRepo() throws IOException {
162163
final int shards = 3;
163164
final boolean readOnly = TEST_STEP.ordinal() > 1; // only restore from read-only repo in steps 3 and 4
164165
createRepository(client, repoName, readOnly);
166+
final String index = "test-index";
165167
if (readOnly == false) {
166-
createIndex(client, "test-index", shards);
167-
createSnapshot(client, repoName, "snapshot-" + TEST_STEP);
168+
createIndex(client, index, shards);
169+
createSnapshot(client, repoName, "snapshot-" + TEST_STEP, index);
168170
}
169171
final List<Map<String, Object>> snapshots = listSnapshots(repoName);
170172
switch (TEST_STEP) {
@@ -196,11 +198,12 @@ public void testUpgradeMovesRepoToNewMetaVersion() throws IOException {
196198
final String repoName = getTestName();
197199
try (RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(adminClient().getNodes().toArray(new Node[0])))) {
198200
final int shards = 3;
199-
createIndex(client, "test-index", shards);
201+
final String index= "test-index";
202+
createIndex(client, index, shards);
200203
createRepository(client, repoName, false);
201204
// only create some snapshots in the first two steps
202205
if (TEST_STEP == TestStep.STEP1_OLD_CLUSTER || TEST_STEP == TestStep.STEP2_NEW_CLUSTER) {
203-
createSnapshot(client, repoName, "snapshot-" + TEST_STEP);
206+
createSnapshot(client, repoName, "snapshot-" + TEST_STEP, index);
204207
final List<Map<String, Object>> snapshots = listSnapshots(repoName);
205208
// Every step creates one snapshot
206209
assertThat(snapshots, hasSize(TEST_STEP.ordinal() + 1));
@@ -211,10 +214,10 @@ public void testUpgradeMovesRepoToNewMetaVersion() throws IOException {
211214
} else {
212215
deleteSnapshot(client, repoName, "snapshot-" + TestStep.STEP1_OLD_CLUSTER);
213216
ensureSnapshotRestoreWorks(client, repoName, "snapshot-" + TestStep.STEP2_NEW_CLUSTER, shards);
214-
createSnapshot(client, repoName, "snapshot-1");
217+
createSnapshot(client, repoName, "snapshot-1", index);
215218
ensureSnapshotRestoreWorks(client, repoName, "snapshot-1", shards);
216219
deleteSnapshot(client, repoName, "snapshot-" + TestStep.STEP2_NEW_CLUSTER);
217-
createSnapshot(client, repoName, "snapshot-2");
220+
createSnapshot(client, repoName, "snapshot-2", index);
218221
ensureSnapshotRestoreWorks(client, repoName, "snapshot-2", shards);
219222
}
220223
} else {
@@ -225,7 +228,7 @@ public void testUpgradeMovesRepoToNewMetaVersion() throws IOException {
225228
expectThrowsAnyOf(expectedExceptions, () -> listSnapshots(repoName));
226229
expectThrowsAnyOf(expectedExceptions, () -> deleteSnapshot(client, repoName, "snapshot-1"));
227230
expectThrowsAnyOf(expectedExceptions, () -> deleteSnapshot(client, repoName, "snapshot-2"));
228-
expectThrowsAnyOf(expectedExceptions, () -> createSnapshot(client, repoName, "snapshot-impossible"));
231+
expectThrowsAnyOf(expectedExceptions, () -> createSnapshot(client, repoName, "snapshot-impossible", index));
229232
} else {
230233
assertThat(listSnapshots(repoName), hasSize(2));
231234
if (TEST_STEP == TestStep.STEP4_NEW_CLUSTER) {
@@ -284,8 +287,8 @@ private static void createRepository(RestHighLevelClient client, String repoName
284287
is(true));
285288
}
286289

287-
private static void createSnapshot(RestHighLevelClient client, String repoName, String name) throws IOException {
288-
client.snapshot().create(new CreateSnapshotRequest(repoName, name).waitForCompletion(true), RequestOptions.DEFAULT);
290+
private static void createSnapshot(RestHighLevelClient client, String repoName, String name, String index) throws IOException {
291+
client.snapshot().create(new CreateSnapshotRequest(repoName, name).waitForCompletion(true).indices(index), RequestOptions.DEFAULT);
289292
}
290293

291294
private void createIndex(RestHighLevelClient client, String name, int shards) throws IOException {

0 commit comments

Comments
 (0)