Skip to content

Commit

Permalink
Switch to ShardsBatchGatewayAllocator in batch enabled mode for shard…
Browse files Browse the repository at this point in the history
… explain allocation API (#14107) (#14340)

(cherry picked from commit 2e13e9c)

Signed-off-by: Swetha Guptha <gupthasg@amazon.com>
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 <gupthasg@amazon.com>
  • Loading branch information
3 people authored Jun 14, 2024
1 parent b79fedc commit e1a632f
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -584,10 +584,7 @@ private void allocateExistingUnassignedShards(RoutingAllocation allocation) {
/*
Use batch mode if enabled and there is no custom allocator set for Allocation service
*/
Boolean batchModeEnabled = EXISTING_SHARDS_ALLOCATOR_BATCH_MODE.get(settings);
if (batchModeEnabled
&& allocation.nodes().getMinNodeVersion().onOrAfter(Version.V_2_14_0)
&& existingShardsAllocators.size() == 2) {
if (isBatchModeEnabled(allocation)) {
/*
If we do not have any custom allocator set then we will be using ShardsBatchGatewayAllocator
Currently AllocationService will not run any custom Allocator that implements allocateAllUnassignedShards
Expand Down Expand Up @@ -724,13 +721,24 @@ private AllocateUnassignedDecision explainUnassignedShardAllocation(ShardRouting

private ExistingShardsAllocator getAllocatorForShard(ShardRouting shardRouting, RoutingAllocation routingAllocation) {
assert assertInitialized();
final String allocatorName = ExistingShardsAllocator.EXISTING_SHARDS_ALLOCATOR_SETTING.get(
routingAllocation.metadata().getIndexSafe(shardRouting.index()).getSettings()
);
String allocatorName;
if (isBatchModeEnabled(routingAllocation)) {
allocatorName = ShardsBatchGatewayAllocator.ALLOCATOR_NAME;
} else {
allocatorName = ExistingShardsAllocator.EXISTING_SHARDS_ALLOCATOR_SETTING.get(
routingAllocation.metadata().getIndexSafe(shardRouting.index()).getSettings()
);
}
final ExistingShardsAllocator existingShardsAllocator = existingShardsAllocators.get(allocatorName);
return existingShardsAllocator != null ? existingShardsAllocator : new NotFoundAllocator(allocatorName);
}

private boolean isBatchModeEnabled(RoutingAllocation routingAllocation) {
return EXISTING_SHARDS_ALLOCATOR_BATCH_MODE.get(settings)
&& routingAllocation.nodes().getMinNodeVersion().onOrAfter(Version.V_2_14_0)
&& existingShardsAllocators.size() == 2;
}

private boolean assertInitialized() {
assert existingShardsAllocators != null : "must have set allocators first";
return true;
Expand Down

0 comments on commit e1a632f

Please sign in to comment.