Skip to content

Commit 1b70fc7

Browse files
opensearch-trigger-bot[bot]github-actions[bot]Swetha Guptha
authored
Switch to ShardsBatchGatewayAllocator in batch enabled mode for shard explain allocation API (#14107) (#14218)
(cherry picked from commit 2e13e9c) Signed-off-by: Swetha Guptha <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Swetha Guptha <[email protected]>
1 parent 8f9d958 commit 1b70fc7

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

server/src/main/java/org/opensearch/cluster/routing/allocation/AllocationService.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)