-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Make some Allocation Decider Code a Little More JIT Aware #62275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e53fbf0
ad98bd5
99019b3
6e772a0
7ef2fc7
1f811c8
6bd6608
8a59791
89bc2c6
7813daf
765850c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
|
|
||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
| import org.elasticsearch.cluster.routing.RoutingNodes; | ||
| import org.elasticsearch.cluster.routing.ShardRouting; | ||
| import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; | ||
| import org.elasticsearch.common.settings.ClusterSettings; | ||
|
|
@@ -109,40 +110,55 @@ public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation alloca | |
| return canRebalance(allocation); | ||
| } | ||
|
|
||
| private static final Decision YES_ALL_PRIMARIES_ACTIVE = Decision.single(Decision.Type.YES, NAME, "all primary shards are active"); | ||
|
|
||
| private static final Decision YES_ALL_SHARDS_ACTIVE = Decision.single(Decision.Type.YES, NAME, "all shards are active"); | ||
|
|
||
| private static final Decision NO_UNASSIGNED_PRIMARIES = Decision.single(Decision.Type.NO, NAME, | ||
| "the cluster has unassigned primary shards and cluster setting [" | ||
| + CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE + "] is set to [" + ClusterRebalanceType.INDICES_PRIMARIES_ACTIVE + "]"); | ||
|
|
||
| private static final Decision NO_INACTIVE_PRIMARIES = Decision.single(Decision.Type.NO, NAME, | ||
| "the cluster has inactive primary shards and cluster setting [" + CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE + | ||
| "] is set to [" + ClusterRebalanceType.INDICES_PRIMARIES_ACTIVE + "]"); | ||
|
|
||
| private static final Decision NO_UNASSIGNED_SHARDS = Decision.single(Decision.Type.NO, NAME, | ||
| "the cluster has unassigned shards and cluster setting [" + CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE + | ||
| "] is set to [" + ClusterRebalanceType.INDICES_ALL_ACTIVE + "]"); | ||
|
|
||
| private static final Decision NO_INACTIVE_SHARDS = Decision.single(Decision.Type.NO, NAME, | ||
| "the cluster has inactive shards and cluster setting [" + CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE + | ||
| "] is set to [" + ClusterRebalanceType.INDICES_ALL_ACTIVE + "]"); | ||
|
|
||
| @SuppressWarnings("fallthrough") | ||
| @Override | ||
| public Decision canRebalance(RoutingAllocation allocation) { | ||
| if (type == ClusterRebalanceType.INDICES_PRIMARIES_ACTIVE) { | ||
| // check if there are unassigned primaries. | ||
| if ( allocation.routingNodes().hasUnassignedPrimaries() ) { | ||
| return allocation.decision(Decision.NO, NAME, | ||
| "the cluster has unassigned primary shards and cluster setting [%s] is set to [%s]", | ||
| CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE, type); | ||
| } | ||
| // check if there are initializing primaries that don't have a relocatingNodeId entry. | ||
| if ( allocation.routingNodes().hasInactivePrimaries() ) { | ||
| return allocation.decision(Decision.NO, NAME, | ||
| "the cluster has inactive primary shards and cluster setting [%s] is set to [%s]", | ||
| CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE, type); | ||
| } | ||
|
|
||
| return allocation.decision(Decision.YES, NAME, "all primary shards are active"); | ||
| } | ||
| if (type == ClusterRebalanceType.INDICES_ALL_ACTIVE) { | ||
| // check if there are unassigned shards. | ||
| if (allocation.routingNodes().hasUnassignedShards() ) { | ||
| return allocation.decision(Decision.NO, NAME, | ||
| "the cluster has unassigned shards and cluster setting [%s] is set to [%s]", | ||
| CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE, type); | ||
| } | ||
| // in case all indices are assigned, are there initializing shards which | ||
| // are not relocating? | ||
| if ( allocation.routingNodes().hasInactiveShards() ) { | ||
| return allocation.decision(Decision.NO, NAME, | ||
| "the cluster has inactive shards and cluster setting [%s] is set to [%s]", | ||
| CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE, type); | ||
| } | ||
| final RoutingNodes routingNodes = allocation.routingNodes(); | ||
| switch (type) { | ||
| case INDICES_PRIMARIES_ACTIVE: | ||
| // check if there are unassigned primaries. | ||
| if (routingNodes.hasUnassignedPrimaries()) { | ||
| return NO_UNASSIGNED_PRIMARIES; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed by checking decision type :) thanks for spotting this!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we can add a test that the early termination works in |
||
| } | ||
| // check if there are initializing primaries that don't have a relocatingNodeId entry. | ||
| if (routingNodes.hasInactivePrimaries()) { | ||
| return NO_INACTIVE_PRIMARIES; | ||
| } | ||
| return YES_ALL_PRIMARIES_ACTIVE; | ||
| case INDICES_ALL_ACTIVE: | ||
| // check if there are unassigned shards. | ||
| if (routingNodes.hasUnassignedShards()) { | ||
| return NO_UNASSIGNED_SHARDS; | ||
| } | ||
| // in case all indices are assigned, are there initializing shards which | ||
| // are not relocating? | ||
| if (routingNodes.hasInactiveShards()) { | ||
| return NO_INACTIVE_SHARDS; | ||
| } | ||
| // fall-through | ||
| default: | ||
| // all shards active from above or type == Type.ALWAYS | ||
| return YES_ALL_SHARDS_ACTIVE; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add
to signal that fall through is intended. |
||
| // type == Type.ALWAYS | ||
| return allocation.decision(Decision.YES, NAME, "all shards are active"); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be nice to add
Decision.constantthat still uses Decision.Single but avoids the trap of being able to specify parameters (or eagerly resolves the string if anyone do specify them).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I'm starting to wonder how much point there even is in making the
Stringcreation in the existingDecision.singlelazy? The memory savings probably aren't that massive they only affectdebuganyway?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++, seems just resolving this early is not a big deal. It will resolve it anyway in both equals, hashCode and streaming write.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect :) Made it eager serialize now, also makes the
Decisionobject immutable in general :)