|
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;
|
43 | 46 | import java.io.InputStream;
|
44 | 47 | import java.net.HttpURLConnection;
|
| 48 | +import java.util.Arrays; |
45 | 49 | import java.util.List;
|
46 | 50 | import java.util.Map;
|
47 | 51 | import java.util.stream.Collectors;
|
|
60 | 64 | * <li>Run against the old version cluster from the first step: {@link TestStep#STEP3_OLD_CLUSTER}</li>
|
61 | 65 | * <li>Run against the current version cluster from the second step: {@link TestStep#STEP4_NEW_CLUSTER}</li>
|
62 | 66 | * </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 | 67 | */
|
66 | 68 | public class MultiVersionRepositoryAccessIT extends ESRestTestCase {
|
67 | 69 |
|
@@ -98,7 +100,7 @@ public static TestStep parse(String value) {
|
98 | 100 | }
|
99 | 101 | }
|
100 | 102 |
|
101 |
| - protected static final TestStep TEST_STEP = TestStep.parse(System.getProperty("tests.rest.suite")); |
| 103 | + private static final TestStep TEST_STEP = TestStep.parse(System.getProperty("tests.rest.suite")); |
102 | 104 |
|
103 | 105 | @Override
|
104 | 106 | protected boolean preserveSnapshotsUponCompletion() {
|
@@ -192,31 +194,46 @@ public void testReadOnlyRepo() throws IOException {
|
192 | 194 | }
|
193 | 195 |
|
194 | 196 | public void testUpgradeMovesRepoToNewMetaVersion() throws IOException {
|
195 |
| - if (TEST_STEP.ordinal() > 1) { |
196 |
| - // Only testing the first 2 steps here |
197 |
| - return; |
198 |
| - } |
199 | 197 | final String repoName = getTestName();
|
200 | 198 | try (RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(adminClient().getNodes().toArray(new Node[0])))) {
|
201 | 199 | final int shards = 3;
|
202 | 200 | createIndex(client, "test-index", shards);
|
203 | 201 | 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); |
| 202 | + // only create some snapshots in the first two steps |
| 203 | + if (TEST_STEP == TestStep.STEP1_OLD_CLUSTER || TEST_STEP == TestStep.STEP2_NEW_CLUSTER) { |
| 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); |
| 212 | + } 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); |
| 220 | + } |
212 | 221 | } 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); |
| 222 | + if (minimumNodeVersion().before(SnapshotsService.SHARD_GEN_IN_REPO_DATA_VERSION)) { |
| 223 | + assertThat(TEST_STEP, is(TestStep.STEP3_OLD_CLUSTER)); |
| 224 | + final List<Class<? extends Exception>> expectedExceptions = |
| 225 | + Arrays.asList(ResponseException.class, ElasticsearchStatusException.class); |
| 226 | + expectThrowsAnyOf(expectedExceptions, () -> listSnapshots(repoName)); |
| 227 | + expectThrowsAnyOf(expectedExceptions, () -> deleteSnapshot(client, repoName, "snapshot-1")); |
| 228 | + expectThrowsAnyOf(expectedExceptions, () -> deleteSnapshot(client, repoName, "snapshot-2")); |
| 229 | + expectThrowsAnyOf(expectedExceptions, () -> createSnapshot(client, repoName, "snapshot-impossible")); |
| 230 | + } else { |
| 231 | + assertThat(listSnapshots(repoName), hasSize(2)); |
| 232 | + if (TEST_STEP == TestStep.STEP4_NEW_CLUSTER) { |
| 233 | + ensureSnapshotRestoreWorks(client, repoName, "snapshot-1", shards); |
| 234 | + ensureSnapshotRestoreWorks(client, repoName, "snapshot-2", shards); |
| 235 | + } |
| 236 | + } |
220 | 237 | }
|
221 | 238 | } finally {
|
222 | 239 | deleteRepository(repoName);
|
|
0 commit comments