@@ -644,6 +644,25 @@ public void testDoNotCancelForBrokenNode() {
644
644
assertThat (allocation .routingNodes ().shardsWithState (ShardRoutingState .UNASSIGNED ), empty ());
645
645
}
646
646
647
+ public void testDoNotCancelForInactivePrimaryNode () {
648
+ RoutingAllocation allocation = oneInactivePrimaryOnNode1And1ReplicaRecovering (yesAllocationDeciders (), null );
649
+ testBatchAllocator .addData (
650
+ node1 ,
651
+ null ,
652
+ "MATCH" ,
653
+ null ,
654
+ new StoreFileMetadata ("file1" , 10 , "MATCH_CHECKSUM" , MIN_SUPPORTED_LUCENE_VERSION )
655
+ ).addData (node2 , randomSyncId (), null , new StoreFileMetadata ("file1" , 10 , "MATCH_CHECKSUM" , MIN_SUPPORTED_LUCENE_VERSION ));
656
+
657
+ testBatchAllocator .processExistingRecoveries (
658
+ allocation ,
659
+ Collections .singletonList (new ArrayList <>(allocation .routingNodes ().shardsWithState (ShardRoutingState .INITIALIZING )))
660
+ );
661
+
662
+ assertThat (allocation .routingNodesChanged (), equalTo (false ));
663
+ assertThat (allocation .routingNodes ().shardsWithState (ShardRoutingState .UNASSIGNED ), empty ());
664
+ }
665
+
647
666
public void testAllocateUnassignedBatchThrottlingAllocationDeciderIsHonoured () throws InterruptedException {
648
667
ClusterSettings clusterSettings = new ClusterSettings (Settings .EMPTY , ClusterSettings .BUILT_IN_CLUSTER_SETTINGS );
649
668
AllocationDeciders allocationDeciders = randomAllocationDeciders (
@@ -872,6 +891,41 @@ private RoutingAllocation onePrimaryOnNode1And1ReplicaRecovering(AllocationDecid
872
891
);
873
892
}
874
893
894
+ private RoutingAllocation oneInactivePrimaryOnNode1And1ReplicaRecovering (AllocationDeciders deciders , UnassignedInfo unassignedInfo ) {
895
+ ShardRouting primaryShard = TestShardRouting .newShardRouting (shardId , node1 .getId (), true , ShardRoutingState .INITIALIZING );
896
+ RoutingTable routingTable = RoutingTable .builder ()
897
+ .add (
898
+ IndexRoutingTable .builder (shardId .getIndex ())
899
+ .addIndexShard (
900
+ new IndexShardRoutingTable .Builder (shardId ).addShard (primaryShard )
901
+ .addShard (
902
+ TestShardRouting .newShardRouting (
903
+ shardId ,
904
+ node2 .getId (),
905
+ null ,
906
+ false ,
907
+ ShardRoutingState .INITIALIZING ,
908
+ unassignedInfo
909
+ )
910
+ )
911
+ .build ()
912
+ )
913
+ )
914
+ .build ();
915
+ ClusterState state = ClusterState .builder (org .opensearch .cluster .ClusterName .CLUSTER_NAME_SETTING .getDefault (Settings .EMPTY ))
916
+ .routingTable (routingTable )
917
+ .nodes (DiscoveryNodes .builder ().add (node1 ).add (node2 ))
918
+ .build ();
919
+ return new RoutingAllocation (
920
+ deciders ,
921
+ new RoutingNodes (state , false ),
922
+ state ,
923
+ ClusterInfo .EMPTY ,
924
+ SnapshotShardSizeInfo .EMPTY ,
925
+ System .nanoTime ()
926
+ );
927
+ }
928
+
875
929
private RoutingAllocation onePrimaryOnNode1And1ReplicaRecovering (AllocationDeciders deciders ) {
876
930
return onePrimaryOnNode1And1ReplicaRecovering (deciders , new UnassignedInfo (UnassignedInfo .Reason .CLUSTER_RECOVERED , null ));
877
931
}
0 commit comments