From 5827170d4231fbcf6e7a0b00a59353edb613c260 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Wed, 18 Dec 2013 14:08:59 +0100 Subject: [PATCH] use the computed data structure to optimize the same shard allocation decider --- .../allocation/decider/SameShardAllocationDecider.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/SameShardAllocationDecider.java b/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/SameShardAllocationDecider.java index e49ab2e6e43..3d429fa5dad 100644 --- a/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/SameShardAllocationDecider.java +++ b/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/SameShardAllocationDecider.java @@ -52,9 +52,9 @@ public class SameShardAllocationDecider extends AllocationDecider { @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { - for (MutableShardRouting nodeShard : node) { - // we do not allow for two shards of the same shard id to exists on the same node - if (nodeShard.shardId().equals(shardRouting.shardId())) { + Iterable assignedShards = allocation.routingNodes().assignedShards(shardRouting); + for (MutableShardRouting assignedShard : assignedShards) { + if (node.nodeId().equals(assignedShard.currentNodeId())) { return Decision.NO; } } @@ -68,8 +68,8 @@ public class SameShardAllocationDecider extends AllocationDecider { if (!checkNode.node().address().sameHost(node.node().address())) { continue; } - for (MutableShardRouting nodeShard : checkNode) { - if (nodeShard.shardId().equals(shardRouting.shardId())) { + for (MutableShardRouting assignedShard : assignedShards) { + if (checkNode.nodeId().equals(assignedShard.currentNodeId())) { return Decision.NO; } }