- 
                Notifications
    You must be signed in to change notification settings 
- Fork 25.6k
Make SnapshotsInProgress project compatible #125470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
d07986e
              1b16e64
              e2e87f7
              ee51a49
              4656baa
              474b486
              3ce8cff
              df35d10
              e211f26
              d5ebf76
              99c248c
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|  | ||
| package org.elasticsearch.upgrades; | ||
|  | ||
| import com.carrotsearch.randomizedtesting.annotations.Name; | ||
|  | ||
| import org.elasticsearch.client.Request; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.test.rest.ObjectPath; | ||
|  | ||
| import java.io.IOException; | ||
| import java.util.Collection; | ||
|  | ||
| import static org.hamcrest.Matchers.equalTo; | ||
| import static org.hamcrest.Matchers.not; | ||
|  | ||
| public class RunningSnapshotIT extends AbstractRollingUpgradeTestCase { | ||
|  | ||
| public RunningSnapshotIT(@Name("upgradedNodes") int upgradedNodes) { | ||
| super(upgradedNodes); | ||
| } | ||
|  | ||
| public void testRunningSnapshotCompleteAfterUpgrade() throws Exception { | ||
| final String indexName = "index"; | ||
| final String repositoryName = "repo"; | ||
| final String snapshotName = "snapshot"; | ||
| final var nodeIds = getNodesInfo(client()).keySet(); | ||
|  | ||
| if (isOldCluster()) { | ||
| // create an index to have one shard per node | ||
| createIndex(indexName, indexSettings(3, 0).put("index.routing.allocation.total_shards_per_node", 1).build()); | ||
| ensureGreen(indexName); | ||
| flush(indexName, true); | ||
| // Signal shutdown to prevent snapshot from being completed | ||
| putShutdownMetadata(nodeIds); | ||
| registerRepository(repositoryName, "fs", randomBoolean(), Settings.builder().put("location", "backup").build()); | ||
|          | ||
| createSnapshot(repositoryName, snapshotName, false); | ||
| assertRunningSnapshot(repositoryName, snapshotName); | ||
| } else { | ||
| if (isUpgradedCluster()) { | ||
| deleteShutdownMetadata(nodeIds); | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe assert that no shutdown metadata exists after deleting it. It might make possible test failures more concrete. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have SnapshotShutdownProgressTracker reporting quite detailed information about shard snapshot pausing and resuming due to shutdown. That said, it does not hurt to double check as well. So I added it in e211f26 | ||
| ensureGreen(indexName); | ||
| assertBusy(() -> assertCompletedSnapshot(repositoryName, snapshotName)); | ||
| } else { | ||
| assertRunningSnapshot(repositoryName, snapshotName); | ||
| } | ||
| } | ||
| } | ||
|  | ||
| private void putShutdownMetadata(Collection<String> nodeIds) throws IOException { | ||
| for (String nodeId : nodeIds) { | ||
| final Request putShutdownRequest = new Request("PUT", "/_nodes/" + nodeId + "/shutdown"); | ||
| putShutdownRequest.setJsonEntity(""" | ||
| { | ||
| "type": "remove", | ||
| "reason": "test" | ||
| }"""); | ||
| client().performRequest(putShutdownRequest); | ||
| } | ||
| } | ||
|  | ||
| private void deleteShutdownMetadata(Collection<String> nodeIds) throws IOException { | ||
| for (String nodeId : nodeIds) { | ||
| final Request request = new Request("DELETE", "/_nodes/" + nodeId + "/shutdown"); | ||
| client().performRequest(request); | ||
| } | ||
| } | ||
|  | ||
| private void assertRunningSnapshot(String repositoryName, String snapshotName) throws IOException { | ||
| final Request request = new Request("GET", "/_snapshot/" + repositoryName + "/_current"); | ||
| final ObjectPath responsePath = assertOKAndCreateObjectPath(client().performRequest(request)); | ||
| assertThat(responsePath.evaluate("total"), equalTo(1)); | ||
| assertThat(responsePath.evaluate("snapshots.0.snapshot"), equalTo(snapshotName)); | ||
| } | ||
|  | ||
| private void assertCompletedSnapshot(String repositoryName, String snapshotName) throws IOException { | ||
| { | ||
| final Request request = new Request("GET", "/_snapshot/" + repositoryName + "/_current"); | ||
| final ObjectPath responsePath = assertOKAndCreateObjectPath(client().performRequest(request)); | ||
| assertThat(responsePath.evaluate("total"), equalTo(0)); | ||
| } | ||
|  | ||
| { | ||
| final Request request = new Request("GET", "/_snapshot/" + repositoryName + "/" + snapshotName); | ||
| final ObjectPath responsePath = assertOKAndCreateObjectPath(client().performRequest(request)); | ||
| assertThat(responsePath.evaluate("total"), equalTo(1)); | ||
| assertThat(responsePath.evaluate("snapshots.0.snapshot"), equalTo(snapshotName)); | ||
| assertThat(responsePath.evaluate("snapshots.0.state"), not(equalTo("IN_PROGRESS"))); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the sake of completeness maybe (randomly) index some data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure see e211f26