20
20
import org .opensearch .client .Requests ;
21
21
import org .opensearch .cluster .ClusterState ;
22
22
import org .opensearch .cluster .metadata .IndexMetadata ;
23
+ import org .opensearch .common .Nullable ;
23
24
import org .opensearch .common .io .PathUtils ;
24
25
import org .opensearch .common .settings .Settings ;
25
26
import org .opensearch .common .util .io .IOUtils ;
47
48
import java .util .Arrays ;
48
49
import java .util .List ;
49
50
import java .util .Map ;
51
+ import java .util .Objects ;
50
52
import java .util .Optional ;
51
53
import java .util .concurrent .ExecutionException ;
52
54
import java .util .stream .Collectors ;
@@ -284,7 +286,7 @@ public void testRemoteStoreCustomDataOnIndexCreationAndRestore() {
284
286
285
287
indexDocuments (client , indexName1 , randomIntBetween (5 , 10 ));
286
288
ensureGreen (indexName1 );
287
- validatePathType (indexName1 , PathType .FIXED , PathHashAlgorithm . FNV_1A );
289
+ validatePathType (indexName1 , PathType .FIXED );
288
290
289
291
logger .info ("--> snapshot" );
290
292
SnapshotInfo snapshotInfo = createSnapshot (snapshotRepoName , snapshotName1 , new ArrayList <>(Arrays .asList (indexName1 )));
@@ -301,7 +303,7 @@ public void testRemoteStoreCustomDataOnIndexCreationAndRestore() {
301
303
.get ();
302
304
assertEquals (RestStatus .ACCEPTED , restoreSnapshotResponse .status ());
303
305
ensureGreen (restoredIndexName1version1 );
304
- validatePathType (restoredIndexName1version1 , PathType .FIXED , PathHashAlgorithm . FNV_1A );
306
+ validatePathType (restoredIndexName1version1 , PathType .FIXED );
305
307
306
308
client (clusterManagerNode ).admin ()
307
309
.cluster ()
@@ -327,16 +329,50 @@ public void testRemoteStoreCustomDataOnIndexCreationAndRestore() {
327
329
validatePathType (indexName2 , PathType .HASHED_PREFIX , PathHashAlgorithm .FNV_1A );
328
330
329
331
// Validating that custom data has not changed for indexes which were created before the cluster setting got updated
330
- validatePathType (indexName1 , PathType .FIXED , PathHashAlgorithm .FNV_1A );
332
+ validatePathType (indexName1 , PathType .FIXED );
333
+
334
+ // Create Snapshot of index 2
335
+ String snapshotName2 = "test-restore-snapshot2" ;
336
+ snapshotInfo = createSnapshot (snapshotRepoName , snapshotName2 , new ArrayList <>(List .of (indexName2 )));
337
+ assertEquals (SnapshotState .SUCCESS , snapshotInfo .state ());
338
+ assertTrue (snapshotInfo .successfulShards () > 0 );
339
+ assertEquals (snapshotInfo .totalShards (), snapshotInfo .successfulShards ());
340
+
341
+ // Update cluster settings to FIXED
342
+ client (clusterManagerNode ).admin ()
343
+ .cluster ()
344
+ .prepareUpdateSettings ()
345
+ .setTransientSettings (Settings .builder ().put (CLUSTER_REMOTE_STORE_PATH_PREFIX_TYPE_SETTING .getKey (), PathType .FIXED ))
346
+ .get ();
347
+
348
+ // Close index 2
349
+ assertAcked (client ().admin ().indices ().prepareClose (indexName2 ));
350
+ restoreSnapshotResponse = client .admin ()
351
+ .cluster ()
352
+ .prepareRestoreSnapshot (snapshotRepoName , snapshotName2 )
353
+ .setWaitForCompletion (false )
354
+ .setIndices (indexName2 )
355
+ .get ();
356
+ assertEquals (RestStatus .ACCEPTED , restoreSnapshotResponse .status ());
357
+ ensureGreen (indexName2 );
358
+
359
+ // Validating that custom data has not changed for testindex2 which was created before the cluster setting got updated
360
+ validatePathType (indexName2 , PathType .HASHED_PREFIX , PathHashAlgorithm .FNV_1A );
331
361
}
332
362
333
- private void validatePathType (String index , PathType pathType , PathHashAlgorithm pathHashAlgorithm ) {
363
+ private void validatePathType (String index , PathType pathType ) {
364
+ validatePathType (index , pathType , null );
365
+ }
366
+
367
+ private void validatePathType (String index , PathType pathType , @ Nullable PathHashAlgorithm pathHashAlgorithm ) {
334
368
ClusterState state = client ().admin ().cluster ().prepareState ().execute ().actionGet ().getState ();
335
369
// Validate that the remote_store custom data is present in index metadata for the created index.
336
370
Map <String , String > remoteCustomData = state .metadata ().index (index ).getCustomData (IndexMetadata .REMOTE_STORE_CUSTOM_KEY );
337
371
assertNotNull (remoteCustomData );
338
372
assertEquals (pathType .name (), remoteCustomData .get (PathType .NAME ));
339
- assertEquals (pathHashAlgorithm .name (), remoteCustomData .get (PathHashAlgorithm .NAME ));
373
+ if (Objects .nonNull (pathHashAlgorithm )) {
374
+ assertEquals (pathHashAlgorithm .name (), remoteCustomData .get (PathHashAlgorithm .NAME ));
375
+ }
340
376
}
341
377
342
378
public void testRestoreInSameRemoteStoreEnabledIndex () throws IOException {
0 commit comments