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