Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,14 @@ private void setPrimariesInitialRecoveries(int primariesInitialRecoveries) {
@Override
public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) {
if (shardRouting.primary() && shardRouting.unassigned()) {
// Primary is unassigned, means we are going to do recovery from store, snapshot or local shards
assert initializingShard(shardRouting, node.nodeId()).recoverySource().getType() != RecoverySource.Type.PEER;
// primary is unassigned, means we are going to do recovery from store, snapshot or local shards
// count *just the primaries* currently doing recovery on the node and check against primariesInitialRecoveries

if (allocation.isSimulating()) {
return allocation.decision(Decision.YES, NAME, "primary allocation is not throttled when simulating");
}

// Count the primaries currently doing recovery on the node, to ensure the primariesInitialRecoveries setting is obeyed.
int primariesInRecovery = 0;
for (ShardRouting shard : node.initializing()) {
// when a primary shard is INITIALIZING, it can be because of *initial recovery* or *relocation from another node*
Expand All @@ -130,10 +134,7 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing
primariesInRecovery++;
}
}
if (allocation.isSimulating()) {
return allocation.decision(Decision.YES, NAME, "primary allocation is not throttled when simulating");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seemed silly to do an early return after counting primariesInRecovery, which isn't used. So I moved it up, save some cycles.

} else if (primariesInRecovery >= primariesInitialRecoveries) {
// TODO: Should index creation not be throttled for primary shards?
if (primariesInRecovery >= primariesInitialRecoveries) {
return allocation.decision(
THROTTLE,
NAME,
Expand All @@ -142,9 +143,8 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing
CLUSTER_ROUTING_ALLOCATION_NODE_INITIAL_PRIMARIES_RECOVERIES_SETTING.getKey(),
primariesInitialRecoveries
);
} else {
return allocation.decision(YES, NAME, "below primary recovery limit of [%d]", primariesInitialRecoveries);
}
return allocation.decision(YES, NAME, "below primary recovery limit of [%d]", primariesInitialRecoveries);
} else {
// Peer recovery
assert initializingShard(shardRouting, node.nodeId()).recoverySource().getType() == RecoverySource.Type.PEER;
Expand Down