Skip to content
Merged
Show file tree
Hide file tree
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 @@ -158,7 +158,7 @@ public void testEnforcedCooldownPeriod() throws IOException {
final BlobStoreRepository repository = (BlobStoreRepository) repositoriesService.repository(repoName);
final RepositoryData repositoryData = getRepositoryData(repository);
final RepositoryData modifiedRepositoryData = repositoryData.withVersions(Collections.singletonMap(fakeOldSnapshot,
SnapshotsService.SHARD_GEN_IN_REPO_DATA_VERSION.minimumCompatibilityVersion())).withoutUuid();
SnapshotsService.SHARD_GEN_IN_REPO_DATA_VERSION.minimumCompatibilityVersion())).withoutRepositoryUUID().withoutClusterUUID();
final BytesReference serialized = BytesReference.bytes(modifiedRepositoryData.snapshotsToXContent(XContentFactory.jsonBuilder(),
SnapshotsService.OLD_SNAPSHOT_FORMAT));
PlainActionFuture.get(f -> repository.threadPool().generic().execute(ActionRunnable.run(f, () ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.elasticsearch.upgrades;

import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.Version;
import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest;
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest;
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest;
Expand Down Expand Up @@ -116,7 +117,7 @@ public void testCreateAndRestoreSnapshot() throws IOException {
final int shards = 3;
final String index = "test-index";
createIndex(client, index, shards);
createRepository(client, repoName, false);
createRepository(client, repoName, false, true);
createSnapshot(client, repoName, "snapshot-" + TEST_STEP, index);
final String snapshotToDeleteName = "snapshot-to-delete";
// Create a snapshot and delete it right away again to test the impact of each version's cleanup functionality that is run
Expand Down Expand Up @@ -161,7 +162,7 @@ public void testReadOnlyRepo() throws IOException {
try (RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(adminClient().getNodes().toArray(new Node[0])))) {
final int shards = 3;
final boolean readOnly = TEST_STEP.ordinal() > 1; // only restore from read-only repo in steps 3 and 4
createRepository(client, repoName, readOnly);
createRepository(client, repoName, readOnly, true);
final String index = "test-index";
if (readOnly == false) {
createIndex(client, index, shards);
Expand Down Expand Up @@ -193,13 +194,25 @@ public void testReadOnlyRepo() throws IOException {
}
}

private static final List<Class<? extends Exception>> EXPECTED_BWC_EXCEPTIONS =
List.of(ResponseException.class, ElasticsearchStatusException.class);

public void testUpgradeMovesRepoToNewMetaVersion() throws IOException {
final String repoName = getTestName();
try (RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(adminClient().getNodes().toArray(new Node[0])))) {
final int shards = 3;
final String index= "test-index";
createIndex(client, index, shards);
createRepository(client, repoName, false);
final Version minNodeVersion = minimumNodeVersion();
// 7.12.0+ will try to load RepositoryData during repo creation if verify is true, which is impossible in case of version
// incompatibility in the downgrade test step. We verify that it is impossible here and then create the repo using verify=false
// to check behavior on other operations below.
final boolean verify = TEST_STEP != TestStep.STEP3_OLD_CLUSTER || SnapshotsService.includesClusterUUID(minNodeVersion)
|| minNodeVersion.before(Version.V_7_12_0);
if (verify == false) {
expectThrowsAnyOf(EXPECTED_BWC_EXCEPTIONS, () -> createRepository(client, repoName, false, true));
}
createRepository(client, repoName, false, verify);
// only create some snapshots in the first two steps
if (TEST_STEP == TestStep.STEP1_OLD_CLUSTER || TEST_STEP == TestStep.STEP2_NEW_CLUSTER) {
createSnapshot(client, repoName, "snapshot-" + TEST_STEP, index);
Expand All @@ -220,14 +233,12 @@ public void testUpgradeMovesRepoToNewMetaVersion() throws IOException {
ensureSnapshotRestoreWorks(client, repoName, "snapshot-2", shards);
}
} else {
if (SnapshotsService.includesRepositoryUuid(minimumNodeVersion()) == false) {
if (SnapshotsService.includesClusterUUID(minNodeVersion) == false) {
assertThat(TEST_STEP, is(TestStep.STEP3_OLD_CLUSTER));
final List<Class<? extends Exception>> expectedExceptions =
List.of(ResponseException.class, ElasticsearchStatusException.class);
expectThrowsAnyOf(expectedExceptions, () -> listSnapshots(repoName));
expectThrowsAnyOf(expectedExceptions, () -> deleteSnapshot(client, repoName, "snapshot-1"));
expectThrowsAnyOf(expectedExceptions, () -> deleteSnapshot(client, repoName, "snapshot-2"));
expectThrowsAnyOf(expectedExceptions, () -> createSnapshot(client, repoName, "snapshot-impossible", index));
expectThrowsAnyOf(EXPECTED_BWC_EXCEPTIONS, () -> listSnapshots(repoName));
expectThrowsAnyOf(EXPECTED_BWC_EXCEPTIONS, () -> deleteSnapshot(client, repoName, "snapshot-1"));
expectThrowsAnyOf(EXPECTED_BWC_EXCEPTIONS, () -> deleteSnapshot(client, repoName, "snapshot-2"));
expectThrowsAnyOf(EXPECTED_BWC_EXCEPTIONS, () -> createSnapshot(client, repoName, "snapshot-impossible", index));
} else {
assertThat(listSnapshots(repoName), hasSize(2));
if (TEST_STEP == TestStep.STEP4_NEW_CLUSTER) {
Expand Down Expand Up @@ -280,9 +291,11 @@ private static void ensureSnapshotRestoreWorks(RestHighLevelClient client, Strin
assertThat(restoreInfo.successfulShards(), equalTo(shards));
}

private static void createRepository(RestHighLevelClient client, String repoName, boolean readOnly) throws IOException {
private static void createRepository(RestHighLevelClient client, String repoName, boolean readOnly,
boolean verify) throws IOException {
assertThat(client.snapshot().createRepository(new PutRepositoryRequest(repoName).type("fs").settings(
Settings.builder().put("location", "./" + repoName).put("readonly", readOnly)), RequestOptions.DEFAULT).isAcknowledged(),
Settings.builder().put("location", "./" + repoName).put("readonly", readOnly)).verify(verify), RequestOptions.DEFAULT)
.isAcknowledged(),
is(true));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ public void testHandlingMissingRootLevelSnapshotMetadata() throws Exception {
Collections.emptyMap(),
Collections.emptyMap(),
ShardGenerations.EMPTY,
IndexMetaDataGenerations.EMPTY);
IndexMetaDataGenerations.EMPTY,
RepositoryData.MISSING_UUID); // old-format repository has no cluster UUID

Files.write(repo.resolve(BlobStoreRepository.INDEX_FILE_PREFIX + withoutVersions.getGenId()),
BytesReference.toBytes(BytesReference.bytes(
Expand Down Expand Up @@ -346,7 +347,7 @@ public void testRepairBrokenShardGenerations() throws Exception {
snapshotIds.values().stream().collect(Collectors.toMap(SnapshotId::getUUID, repositoryData::getVersion)),
repositoryData.getIndices().values().stream().collect(Collectors.toMap(Function.identity(), repositoryData::getSnapshots)),
ShardGenerations.builder().putAll(repositoryData.shardGenerations()).put(indexId, 0, "0").build(),
repositoryData.indexMetaDataGenerations());
repositoryData.indexMetaDataGenerations(), repositoryData.getClusterUUID());
Files.write(repoPath.resolve(BlobStoreRepository.INDEX_FILE_PREFIX + repositoryData.getGenId()),
BytesReference.toBytes(BytesReference.bytes(
brokenRepoData.snapshotsToXContent(XContentFactory.jsonBuilder(), Version.CURRENT))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ public void testConcurrentDeleteFromOtherCluster() throws InterruptedException {
assertThat(sne.getMessage(), containsString("failed to update snapshot in repository"));
final RepositoryException cause = (RepositoryException) sne.getCause();
assertThat(cause.getMessage(), containsString("[" + repoNameOnFirstCluster +
"] concurrent modification of the index-N file, expected current generation [2] but it was not found in the repository"));
"] concurrent modification of the index-N file, expected current generation [2] but it was not found in the repository."
+ " The last cluster to write to this repository was ["
+ secondCluster.client().admin().cluster().prepareState().get().getState().metadata().clusterUUID()
+ "] at generation [4]."));
assertAcked(client().admin().cluster().prepareDeleteRepository(repoNameOnFirstCluster).get());
createRepository(repoNameOnFirstCluster, "fs", repoPath);
createFullSnapshot(repoNameOnFirstCluster, "snap-5");
Expand Down
Loading