From a84353d2d695c9c040fdd43cfac9f21a03ba9041 Mon Sep 17 00:00:00 2001 From: Luca Cavanna Date: Wed, 23 Nov 2016 22:18:02 +0100 Subject: [PATCH] Don't carry ShardRouting around when not needed in AbstractSearchAsyncAction (#21753) * replace ShardRouting argument in AbstractSearchAsyncAction#onFirstPhaseResult with more contained String nodeId There is no need to pass in ShardRouting if the only info read from it is the current node id, the shard id can be read directly from the ShardIterator that's already provided as an argument. * avoid creating a new ShardId when creating a SearchShardTarget in SnapshotsService --- .../action/search/AbstractSearchAsyncAction.java | 10 +++++----- .../org/elasticsearch/snapshots/SnapshotsService.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java b/core/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java index 824ad6f00fd..bd19e924a37 100644 --- a/core/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java +++ b/core/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java @@ -131,7 +131,7 @@ abstract class AbstractSearchAsyncAction sendExecuteFirstPhase(node, transportRequest , new ActionListener() { @Override public void onResponse(FirstResult result) { - onFirstPhaseResult(shardIndex, shard, result, shardIt); + onFirstPhaseResult(shardIndex, shard.currentNodeId(), result, shardIt); } @Override @@ -143,8 +143,8 @@ abstract class AbstractSearchAsyncAction } } - void onFirstPhaseResult(int shardIndex, ShardRouting shard, FirstResult result, ShardIterator shardIt) { - result.shardTarget(new SearchShardTarget(shard.currentNodeId(), shard.index(), shard.id())); + private void onFirstPhaseResult(int shardIndex, String nodeId, FirstResult result, ShardIterator shardIt) { + result.shardTarget(new SearchShardTarget(nodeId, shardIt.shardId())); processFirstPhaseResult(shardIndex, result); // we need to increment successful ops first before we compare the exit condition otherwise if we // are fast we could concurrently update totalOps but then preempt one of the threads which can @@ -173,11 +173,11 @@ abstract class AbstractSearchAsyncAction } } - void onFirstPhaseResult(final int shardIndex, @Nullable ShardRouting shard, @Nullable String nodeId, + private void onFirstPhaseResult(final int shardIndex, @Nullable ShardRouting shard, @Nullable String nodeId, final ShardIterator shardIt, Exception e) { // we always add the shard failure for a specific shard instance // we do make sure to clean it on a successful response from a shard - SearchShardTarget shardTarget = new SearchShardTarget(nodeId, shardIt.shardId().getIndex(), shardIt.shardId().getId()); + SearchShardTarget shardTarget = new SearchShardTarget(nodeId, shardIt.shardId()); addShardFailure(shardIndex, shardTarget, e); if (totalOps.incrementAndGet() == expectedTotalOps) { diff --git a/core/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java b/core/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java index f5ef5f111df..d84e3c79f66 100644 --- a/core/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java +++ b/core/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java @@ -871,7 +871,7 @@ public class SnapshotsService extends AbstractLifecycleComponent implements Clus ShardId shardId = shardStatus.key; ShardSnapshotStatus status = shardStatus.value; if (status.state().failed()) { - failures.add(new ShardSearchFailure(status.reason(), new SearchShardTarget(status.nodeId(), shardId.getIndex(), shardId.id()))); + failures.add(new ShardSearchFailure(status.reason(), new SearchShardTarget(status.nodeId(), shardId))); shardFailures.add(new SnapshotShardFailure(status.nodeId(), shardId, status.reason())); } }