24
24
import org .opensearch .test .OpenSearchIntegTestCase ;
25
25
import org .junit .Before ;
26
26
27
+ import java .io .IOException ;
27
28
import java .nio .charset .StandardCharsets ;
28
29
import java .nio .file .Path ;
29
30
import java .util .ArrayList ;
46
47
public class RemoteRoutingTableServiceIT extends RemoteStoreBaseIntegTestCase {
47
48
private static final String INDEX_NAME = "test-index" ;
48
49
private static final String INDEX_NAME_1 = "test-index-1" ;
49
- BlobPath indexRoutingPath ;
50
+ List < BlobPath > indexRoutingPaths ;
50
51
AtomicInteger indexRoutingFiles = new AtomicInteger ();
51
52
private final RemoteStoreEnums .PathType pathType = RemoteStoreEnums .PathType .HASHED_PREFIX ;
52
53
@@ -91,7 +92,7 @@ public void testRemoteRoutingTableIndexLifecycle() throws Exception {
91
92
updateIndexSettings (INDEX_NAME , IndexMetadata .SETTING_NUMBER_OF_REPLICAS , 2 );
92
93
ensureGreen (INDEX_NAME );
93
94
assertBusy (() -> {
94
- int indexRoutingFilesAfterUpdate = repository .blobStore ().blobContainer (indexRoutingPath ).listBlobs ().size ();
95
+ int indexRoutingFilesAfterUpdate = repository .blobStore ().blobContainer (indexRoutingPaths . get ( 0 ) ).listBlobs ().size ();
95
96
// At-least 3 new index routing files will be created as shards will transition from INIT -> UNASSIGNED -> STARTED state
96
97
assertTrue (indexRoutingFilesAfterUpdate >= indexRoutingFiles .get () + 3 );
97
98
});
@@ -112,6 +113,47 @@ public void testRemoteRoutingTableIndexLifecycle() throws Exception {
112
113
assertTrue (areRoutingTablesSame (routingTableVersions ));
113
114
}
114
115
116
+ public void testRemoteRoutingTableWithMultipleIndex () throws Exception {
117
+ BlobStoreRepository repository = prepareClusterAndVerifyRepository ();
118
+
119
+ RemoteClusterStateService remoteClusterStateService = internalCluster ().getClusterManagerNodeInstance (
120
+ RemoteClusterStateService .class
121
+ );
122
+ RemoteManifestManager remoteManifestManager = remoteClusterStateService .getRemoteManifestManager ();
123
+ Optional <ClusterMetadataManifest > latestManifest = remoteManifestManager .getLatestClusterMetadataManifest (
124
+ getClusterState ().getClusterName ().value (),
125
+ getClusterState ().getMetadata ().clusterUUID ()
126
+ );
127
+ List <String > expectedIndexNames = new ArrayList <>();
128
+ List <String > deletedIndexNames = new ArrayList <>();
129
+ verifyUpdatesInManifestFile (latestManifest , expectedIndexNames , 1 , deletedIndexNames , true );
130
+
131
+ List <RoutingTable > routingTables = getRoutingTableFromAllNodes ();
132
+ // Verify indices in routing table
133
+ Set <String > expectedIndicesInRoutingTable = Set .of (INDEX_NAME );
134
+ assertEquals (routingTables .get (0 ).getIndicesRouting ().keySet (), expectedIndicesInRoutingTable );
135
+ // Verify routing table across all nodes is equal
136
+ assertTrue (areRoutingTablesSame (routingTables ));
137
+
138
+ // Create new index
139
+ createIndex (INDEX_NAME_1 , remoteStoreIndexSettings (1 , 5 ));
140
+ ensureGreen (INDEX_NAME_1 );
141
+
142
+ latestManifest = remoteManifestManager .getLatestClusterMetadataManifest (
143
+ getClusterState ().getClusterName ().value (),
144
+ getClusterState ().getMetadata ().clusterUUID ()
145
+ );
146
+
147
+ updateIndexRoutingPaths (repository );
148
+ verifyUpdatesInManifestFile (latestManifest , expectedIndexNames , 2 , deletedIndexNames , true );
149
+ routingTables = getRoutingTableFromAllNodes ();
150
+ // Verify indices in routing table
151
+ expectedIndicesInRoutingTable = Set .of (INDEX_NAME , INDEX_NAME_1 );
152
+ assertEquals (routingTables .get (0 ).getIndicesRouting ().keySet (), expectedIndicesInRoutingTable );
153
+ // Verify routing table across all nodes is equal
154
+ assertTrue (areRoutingTablesSame (routingTables ));
155
+ }
156
+
115
157
public void testRemoteRoutingTableEmptyRoutingTableDiff () throws Exception {
116
158
prepareClusterAndVerifyRepository ();
117
159
@@ -166,7 +208,7 @@ public void testRemoteRoutingTableIndexNodeRestart() throws Exception {
166
208
assertRemoteStoreRepositoryOnAllNodes (REMOTE_ROUTING_TABLE_REPO );
167
209
168
210
assertBusy (() -> {
169
- int indexRoutingFilesAfterNodeDrop = repository .blobStore ().blobContainer (indexRoutingPath ).listBlobs ().size ();
211
+ int indexRoutingFilesAfterNodeDrop = repository .blobStore ().blobContainer (indexRoutingPaths . get ( 0 ) ).listBlobs ().size ();
170
212
assertTrue (indexRoutingFilesAfterNodeDrop > indexRoutingFiles .get ());
171
213
});
172
214
@@ -201,7 +243,7 @@ public void testRemoteRoutingTableIndexMasterRestart() throws Exception {
201
243
assertRemoteStoreRepositoryOnAllNodes (REMOTE_ROUTING_TABLE_REPO );
202
244
203
245
assertBusy (() -> {
204
- int indexRoutingFilesAfterNodeDrop = repository .blobStore ().blobContainer (indexRoutingPath ).listBlobs ().size ();
246
+ int indexRoutingFilesAfterNodeDrop = repository .blobStore ().blobContainer (indexRoutingPaths . get ( 0 ) ).listBlobs ().size ();
205
247
assertTrue (indexRoutingFilesAfterNodeDrop > indexRoutingFiles .get ());
206
248
});
207
249
@@ -240,10 +282,14 @@ private BlobStoreRepository prepareClusterAndVerifyRepository() throws Exception
240
282
241
283
BlobPath baseMetadataPath = getBaseMetadataPath (repository );
242
284
List <IndexRoutingTable > indexRoutingTables = new ArrayList <>(getClusterState ().routingTable ().indicesRouting ().values ());
243
- indexRoutingPath = getIndexRoutingPath (baseMetadataPath .add (INDEX_ROUTING_TABLE ), indexRoutingTables .get (0 ).getIndex ().getUUID ());
285
+ indexRoutingPaths = new ArrayList <>();
286
+ for (IndexRoutingTable indexRoutingTable : indexRoutingTables ) {
287
+ indexRoutingPaths .add (getIndexRoutingPath (baseMetadataPath .add (INDEX_ROUTING_TABLE ), indexRoutingTable .getIndex ().getUUID ()));
288
+ }
244
289
245
290
assertBusy (() -> {
246
- indexRoutingFiles .set (repository .blobStore ().blobContainer (indexRoutingPath ).listBlobs ().size ());
291
+ int totalRoutingFiles = calculateTotalRoutingFiles (repository );
292
+ indexRoutingFiles .set (totalRoutingFiles );
247
293
// There would be >=3 files as shards will transition from UNASSIGNED -> INIT -> STARTED state
248
294
assertTrue (indexRoutingFiles .get () >= 3 );
249
295
});
@@ -280,11 +326,19 @@ private void verifyUpdatesInManifestFile(
280
326
assertTrue (latestManifest .isPresent ());
281
327
ClusterMetadataManifest manifest = latestManifest .get ();
282
328
283
- assertEquals (expectedIndexNames , manifest .getDiffManifest ().getIndicesRoutingUpdated ());
284
329
assertEquals (expectedDeletedIndex , manifest .getDiffManifest ().getIndicesDeleted ());
285
330
assertEquals (expectedIndicesRoutingFilesInManifest , manifest .getIndicesRouting ().size ());
331
+
332
+ // Check if all paths in manifest.getIndicesRouting() are present in indexRoutingPaths
286
333
for (ClusterMetadataManifest .UploadedIndexMetadata uploadedFilename : manifest .getIndicesRouting ()) {
287
- assertTrue (uploadedFilename .getUploadedFilename ().contains (indexRoutingPath .buildAsString ()));
334
+ boolean pathFound = false ;
335
+ for (BlobPath indexRoutingPath : indexRoutingPaths ) {
336
+ if (uploadedFilename .getUploadedFilename ().contains (indexRoutingPath .buildAsString ())) {
337
+ pathFound = true ;
338
+ break ;
339
+ }
340
+ }
341
+ assertTrue ("Uploaded file not found in indexRoutingPaths: " + uploadedFilename .getUploadedFilename (), pathFound );
288
342
}
289
343
assertEquals (isRoutingTableDiffFileExpected , manifest .getDiffManifest ().getIndicesRoutingDiffPath () != null );
290
344
}
@@ -305,6 +359,24 @@ private List<RoutingTable> getRoutingTableFromAllNodes() throws ExecutionExcepti
305
359
return routingTables ;
306
360
}
307
361
362
+ private void updateIndexRoutingPaths (BlobStoreRepository repository ) {
363
+ BlobPath baseMetadataPath = getBaseMetadataPath (repository );
364
+ List <IndexRoutingTable > indexRoutingTables = new ArrayList <>(getClusterState ().routingTable ().indicesRouting ().values ());
365
+
366
+ indexRoutingPaths .clear (); // Clear the list to avoid stale data
367
+ for (IndexRoutingTable indexRoutingTable : indexRoutingTables ) {
368
+ indexRoutingPaths .add (getIndexRoutingPath (baseMetadataPath .add (INDEX_ROUTING_TABLE ), indexRoutingTable .getIndex ().getUUID ()));
369
+ }
370
+ }
371
+
372
+ private int calculateTotalRoutingFiles (BlobStoreRepository repository ) throws IOException {
373
+ int totalRoutingFiles = 0 ;
374
+ for (BlobPath path : indexRoutingPaths ) {
375
+ totalRoutingFiles += repository .blobStore ().blobContainer (path ).listBlobs ().size ();
376
+ }
377
+ return totalRoutingFiles ;
378
+ }
379
+
308
380
private boolean areRoutingTablesSame (List <RoutingTable > routingTables ) {
309
381
if (routingTables == null || routingTables .isEmpty ()) {
310
382
return false ;
@@ -356,7 +428,6 @@ private void deleteIndexAndVerify(RemoteManifestManager remoteManifestManager) {
356
428
);
357
429
assertTrue (latestManifest .isPresent ());
358
430
ClusterMetadataManifest manifest = latestManifest .get ();
359
- assertTrue (manifest .getDiffManifest ().getIndicesRoutingUpdated ().isEmpty ());
360
431
assertTrue (manifest .getDiffManifest ().getIndicesDeleted ().contains (INDEX_NAME ));
361
432
assertTrue (manifest .getIndicesRouting ().isEmpty ());
362
433
}
0 commit comments