use the computed data structure to optimize the same shard allocation decider

This commit is contained in:
Shay Banon 2013-12-18 14:08:59 +01:00
parent f5d217c08e
commit 5827170d42
1 changed files with 5 additions and 5 deletions

View File

@ -52,9 +52,9 @@ public class SameShardAllocationDecider extends AllocationDecider {
@Override @Override
public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) {
for (MutableShardRouting nodeShard : node) { Iterable<MutableShardRouting> assignedShards = allocation.routingNodes().assignedShards(shardRouting);
// we do not allow for two shards of the same shard id to exists on the same node for (MutableShardRouting assignedShard : assignedShards) {
if (nodeShard.shardId().equals(shardRouting.shardId())) { if (node.nodeId().equals(assignedShard.currentNodeId())) {
return Decision.NO; return Decision.NO;
} }
} }
@ -68,8 +68,8 @@ public class SameShardAllocationDecider extends AllocationDecider {
if (!checkNode.node().address().sameHost(node.node().address())) { if (!checkNode.node().address().sameHost(node.node().address())) {
continue; continue;
} }
for (MutableShardRouting nodeShard : checkNode) { for (MutableShardRouting assignedShard : assignedShards) {
if (nodeShard.shardId().equals(shardRouting.shardId())) { if (checkNode.nodeId().equals(assignedShard.currentNodeId())) {
return Decision.NO; return Decision.NO;
} }
} }