12
12
import com .carrotsearch .randomizedtesting .annotations .Name ;
13
13
14
14
import org .elasticsearch .client .Request ;
15
- import org .elasticsearch .common .Strings ;
16
15
import org .elasticsearch .common .settings .Settings ;
17
16
import org .elasticsearch .test .rest .ObjectPath ;
18
17
19
18
import java .io .IOException ;
20
- import java .util .Collection ;
21
19
import java .util .Map ;
22
20
import java .util .stream .Collectors ;
23
21
26
24
import static org .hamcrest .Matchers .containsInAnyOrder ;
27
25
import static org .hamcrest .Matchers .empty ;
28
26
import static org .hamcrest .Matchers .equalTo ;
29
- import static org .hamcrest .Matchers .hasSize ;
30
27
import static org .hamcrest .Matchers .not ;
31
28
32
29
public class RunningSnapshotIT extends AbstractRollingUpgradeTestCase {
@@ -45,6 +42,13 @@ public void testRunningSnapshotCompleteAfterUpgrade() throws Exception {
45
42
.collect (Collectors .toUnmodifiableMap (Map .Entry ::getKey , entry -> entry .getValue ().get ("name" ).toString ()));
46
43
assertThat (nodeIdToNodeNames .values (), containsInAnyOrder ("test-cluster-0" , "test-cluster-1" , "test-cluster-2" ));
47
44
45
+ final var lastUpgradeNodeId = nodeIdToNodeNames .entrySet ()
46
+ .stream ()
47
+ .filter (entry -> "test-cluster-2" .equals (entry .getValue ()))
48
+ .map (Map .Entry ::getKey )
49
+ .findFirst ()
50
+ .orElseThrow (() -> new AssertionError ("node id not found in " + nodeIdToNodeNames ));
51
+
48
52
if (isOldCluster ()) {
49
53
registerRepository (repositoryName , "fs" , randomBoolean (), Settings .builder ().put ("location" , "backup" ).build ());
50
54
// create an index to have one shard per node
@@ -54,54 +58,41 @@ public void testRunningSnapshotCompleteAfterUpgrade() throws Exception {
54
58
indexDocs (indexName , between (10 , 50 ));
55
59
}
56
60
flush (indexName , true );
57
- // Signal shutdown to prevent snapshot from being completed
58
- putShutdownMetadata (nodeIdToNodeNames . keySet () );
61
+ // Signal shutdown for the last node to upgrade to prevent snapshot from being completed during the upgrade process
62
+ putShutdownMetadata (lastUpgradeNodeId );
59
63
createSnapshot (repositoryName , snapshotName , false );
60
64
assertRunningSnapshot (repositoryName , snapshotName );
61
65
} else {
62
66
if (isUpgradedCluster ()) {
63
- deleteShutdownMetadata (nodeIdToNodeNames . keySet () );
64
- assertNoShutdownMetadata (nodeIdToNodeNames . keySet () );
67
+ deleteShutdownMetadata (lastUpgradeNodeId );
68
+ assertNoShutdownMetadata (lastUpgradeNodeId );
65
69
ensureGreen (indexName );
66
70
assertBusy (() -> assertCompletedSnapshot (repositoryName , snapshotName ));
67
71
} else {
68
- if (isFirstMixedCluster ()) {
69
- final var upgradedNodeIds = nodeIdToNodeNames .entrySet ()
70
- .stream ()
71
- .filter (entry -> "test-cluster-0" .equals (entry .getValue ()))
72
- .map (Map .Entry ::getKey )
73
- .collect (Collectors .toUnmodifiableSet ());
74
- assertThat (upgradedNodeIds , hasSize (1 ));
75
- deleteShutdownMetadata (upgradedNodeIds );
76
- }
77
72
assertRunningSnapshot (repositoryName , snapshotName );
78
73
}
79
74
}
80
75
}
81
76
82
- private void putShutdownMetadata (Collection <String > nodeIds ) throws IOException {
83
- for (String nodeId : nodeIds ) {
84
- final Request putShutdownRequest = new Request ("PUT" , "/_nodes/" + nodeId + "/shutdown" );
85
- putShutdownRequest .setJsonEntity ("""
86
- {
87
- "type": "remove",
88
- "reason": "test"
89
- }""" );
90
- client ().performRequest (putShutdownRequest );
91
- }
77
+ private void putShutdownMetadata (String nodeId ) throws IOException {
78
+ final Request putShutdownRequest = new Request ("PUT" , "/_nodes/" + nodeId + "/shutdown" );
79
+ putShutdownRequest .setJsonEntity ("""
80
+ {
81
+ "type": "remove",
82
+ "reason": "test"
83
+ }""" );
84
+ client ().performRequest (putShutdownRequest );
92
85
}
93
86
94
- private void deleteShutdownMetadata (Collection <String > nodeIds ) throws IOException {
95
- for (String nodeId : nodeIds ) {
96
- final Request request = new Request ("DELETE" , "/_nodes/" + nodeId + "/shutdown" );
97
- request .addParameter (IGNORE_RESPONSE_CODES_PARAM , "404" );
98
- client ().performRequest (request );
99
- }
87
+ private void deleteShutdownMetadata (String nodeId ) throws IOException {
88
+ final Request request = new Request ("DELETE" , "/_nodes/" + nodeId + "/shutdown" );
89
+ request .addParameter (IGNORE_RESPONSE_CODES_PARAM , "404" );
90
+ client ().performRequest (request );
100
91
}
101
92
102
- private void assertNoShutdownMetadata (Collection < String > nodeIds ) throws IOException {
93
+ private void assertNoShutdownMetadata (String nodeId ) throws IOException {
103
94
final ObjectPath responsePath = assertOKAndCreateObjectPath (
104
- client ().performRequest (new Request ("GET" , "/_nodes/" + Strings . collectionToCommaDelimitedString ( nodeIds ) + "/shutdown" ))
95
+ client ().performRequest (new Request ("GET" , "/_nodes/" + nodeId + "/shutdown" ))
105
96
);
106
97
assertThat (responsePath .evaluate ("nodes" ), empty ());
107
98
}
0 commit comments