88
99package org .opensearch .gateway .remote ;
1010
11+ import org .opensearch .action .admin .cluster .settings .ClusterUpdateSettingsResponse ;
1112import org .opensearch .action .admin .cluster .state .ClusterStateRequest ;
1213import org .opensearch .cluster .metadata .IndexMetadata ;
1314import org .opensearch .cluster .routing .IndexRoutingTable ;
3233import java .util .Optional ;
3334import java .util .Set ;
3435import java .util .concurrent .ExecutionException ;
36+ import java .util .concurrent .TimeUnit ;
3537import java .util .concurrent .atomic .AtomicInteger ;
3638
3739import static org .opensearch .common .util .FeatureFlags .REMOTE_PUBLICATION_EXPERIMENTAL ;
3840import static org .opensearch .gateway .remote .RemoteClusterStateService .REMOTE_CLUSTER_STATE_ENABLED_SETTING ;
3941import static org .opensearch .gateway .remote .routingtable .RemoteIndexRoutingTable .INDEX_ROUTING_TABLE ;
42+ import static org .opensearch .indices .IndicesService .CLUSTER_DEFAULT_INDEX_REFRESH_INTERVAL_SETTING ;
4043import static org .opensearch .node .remotestore .RemoteStoreNodeAttribute .REMOTE_STORE_ROUTING_TABLE_REPOSITORY_NAME_ATTRIBUTE_KEY ;
4144
4245@ OpenSearchIntegTestCase .ClusterScope (scope = OpenSearchIntegTestCase .Scope .TEST , numDataNodes = 0 )
4346public class RemoteRoutingTableServiceIT extends RemoteStoreBaseIntegTestCase {
4447 private static final String INDEX_NAME = "test-index" ;
48+ private static final String INDEX_NAME_1 = "test-index-1" ;
4549 BlobPath indexRoutingPath ;
4650 AtomicInteger indexRoutingFiles = new AtomicInteger ();
4751 private final RemoteStoreEnums .PathType pathType = RemoteStoreEnums .PathType .HASHED_PREFIX ;
@@ -72,7 +76,13 @@ public void testRemoteRoutingTableIndexLifecycle() throws Exception {
7276 RemoteClusterStateService .class
7377 );
7478 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 );
7686
7787 List <RoutingTable > routingTableVersions = getRoutingTableFromAllNodes ();
7888 assertTrue (areRoutingTablesSame (routingTableVersions ));
@@ -86,7 +96,11 @@ public void testRemoteRoutingTableIndexLifecycle() throws Exception {
8696 assertTrue (indexRoutingFilesAfterUpdate >= indexRoutingFiles .get () + 3 );
8797 });
8898
89- verifyUpdatesInManifestFile (remoteManifestManager );
99+ latestManifest = remoteManifestManager .getLatestClusterMetadataManifest (
100+ getClusterState ().getClusterName ().value (),
101+ getClusterState ().getMetadata ().clusterUUID ()
102+ );
103+ verifyUpdatesInManifestFile (latestManifest , expectedIndexNames , 1 , deletedIndexNames , true );
90104
91105 routingTableVersions = getRoutingTableFromAllNodes ();
92106 assertTrue (areRoutingTablesSame (routingTableVersions ));
@@ -98,6 +112,42 @@ public void testRemoteRoutingTableIndexLifecycle() throws Exception {
98112 assertTrue (areRoutingTablesSame (routingTableVersions ));
99113 }
100114
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+
101151 public void testRemoteRoutingTableIndexNodeRestart () throws Exception {
102152 BlobStoreRepository repository = prepareClusterAndVerifyRepository ();
103153
@@ -124,10 +174,16 @@ public void testRemoteRoutingTableIndexNodeRestart() throws Exception {
124174 RemoteClusterStateService .class
125175 );
126176 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 );
128184 }
129185
130- public void testRemoteRoutingTableIndexMasterRestart1 () throws Exception {
186+ public void testRemoteRoutingTableIndexMasterRestart () throws Exception {
131187 BlobStoreRepository repository = prepareClusterAndVerifyRepository ();
132188
133189 List <RoutingTable > routingTableVersions = getRoutingTableFromAllNodes ();
@@ -153,7 +209,13 @@ public void testRemoteRoutingTableIndexMasterRestart1() throws Exception {
153209 RemoteClusterStateService .class
154210 );
155211 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 );
157219 }
158220
159221 private BlobStoreRepository prepareClusterAndVerifyRepository () throws Exception {
@@ -208,18 +270,23 @@ private BlobPath getIndexRoutingPath(BlobPath indexRoutingPath, String indexUUID
208270 );
209271 }
210272
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+ ) {
216280 assertTrue (latestManifest .isPresent ());
217281 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 );
223290 }
224291
225292 private List <RoutingTable > getRoutingTableFromAllNodes () throws ExecutionException , InterruptedException {
0 commit comments