Skip to content

Commit 213ae57

Browse files
Simplify AbstractSearchAsyncAction.doPerformPhaseOnShard (#116104) (#117411)
1. No need to catch here any longer, we fixed the connection related exceptions separately now, throwing from an method that consumes a listener was smelly to begin with. 2. Not need to try-with-resources that `releasable`, just release it as soon as possible to get the next per-shard request going while we process a result. No need to waste time on an idle data node here.
1 parent e34e735 commit 213ae57

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

server/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -324,33 +324,23 @@ protected void performPhaseOnShard(final int shardIndex, final SearchShardIterat
324324
}
325325

326326
private void doPerformPhaseOnShard(int shardIndex, SearchShardIterator shardIt, SearchShardTarget shard, Releasable releasable) {
327-
try {
328-
executePhaseOnShard(shardIt, shard, new SearchActionListener<>(shard, shardIndex) {
329-
@Override
330-
public void innerOnResponse(Result result) {
331-
try (releasable) {
332-
onShardResult(result, shardIt);
333-
} catch (Exception exc) {
334-
onShardFailure(shardIndex, shard, shardIt, exc);
335-
}
327+
executePhaseOnShard(shardIt, shard, new SearchActionListener<>(shard, shardIndex) {
328+
@Override
329+
public void innerOnResponse(Result result) {
330+
try {
331+
releasable.close();
332+
onShardResult(result, shardIt);
333+
} catch (Exception exc) {
334+
onShardFailure(shardIndex, shard, shardIt, exc);
336335
}
336+
}
337337

338-
@Override
339-
public void onFailure(Exception e) {
340-
try (releasable) {
341-
onShardFailure(shardIndex, shard, shardIt, e);
342-
}
343-
}
344-
});
345-
} catch (final Exception e) {
346-
/*
347-
* It is possible to run into connection exceptions here because we are getting the connection early and might
348-
* run into nodes that are not connected. In this case, on shard failure will move us to the next shard copy.
349-
*/
350-
try (releasable) {
338+
@Override
339+
public void onFailure(Exception e) {
340+
releasable.close();
351341
onShardFailure(shardIndex, shard, shardIt, e);
352342
}
353-
}
343+
});
354344
}
355345

356346
private void failOnUnavailable(int shardIndex, SearchShardIterator shardIt) {

0 commit comments

Comments
 (0)