Skip to content

Commit

Permalink
Make AllocationDeciders.canRemain more Efficient (elastic#83171)
Browse files Browse the repository at this point in the history
The iteration before this change was over the value collection
of a linked hash map, wrapped in unmodifiable. Given that this runs
approximately #deciders * #shards iterations during a reroute it
makes sense to optimize here.
In practice the iteration did not inline well and showed up as about
25% of the overall cost of this method.
  • Loading branch information
original-brownbear authored Jan 26, 2022
1 parent 305ff20 commit 5b1f8d4
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;

import java.util.Collection;
import java.util.Collections;

/**
* A composite {@link AllocationDecider} combining the "decision" of multiple
Expand All @@ -27,10 +26,10 @@ public class AllocationDeciders extends AllocationDecider {

private static final Logger logger = LogManager.getLogger(AllocationDeciders.class);

private final Collection<AllocationDecider> allocations;
private final AllocationDecider[] allocations;

public AllocationDeciders(Collection<AllocationDecider> allocations) {
this.allocations = Collections.unmodifiableCollection(allocations);
this.allocations = allocations.toArray(AllocationDecider[]::new);
}

@Override
Expand Down Expand Up @@ -265,7 +264,7 @@ public Decision canAllocateReplicaWhenThereIsRetentionLease(ShardRouting shardRo
return ret;
}

private void addDecision(Decision.Multi ret, Decision decision, RoutingAllocation allocation) {
private static void addDecision(Decision.Multi ret, Decision decision, RoutingAllocation allocation) {
// We never add ALWAYS decisions and only add YES decisions when requested by debug mode (since Multi default is YES).
if (decision != Decision.ALWAYS
&& (allocation.getDebugMode() == RoutingAllocation.DebugMode.ON || decision.type() != Decision.Type.YES)) {
Expand Down

0 comments on commit 5b1f8d4

Please sign in to comment.