|
19 | 19 |
|
20 | 20 | package org.elasticsearch.upgrades; |
21 | 21 |
|
| 22 | +import org.elasticsearch.ElasticsearchStatusException; |
22 | 23 | import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest; |
23 | 24 | import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest; |
24 | 25 | import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest; |
|
30 | 31 | import org.elasticsearch.client.Request; |
31 | 32 | import org.elasticsearch.client.RequestOptions; |
32 | 33 | import org.elasticsearch.client.Response; |
| 34 | +import org.elasticsearch.client.ResponseException; |
33 | 35 | import org.elasticsearch.client.RestClient; |
34 | 36 | import org.elasticsearch.client.RestHighLevelClient; |
35 | 37 | import org.elasticsearch.common.settings.Settings; |
36 | 38 | import org.elasticsearch.common.xcontent.DeprecationHandler; |
37 | 39 | import org.elasticsearch.common.xcontent.XContentParser; |
38 | 40 | import org.elasticsearch.common.xcontent.json.JsonXContent; |
39 | 41 | import org.elasticsearch.snapshots.RestoreInfo; |
| 42 | +import org.elasticsearch.snapshots.SnapshotsService; |
40 | 43 | import org.elasticsearch.test.rest.ESRestTestCase; |
41 | 44 |
|
42 | 45 | import java.io.IOException; |
|
60 | 63 | * <li>Run against the old version cluster from the first step: {@link TestStep#STEP3_OLD_CLUSTER}</li> |
61 | 64 | * <li>Run against the current version cluster from the second step: {@link TestStep#STEP4_NEW_CLUSTER}</li> |
62 | 65 | * </ul> |
63 | | - * TODO: Add two more steps: delete all old version snapshots from the repository, then downgrade again and verify that the repository |
64 | | - * is not being corrupted. This requires first merging the logic for reading the min_version field in RepositoryData back to 7.6. |
65 | 66 | */ |
66 | 67 | public class MultiVersionRepositoryAccessIT extends ESRestTestCase { |
67 | 68 |
|
@@ -98,7 +99,7 @@ public static TestStep parse(String value) { |
98 | 99 | } |
99 | 100 | } |
100 | 101 |
|
101 | | - protected static final TestStep TEST_STEP = TestStep.parse(System.getProperty("tests.rest.suite")); |
| 102 | + private static final TestStep TEST_STEP = TestStep.parse(System.getProperty("tests.rest.suite")); |
102 | 103 |
|
103 | 104 | @Override |
104 | 105 | protected boolean preserveSnapshotsUponCompletion() { |
@@ -192,31 +193,46 @@ public void testReadOnlyRepo() throws IOException { |
192 | 193 | } |
193 | 194 |
|
194 | 195 | public void testUpgradeMovesRepoToNewMetaVersion() throws IOException { |
195 | | - if (TEST_STEP.ordinal() > 1) { |
196 | | - // Only testing the first 2 steps here |
197 | | - return; |
198 | | - } |
199 | 196 | final String repoName = getTestName(); |
200 | 197 | try (RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(adminClient().getNodes().toArray(new Node[0])))) { |
201 | 198 | final int shards = 3; |
202 | 199 | createIndex(client, "test-index", shards); |
203 | 200 | createRepository(client, repoName, false); |
204 | | - createSnapshot(client, repoName, "snapshot-" + TEST_STEP); |
205 | | - final List<Map<String, Object>> snapshots = listSnapshots(repoName); |
206 | | - // Every step creates one snapshot |
207 | | - assertThat(snapshots, hasSize(TEST_STEP.ordinal() + 1)); |
208 | | - assertSnapshotStatusSuccessful(client, repoName, |
209 | | - snapshots.stream().map(sn -> (String) sn.get("snapshot")).toArray(String[]::new)); |
210 | | - if (TEST_STEP == TestStep.STEP1_OLD_CLUSTER) { |
211 | | - ensureSnapshotRestoreWorks(client, repoName, "snapshot-" + TestStep.STEP1_OLD_CLUSTER, shards); |
| 201 | + // only create some snapshots in the first two steps |
| 202 | + if (TEST_STEP == TestStep.STEP1_OLD_CLUSTER || TEST_STEP == TestStep.STEP2_NEW_CLUSTER) { |
| 203 | + createSnapshot(client, repoName, "snapshot-" + TEST_STEP); |
| 204 | + final List<Map<String, Object>> snapshots = listSnapshots(repoName); |
| 205 | + // Every step creates one snapshot |
| 206 | + assertThat(snapshots, hasSize(TEST_STEP.ordinal() + 1)); |
| 207 | + assertSnapshotStatusSuccessful(client, repoName, |
| 208 | + snapshots.stream().map(sn -> (String) sn.get("snapshot")).toArray(String[]::new)); |
| 209 | + if (TEST_STEP == TestStep.STEP1_OLD_CLUSTER) { |
| 210 | + ensureSnapshotRestoreWorks(client, repoName, "snapshot-" + TestStep.STEP1_OLD_CLUSTER, shards); |
| 211 | + } else { |
| 212 | + deleteSnapshot(client, repoName, "snapshot-" + TestStep.STEP1_OLD_CLUSTER); |
| 213 | + ensureSnapshotRestoreWorks(client, repoName, "snapshot-" + TestStep.STEP2_NEW_CLUSTER, shards); |
| 214 | + createSnapshot(client, repoName, "snapshot-1"); |
| 215 | + ensureSnapshotRestoreWorks(client, repoName, "snapshot-1", shards); |
| 216 | + deleteSnapshot(client, repoName, "snapshot-" + TestStep.STEP2_NEW_CLUSTER); |
| 217 | + createSnapshot(client, repoName, "snapshot-2"); |
| 218 | + ensureSnapshotRestoreWorks(client, repoName, "snapshot-2", shards); |
| 219 | + } |
212 | 220 | } else { |
213 | | - deleteSnapshot(client, repoName, "snapshot-" + TestStep.STEP1_OLD_CLUSTER); |
214 | | - ensureSnapshotRestoreWorks(client, repoName, "snapshot-" + TestStep.STEP2_NEW_CLUSTER, shards); |
215 | | - createSnapshot(client, repoName, "snapshot-1"); |
216 | | - ensureSnapshotRestoreWorks(client, repoName, "snapshot-1", shards); |
217 | | - deleteSnapshot(client, repoName, "snapshot-" + TestStep.STEP2_NEW_CLUSTER); |
218 | | - createSnapshot(client, repoName, "snapshot-2"); |
219 | | - ensureSnapshotRestoreWorks(client, repoName, "snapshot-2", shards); |
| 221 | + if (minimumNodeVersion().before(SnapshotsService.SHARD_GEN_IN_REPO_DATA_VERSION)) { |
| 222 | + assertThat(TEST_STEP, is(TestStep.STEP3_OLD_CLUSTER)); |
| 223 | + final List<Class<? extends Exception>> expectedExceptions = |
| 224 | + List.of(ResponseException.class, ElasticsearchStatusException.class); |
| 225 | + expectThrowsAnyOf(expectedExceptions, () -> listSnapshots(repoName)); |
| 226 | + expectThrowsAnyOf(expectedExceptions, () -> deleteSnapshot(client, repoName, "snapshot-1")); |
| 227 | + expectThrowsAnyOf(expectedExceptions, () -> deleteSnapshot(client, repoName, "snapshot-2")); |
| 228 | + expectThrowsAnyOf(expectedExceptions, () -> createSnapshot(client, repoName, "snapshot-impossible")); |
| 229 | + } else { |
| 230 | + assertThat(listSnapshots(repoName), hasSize(2)); |
| 231 | + if (TEST_STEP == TestStep.STEP4_NEW_CLUSTER) { |
| 232 | + ensureSnapshotRestoreWorks(client, repoName, "snapshot-1", shards); |
| 233 | + ensureSnapshotRestoreWorks(client, repoName, "snapshot-2", shards); |
| 234 | + } |
| 235 | + } |
220 | 236 | } |
221 | 237 | } finally { |
222 | 238 | deleteRepository(repoName); |
|
0 commit comments