8
8
9
9
package org .opensearch .gateway .remote ;
10
10
11
+ import org .opensearch .action .admin .cluster .settings .ClusterUpdateSettingsResponse ;
11
12
import org .opensearch .action .admin .cluster .state .ClusterStateRequest ;
12
13
import org .opensearch .cluster .metadata .IndexMetadata ;
13
14
import org .opensearch .cluster .routing .IndexRoutingTable ;
32
33
import java .util .Optional ;
33
34
import java .util .Set ;
34
35
import java .util .concurrent .ExecutionException ;
36
+ import java .util .concurrent .TimeUnit ;
35
37
import java .util .concurrent .atomic .AtomicInteger ;
36
38
37
39
import static org .opensearch .common .util .FeatureFlags .REMOTE_PUBLICATION_EXPERIMENTAL ;
38
40
import static org .opensearch .gateway .remote .RemoteClusterStateService .REMOTE_CLUSTER_STATE_ENABLED_SETTING ;
39
41
import static org .opensearch .gateway .remote .routingtable .RemoteIndexRoutingTable .INDEX_ROUTING_TABLE ;
42
+ import static org .opensearch .indices .IndicesService .CLUSTER_DEFAULT_INDEX_REFRESH_INTERVAL_SETTING ;
40
43
import static org .opensearch .node .remotestore .RemoteStoreNodeAttribute .REMOTE_STORE_ROUTING_TABLE_REPOSITORY_NAME_ATTRIBUTE_KEY ;
41
44
42
45
@ OpenSearchIntegTestCase .ClusterScope (scope = OpenSearchIntegTestCase .Scope .TEST , numDataNodes = 0 )
43
46
public class RemoteRoutingTableServiceIT extends RemoteStoreBaseIntegTestCase {
44
47
private static final String INDEX_NAME = "test-index" ;
48
+ private static final String INDEX_NAME_1 = "test-index-1" ;
45
49
BlobPath indexRoutingPath ;
46
50
AtomicInteger indexRoutingFiles = new AtomicInteger ();
47
51
private final RemoteStoreEnums .PathType pathType = RemoteStoreEnums .PathType .HASHED_PREFIX ;
@@ -72,7 +76,13 @@ public void testRemoteRoutingTableIndexLifecycle() throws Exception {
72
76
RemoteClusterStateService .class
73
77
);
74
78
RemoteManifestManager remoteManifestManager = remoteClusterStateService .getRemoteManifestManager ();
75
- verifyUpdatesInManifestFile (remoteManifestManager );
79
+ Optional <ClusterMetadataManifest > latestManifest = remoteManifestManager .getLatestClusterMetadataManifest (
80
+ getClusterState ().getClusterName ().value (),
81
+ getClusterState ().getMetadata ().clusterUUID ()
82
+ );
83
+ List <String > expectedIndexNames = new ArrayList <>();
84
+ List <String > deletedIndexNames = new ArrayList <>();
85
+ verifyUpdatesInManifestFile (latestManifest , expectedIndexNames , 1 , deletedIndexNames , true );
76
86
77
87
List <RoutingTable > routingTableVersions = getRoutingTableFromAllNodes ();
78
88
assertTrue (areRoutingTablesSame (routingTableVersions ));
@@ -86,7 +96,11 @@ public void testRemoteRoutingTableIndexLifecycle() throws Exception {
86
96
assertTrue (indexRoutingFilesAfterUpdate >= indexRoutingFiles .get () + 3 );
87
97
});
88
98
89
- verifyUpdatesInManifestFile (remoteManifestManager );
99
+ latestManifest = remoteManifestManager .getLatestClusterMetadataManifest (
100
+ getClusterState ().getClusterName ().value (),
101
+ getClusterState ().getMetadata ().clusterUUID ()
102
+ );
103
+ verifyUpdatesInManifestFile (latestManifest , expectedIndexNames , 1 , deletedIndexNames , true );
90
104
91
105
routingTableVersions = getRoutingTableFromAllNodes ();
92
106
assertTrue (areRoutingTablesSame (routingTableVersions ));
@@ -98,6 +112,42 @@ public void testRemoteRoutingTableIndexLifecycle() throws Exception {
98
112
assertTrue (areRoutingTablesSame (routingTableVersions ));
99
113
}
100
114
115
+ public void testRemoteRoutingTableEmptyRoutingTableDiff () throws Exception {
116
+ prepareClusterAndVerifyRepository ();
117
+
118
+ RemoteClusterStateService remoteClusterStateService = internalCluster ().getClusterManagerNodeInstance (
119
+ RemoteClusterStateService .class
120
+ );
121
+ RemoteManifestManager remoteManifestManager = remoteClusterStateService .getRemoteManifestManager ();
122
+ Optional <ClusterMetadataManifest > latestManifest = remoteManifestManager .getLatestClusterMetadataManifest (
123
+ getClusterState ().getClusterName ().value (),
124
+ getClusterState ().getMetadata ().clusterUUID ()
125
+ );
126
+ List <String > expectedIndexNames = new ArrayList <>();
127
+ List <String > deletedIndexNames = new ArrayList <>();
128
+ verifyUpdatesInManifestFile (latestManifest , expectedIndexNames , 1 , deletedIndexNames , true );
129
+
130
+ List <RoutingTable > routingTableVersions = getRoutingTableFromAllNodes ();
131
+ assertTrue (areRoutingTablesSame (routingTableVersions ));
132
+
133
+ // Update cluster settings
134
+ ClusterUpdateSettingsResponse response = client ().admin ()
135
+ .cluster ()
136
+ .prepareUpdateSettings ()
137
+ .setPersistentSettings (Settings .builder ().put (CLUSTER_DEFAULT_INDEX_REFRESH_INTERVAL_SETTING .getKey (), 0 , TimeUnit .SECONDS ))
138
+ .get ();
139
+ assertTrue (response .isAcknowledged ());
140
+
141
+ latestManifest = remoteManifestManager .getLatestClusterMetadataManifest (
142
+ getClusterState ().getClusterName ().value (),
143
+ getClusterState ().getMetadata ().clusterUUID ()
144
+ );
145
+ verifyUpdatesInManifestFile (latestManifest , expectedIndexNames , 1 , deletedIndexNames , false );
146
+
147
+ routingTableVersions = getRoutingTableFromAllNodes ();
148
+ assertTrue (areRoutingTablesSame (routingTableVersions ));
149
+ }
150
+
101
151
public void testRemoteRoutingTableIndexNodeRestart () throws Exception {
102
152
BlobStoreRepository repository = prepareClusterAndVerifyRepository ();
103
153
@@ -124,10 +174,16 @@ public void testRemoteRoutingTableIndexNodeRestart() throws Exception {
124
174
RemoteClusterStateService .class
125
175
);
126
176
RemoteManifestManager remoteManifestManager = remoteClusterStateService .getRemoteManifestManager ();
127
- verifyUpdatesInManifestFile (remoteManifestManager );
177
+ Optional <ClusterMetadataManifest > latestManifest = remoteManifestManager .getLatestClusterMetadataManifest (
178
+ getClusterState ().getClusterName ().value (),
179
+ getClusterState ().getMetadata ().clusterUUID ()
180
+ );
181
+ List <String > expectedIndexNames = new ArrayList <>();
182
+ List <String > deletedIndexNames = new ArrayList <>();
183
+ verifyUpdatesInManifestFile (latestManifest , expectedIndexNames , 1 , deletedIndexNames , true );
128
184
}
129
185
130
- public void testRemoteRoutingTableIndexMasterRestart1 () throws Exception {
186
+ public void testRemoteRoutingTableIndexMasterRestart () throws Exception {
131
187
BlobStoreRepository repository = prepareClusterAndVerifyRepository ();
132
188
133
189
List <RoutingTable > routingTableVersions = getRoutingTableFromAllNodes ();
@@ -153,7 +209,13 @@ public void testRemoteRoutingTableIndexMasterRestart1() throws Exception {
153
209
RemoteClusterStateService .class
154
210
);
155
211
RemoteManifestManager remoteManifestManager = remoteClusterStateService .getRemoteManifestManager ();
156
- verifyUpdatesInManifestFile (remoteManifestManager );
212
+ Optional <ClusterMetadataManifest > latestManifest = remoteManifestManager .getLatestClusterMetadataManifest (
213
+ getClusterState ().getClusterName ().value (),
214
+ getClusterState ().getMetadata ().clusterUUID ()
215
+ );
216
+ List <String > expectedIndexNames = new ArrayList <>();
217
+ List <String > deletedIndexNames = new ArrayList <>();
218
+ verifyUpdatesInManifestFile (latestManifest , expectedIndexNames , 1 , deletedIndexNames , true );
157
219
}
158
220
159
221
private BlobStoreRepository prepareClusterAndVerifyRepository () throws Exception {
@@ -208,18 +270,23 @@ private BlobPath getIndexRoutingPath(BlobPath indexRoutingPath, String indexUUID
208
270
);
209
271
}
210
272
211
- private void verifyUpdatesInManifestFile (RemoteManifestManager remoteManifestManager ) {
212
- Optional <ClusterMetadataManifest > latestManifest = remoteManifestManager .getLatestClusterMetadataManifest (
213
- getClusterState ().getClusterName ().value (),
214
- getClusterState ().getMetadata ().clusterUUID ()
215
- );
273
+ private void verifyUpdatesInManifestFile (
274
+ Optional <ClusterMetadataManifest > latestManifest ,
275
+ List <String > expectedIndexNames ,
276
+ int expectedIndicesRoutingFilesInManifest ,
277
+ List <String > expectedDeletedIndex ,
278
+ boolean isRoutingTableDiffFileExpected
279
+ ) {
216
280
assertTrue (latestManifest .isPresent ());
217
281
ClusterMetadataManifest manifest = latestManifest .get ();
218
- assertTrue (manifest .getDiffManifest ().getIndicesRoutingUpdated ().contains (INDEX_NAME ));
219
- assertTrue (manifest .getDiffManifest ().getIndicesDeleted ().isEmpty ());
220
- assertFalse (manifest .getIndicesRouting ().isEmpty ());
221
- assertEquals (1 , manifest .getIndicesRouting ().size ());
222
- assertTrue (manifest .getIndicesRouting ().get (0 ).getUploadedFilename ().contains (indexRoutingPath .buildAsString ()));
282
+
283
+ assertEquals (expectedIndexNames , manifest .getDiffManifest ().getIndicesRoutingUpdated ());
284
+ assertEquals (expectedDeletedIndex , manifest .getDiffManifest ().getIndicesDeleted ());
285
+ assertEquals (expectedIndicesRoutingFilesInManifest , manifest .getIndicesRouting ().size ());
286
+ for (ClusterMetadataManifest .UploadedIndexMetadata uploadedFilename : manifest .getIndicesRouting ()) {
287
+ assertTrue (uploadedFilename .getUploadedFilename ().contains (indexRoutingPath .buildAsString ()));
288
+ }
289
+ assertEquals (isRoutingTableDiffFileExpected , manifest .getDiffManifest ().getIndicesRoutingDiffPath () != null );
223
290
}
224
291
225
292
private List <RoutingTable > getRoutingTableFromAllNodes () throws ExecutionException , InterruptedException {
0 commit comments