@@ -397,7 +397,52 @@ public void testIgnoreTotalShardsPerNodeInFrozenPhase() throws Exception {
397
397
}
398
398
}
399
399
400
- public void testDoNotIgnoreTotalShardsPerNodeAndReplicasIfSet () throws Exception {
400
+ public void testDoNotIgnorePropagatedTotalShardsPerNodeInColdPhase () throws Exception {
401
+ String indexName = randomAlphaOfLength (10 );
402
+ String policyName = "test-ilm-policy" ;
403
+ Map <String , String > ilmCustom = new HashMap <>();
404
+ String snapshotName = indexName + "-" + policyName ;
405
+ ilmCustom .put ("snapshot_name" , snapshotName );
406
+ String repository = "repository" ;
407
+ ilmCustom .put ("snapshot_repository" , repository );
408
+
409
+ IndexMetadata .Builder indexMetadataBuilder = IndexMetadata .builder (indexName )
410
+ .settings (settings (IndexVersion .current ()).put (LifecycleSettings .LIFECYCLE_NAME , policyName ))
411
+ .putCustom (LifecycleExecutionState .ILM_CUSTOM_METADATA_KEY , ilmCustom )
412
+ .numberOfShards (randomIntBetween (1 , 5 ))
413
+ .numberOfReplicas (randomIntBetween (0 , 5 ));
414
+ IndexMetadata indexMetadata = indexMetadataBuilder .build ();
415
+
416
+ ClusterState clusterState = ClusterState .builder (emptyClusterState ())
417
+ .metadata (Metadata .builder ().put (indexMetadata , true ).build ())
418
+ .build ();
419
+
420
+ try (var threadPool = createThreadPool ()) {
421
+ final var client = getRestoreSnapshotRequestAssertingClient (
422
+ threadPool ,
423
+ repository ,
424
+ snapshotName ,
425
+ indexName ,
426
+ RESTORED_INDEX_PREFIX ,
427
+ indexName ,
428
+ new String [] { LifecycleSettings .LIFECYCLE_NAME },
429
+ null ,
430
+ 0
431
+ );
432
+ MountSnapshotStep step = new MountSnapshotStep (
433
+ new StepKey (TimeseriesLifecycleType .COLD_PHASE , randomAlphaOfLength (10 ), randomAlphaOfLength (10 )),
434
+ randomStepKey (),
435
+ client ,
436
+ RESTORED_INDEX_PREFIX ,
437
+ randomStorageType (),
438
+ null ,
439
+ 0
440
+ );
441
+ performActionAndWait (step , indexMetadata , clusterState , null );
442
+ }
443
+ }
444
+
445
+ public void testDoNotIgnoreTotalShardsPerNodeAndReplicasIfSetInFrozenPhase () throws Exception {
401
446
String indexName = randomAlphaOfLength (10 );
402
447
String policyName = "test-ilm-policy" ;
403
448
Map <String , String > ilmCustom = new HashMap <>();
@@ -445,6 +490,54 @@ public void testDoNotIgnoreTotalShardsPerNodeAndReplicasIfSet() throws Exception
445
490
}
446
491
}
447
492
493
+ public void testDoNotIgnoreTotalShardsPerNodeAndReplicasIfSetInCold () throws Exception {
494
+ String indexName = randomAlphaOfLength (10 );
495
+ String policyName = "test-ilm-policy" ;
496
+ Map <String , String > ilmCustom = new HashMap <>();
497
+ String snapshotName = indexName + "-" + policyName ;
498
+ ilmCustom .put ("snapshot_name" , snapshotName );
499
+ String repository = "repository" ;
500
+ ilmCustom .put ("snapshot_repository" , repository );
501
+
502
+ IndexMetadata .Builder indexMetadataBuilder = IndexMetadata .builder (indexName )
503
+ .settings (settings (IndexVersion .current ()).put (LifecycleSettings .LIFECYCLE_NAME , policyName ))
504
+ .putCustom (LifecycleExecutionState .ILM_CUSTOM_METADATA_KEY , ilmCustom )
505
+ .numberOfShards (randomIntBetween (1 , 5 ))
506
+ .numberOfReplicas (randomIntBetween (0 , 5 ));
507
+ IndexMetadata indexMetadata = indexMetadataBuilder .build ();
508
+
509
+ ClusterState clusterState = ClusterState .builder (emptyClusterState ())
510
+ .metadata (Metadata .builder ().put (indexMetadata , true ).build ())
511
+ .build ();
512
+
513
+ final Integer totalShardsPerNode = randomTotalShardsPerNode (false );
514
+ final int replicas = randomIntBetween (1 , 5 );
515
+
516
+ try (var threadPool = createThreadPool ()) {
517
+ final var client = getRestoreSnapshotRequestAssertingClient (
518
+ threadPool ,
519
+ repository ,
520
+ snapshotName ,
521
+ indexName ,
522
+ RESTORED_INDEX_PREFIX ,
523
+ indexName ,
524
+ new String [] { LifecycleSettings .LIFECYCLE_NAME },
525
+ totalShardsPerNode ,
526
+ replicas
527
+ );
528
+ MountSnapshotStep step = new MountSnapshotStep (
529
+ new StepKey (TimeseriesLifecycleType .COLD_PHASE , randomAlphaOfLength (10 ), randomAlphaOfLength (10 )),
530
+ randomStepKey (),
531
+ client ,
532
+ RESTORED_INDEX_PREFIX ,
533
+ randomStorageType (),
534
+ totalShardsPerNode ,
535
+ replicas
536
+ );
537
+ performActionAndWait (step , indexMetadata , clusterState , null );
538
+ }
539
+ }
540
+
448
541
@ SuppressWarnings ("unchecked" )
449
542
private NoOpClient getClientTriggeringResponse (ThreadPool threadPool , RestoreSnapshotResponse response ) {
450
543
return new NoOpClient (threadPool ) {
0 commit comments