From 5ce42b337d01bc75d7dada53791e4bc9bde95341 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Sun, 24 Jul 2011 20:33:49 +0300 Subject: [PATCH] Get API: Will always prefer first local execution, regardless of the preference, closes #1153. --- .../TransportShardSingleOperationAction.java | 114 ++++++++---------- 1 file changed, 48 insertions(+), 66 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/single/shard/TransportShardSingleOperationAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/single/shard/TransportShardSingleOperationAction.java index d6ea757a071..39b8533d10f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/single/shard/TransportShardSingleOperationAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/single/shard/TransportShardSingleOperationAction.java @@ -30,6 +30,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.ShardIterator; import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.common.Nullable; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; @@ -117,7 +118,7 @@ public abstract class TransportShardSingleOperationAction() { - - @Override public Response newInstance() { - return newResponse(); - } - - @Override public String executor() { - return ThreadPool.Names.SAME; - } - - @Override public void handleResponse(final Response response) { - listener.onResponse(response); - } - - @Override public void handleException(TransportException exp) { - onFailure(shard, exp); - } - }); - return; - } - } - if (!shardIt.hasNextActive()) { + private void perform(@Nullable final Exception lastException) { + final ShardRouting shardRouting = shardIt.nextActiveOrNull(); + if (shardRouting == null) { Exception failure = lastException; if (failure == null) { failure = new NoShardAvailableActionException(shardIt.shardId(), "No shard available for [" + request + "]"); @@ -201,6 +140,49 @@ public abstract class TransportShardSingleOperationAction() { + + @Override public Response newInstance() { + return newResponse(); + } + + @Override public String executor() { + return ThreadPool.Names.SAME; + } + + @Override public void handleResponse(final Response response) { + listener.onResponse(response); + } + + @Override public void handleException(TransportException exp) { + onFailure(shardRouting, exp); + } + }); } } }