@@ -584,10 +584,7 @@ private void allocateExistingUnassignedShards(RoutingAllocation allocation) {
584584 /*
585585 Use batch mode if enabled and there is no custom allocator set for Allocation service
586586 */
587- Boolean batchModeEnabled = EXISTING_SHARDS_ALLOCATOR_BATCH_MODE .get (settings );
588- if (batchModeEnabled
589- && allocation .nodes ().getMinNodeVersion ().onOrAfter (Version .V_2_14_0 )
590- && existingShardsAllocators .size () == 2 ) {
587+ if (isBatchModeEnabled (allocation )) {
591588 /*
592589 If we do not have any custom allocator set then we will be using ShardsBatchGatewayAllocator
593590 Currently AllocationService will not run any custom Allocator that implements allocateAllUnassignedShards
@@ -724,13 +721,24 @@ private AllocateUnassignedDecision explainUnassignedShardAllocation(ShardRouting
724721
725722 private ExistingShardsAllocator getAllocatorForShard (ShardRouting shardRouting , RoutingAllocation routingAllocation ) {
726723 assert assertInitialized ();
727- final String allocatorName = ExistingShardsAllocator .EXISTING_SHARDS_ALLOCATOR_SETTING .get (
728- routingAllocation .metadata ().getIndexSafe (shardRouting .index ()).getSettings ()
729- );
724+ String allocatorName ;
725+ if (isBatchModeEnabled (routingAllocation )) {
726+ allocatorName = ShardsBatchGatewayAllocator .ALLOCATOR_NAME ;
727+ } else {
728+ allocatorName = ExistingShardsAllocator .EXISTING_SHARDS_ALLOCATOR_SETTING .get (
729+ routingAllocation .metadata ().getIndexSafe (shardRouting .index ()).getSettings ()
730+ );
731+ }
730732 final ExistingShardsAllocator existingShardsAllocator = existingShardsAllocators .get (allocatorName );
731733 return existingShardsAllocator != null ? existingShardsAllocator : new NotFoundAllocator (allocatorName );
732734 }
733735
736+ private boolean isBatchModeEnabled (RoutingAllocation routingAllocation ) {
737+ return EXISTING_SHARDS_ALLOCATOR_BATCH_MODE .get (settings )
738+ && routingAllocation .nodes ().getMinNodeVersion ().onOrAfter (Version .V_2_14_0 )
739+ && existingShardsAllocators .size () == 2 ;
740+ }
741+
734742 private boolean assertInitialized () {
735743 assert existingShardsAllocators != null : "must have set allocators first" ;
736744 return true ;
0 commit comments