Skip to content

Commit e2e87f7

Browse files
committed
tests and fix
1 parent 1b16e64 commit e2e87f7

File tree

3 files changed

+100
-2
lines changed

3 files changed

+100
-2
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.upgrades;
11+
12+
import com.carrotsearch.randomizedtesting.annotations.Name;
13+
14+
import org.elasticsearch.client.Request;
15+
import org.elasticsearch.common.settings.Settings;
16+
import org.elasticsearch.test.rest.ObjectPath;
17+
18+
import java.io.IOException;
19+
import java.util.Collection;
20+
21+
import static org.hamcrest.Matchers.equalTo;
22+
import static org.hamcrest.Matchers.not;
23+
24+
public class RunningSnapshotIT extends AbstractRollingUpgradeTestCase {
25+
26+
public RunningSnapshotIT(@Name("upgradedNodes") int upgradedNodes) {
27+
super(upgradedNodes);
28+
}
29+
30+
public void testRunningSnapshotCompleteAfterUpgrade() throws Exception {
31+
final String indexName = "index";
32+
final String repositoryName = "repo";
33+
final String snapshotName = "snapshot";
34+
final var nodeIds = getNodesInfo(client()).keySet();
35+
36+
if (isOldCluster()) {
37+
// create an index to have one shard per node
38+
createIndex(indexName, indexSettings(3, 0).put("index.routing.allocation.total_shards_per_node", 1).build());
39+
ensureGreen(indexName);
40+
flush(indexName, true);
41+
// Signal shutdown to prevent snapshot from being completed
42+
putShutdownMetadata(nodeIds);
43+
registerRepository(repositoryName, "fs", randomBoolean(), Settings.builder().put("location", "backup").build());
44+
createSnapshot(repositoryName, snapshotName, false);
45+
assertRunningSnapshot(repositoryName, snapshotName);
46+
} else {
47+
if (isUpgradedCluster()) {
48+
deleteShutdownMetadata(nodeIds);
49+
ensureGreen(indexName);
50+
assertBusy(() -> assertCompletedSnapshot(repositoryName, snapshotName));
51+
} else {
52+
assertRunningSnapshot(repositoryName, snapshotName);
53+
}
54+
}
55+
}
56+
57+
private void putShutdownMetadata(Collection<String> nodeIds) throws IOException {
58+
for (String nodeId : nodeIds) {
59+
final Request putShutdownRequest = new Request("PUT", "/_nodes/" + nodeId + "/shutdown");
60+
putShutdownRequest.setJsonEntity("""
61+
{
62+
"type": "remove",
63+
"reason": "test"
64+
}""");
65+
client().performRequest(putShutdownRequest);
66+
}
67+
}
68+
69+
private void deleteShutdownMetadata(Collection<String> nodeIds) throws IOException {
70+
for (String nodeId : nodeIds) {
71+
final Request request = new Request("DELETE", "/_nodes/" + nodeId + "/shutdown");
72+
client().performRequest(request);
73+
}
74+
}
75+
76+
private void assertRunningSnapshot(String repositoryName, String snapshotName) throws IOException {
77+
final Request request = new Request("GET", "/_snapshot/" + repositoryName + "/_current");
78+
final ObjectPath responsePath = assertOKAndCreateObjectPath(client().performRequest(request));
79+
assertThat(responsePath.evaluate("total"), equalTo(1));
80+
assertThat(responsePath.evaluate("snapshots.0.snapshot"), equalTo(snapshotName));
81+
}
82+
83+
private void assertCompletedSnapshot(String repositoryName, String snapshotName) throws IOException {
84+
{
85+
final Request request = new Request("GET", "/_snapshot/" + repositoryName + "/_current");
86+
final ObjectPath responsePath = assertOKAndCreateObjectPath(client().performRequest(request));
87+
assertThat(responsePath.evaluate("total"), equalTo(0));
88+
}
89+
90+
{
91+
final Request request = new Request("GET", "/_snapshot/" + repositoryName + "/" + snapshotName);
92+
final ObjectPath responsePath = assertOKAndCreateObjectPath(client().performRequest(request));
93+
assertThat(responsePath.evaluate("total"), equalTo(1));
94+
assertThat(responsePath.evaluate("snapshots.0.snapshot"), equalTo(snapshotName));
95+
assertThat(responsePath.evaluate("snapshots.0.state"), not(equalTo("IN_PROGRESS")));
96+
}
97+
}
98+
}

server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/RestoreInProgressAllocationDeciderTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void testCannotAllocatePrimaryMissingInRestoreInProgress() {
8181
assertThat(
8282
decision.getExplanation(),
8383
equalTo(
84-
"shard has failed to be restored from the snapshot [_repository:_missing/_uuid] - manually close or "
84+
"shard has failed to be restored from the snapshot [default:_repository:_missing/_uuid] - manually close or "
8585
+ "delete the index [test] in order to retry to restore the snapshot again or use the reroute API "
8686
+ "to force the allocation of an empty primary shard. Details: [restore_source[_repository/_missing]]"
8787
)

server/src/test/java/org/elasticsearch/snapshots/RestoreServiceTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public void testNotAllowToRestoreGlobalStateFromSnapshotWithoutOne() {
241241
);
242242
assertThat(
243243
exception.getMessage(),
244-
equalTo("[name:name/uuid] cannot restore global state since the snapshot was created without global state")
244+
equalTo("[default:name:name/uuid] cannot restore global state since the snapshot was created without global state")
245245
);
246246
}
247247

0 commit comments

Comments
 (0)