10
10
11
11
import org .opensearch .action .admin .cluster .node .stats .NodesStatsRequest ;
12
12
import org .opensearch .action .admin .cluster .node .stats .NodesStatsResponse ;
13
+ import org .opensearch .cluster .metadata .IndexMetadata ;
13
14
import org .opensearch .common .blobstore .BlobPath ;
14
15
import org .opensearch .common .settings .Settings ;
15
16
import org .opensearch .discovery .DiscoveryStats ;
26
27
import java .util .function .Function ;
27
28
import java .util .stream .Collectors ;
28
29
30
+ import static org .opensearch .cluster .metadata .IndexMetadata .SETTING_NUMBER_OF_REPLICAS ;
29
31
import static org .opensearch .gateway .remote .RemoteClusterStateService .COORDINATION_METADATA ;
30
32
import static org .opensearch .gateway .remote .RemoteClusterStateService .CUSTOM_METADATA ;
31
33
import static org .opensearch .gateway .remote .RemoteClusterStateService .DELIMITER ;
@@ -49,6 +51,16 @@ protected Settings nodeSettings(int nodeOrdinal) {
49
51
return Settings .builder ().put (super .nodeSettings (nodeOrdinal )).put (REMOTE_CLUSTER_STATE_ENABLED_SETTING .getKey (), true ).build ();
50
52
}
51
53
54
+ private void prepareCluster (int numClusterManagerNodes , int numDataOnlyNodes , String indices , int replicaCount , int shardCount ) {
55
+ internalCluster ().startClusterManagerOnlyNodes (numClusterManagerNodes );
56
+ internalCluster ().startDataOnlyNodes (numDataOnlyNodes );
57
+ for (String index : indices .split ("," )) {
58
+ createIndex (index , remoteStoreIndexSettings (replicaCount , shardCount ));
59
+ ensureYellowAndNoInitializingShards (index );
60
+ ensureGreen (index );
61
+ }
62
+ }
63
+
52
64
private Map <String , Long > initialTestSetup (int shardCount , int replicaCount , int dataNodeCount , int clusterManagerNodeCount ) {
53
65
prepareCluster (clusterManagerNodeCount , dataNodeCount , INDEX_NAME , replicaCount , shardCount );
54
66
Map <String , Long > indexStats = indexData (1 , false , INDEX_NAME );
@@ -57,6 +69,49 @@ private Map<String, Long> initialTestSetup(int shardCount, int replicaCount, int
57
69
return indexStats ;
58
70
}
59
71
72
+ public void testFullClusterRestoreStaleDelete () throws Exception {
73
+ int shardCount = randomIntBetween (1 , 2 );
74
+ int replicaCount = 1 ;
75
+ int dataNodeCount = shardCount * (replicaCount + 1 );
76
+ int clusterManagerNodeCount = 1 ;
77
+
78
+ initialTestSetup (shardCount , replicaCount , dataNodeCount , clusterManagerNodeCount );
79
+ setReplicaCount (0 );
80
+ setReplicaCount (2 );
81
+ setReplicaCount (0 );
82
+ setReplicaCount (1 );
83
+ setReplicaCount (0 );
84
+ setReplicaCount (1 );
85
+ setReplicaCount (0 );
86
+ setReplicaCount (2 );
87
+ setReplicaCount (0 );
88
+
89
+ RemoteClusterStateService remoteClusterStateService = internalCluster ().getClusterManagerNodeInstance (
90
+ RemoteClusterStateService .class
91
+ );
92
+
93
+ RepositoriesService repositoriesService = internalCluster ().getClusterManagerNodeInstance (RepositoriesService .class );
94
+
95
+ BlobStoreRepository repository = (BlobStoreRepository ) repositoriesService .repository (REPOSITORY_NAME );
96
+ BlobPath baseMetadataPath = repository .basePath ()
97
+ .add (
98
+ Base64 .getUrlEncoder ()
99
+ .withoutPadding ()
100
+ .encodeToString (getClusterState ().getClusterName ().value ().getBytes (StandardCharsets .UTF_8 ))
101
+ )
102
+ .add ("cluster-state" )
103
+ .add (getClusterState ().metadata ().clusterUUID ());
104
+
105
+ assertEquals (10 , repository .blobStore ().blobContainer (baseMetadataPath .add ("manifest" )).listBlobsByPrefix ("manifest" ).size ());
106
+
107
+ Map <String , IndexMetadata > indexMetadataMap = remoteClusterStateService .getLatestClusterState (
108
+ cluster ().getClusterName (),
109
+ getClusterState ().metadata ().clusterUUID ()
110
+ ).getMetadata ().getIndices ();
111
+ assertEquals (0 , indexMetadataMap .values ().stream ().findFirst ().get ().getNumberOfReplicas ());
112
+ assertEquals (shardCount , indexMetadataMap .values ().stream ().findFirst ().get ().getNumberOfShards ());
113
+ }
114
+
60
115
public void testRemoteStateStats () {
61
116
int shardCount = randomIntBetween (1 , 2 );
62
117
int replicaCount = 1 ;
@@ -186,4 +241,12 @@ private void validateNodesStatsResponse(NodesStatsResponse nodesStatsResponse) {
186
241
assertNotNull (nodesStatsResponse .getNodes ().get (0 ));
187
242
assertNotNull (nodesStatsResponse .getNodes ().get (0 ).getDiscoveryStats ());
188
243
}
244
+
245
+ private void setReplicaCount (int replicaCount ) {
246
+ client ().admin ()
247
+ .indices ()
248
+ .prepareUpdateSettings (INDEX_NAME )
249
+ .setSettings (Settings .builder ().put (SETTING_NUMBER_OF_REPLICAS , replicaCount ))
250
+ .get ();
251
+ }
189
252
}
0 commit comments