Skip to content

Commit c00abac

Browse files
Simplify AbstractSearchAsyncAction.doPerformPhaseOnShard (#116104)
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 7d0d50d commit c00abac

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
@@ -296,33 +296,23 @@ protected void performPhaseOnShard(final int shardIndex, final SearchShardIterat
296296
}
297297

298298
private void doPerformPhaseOnShard(int shardIndex, SearchShardIterator shardIt, SearchShardTarget shard, Releasable releasable) {
299-
try {
300-
executePhaseOnShard(shardIt, shard, new SearchActionListener<>(shard, shardIndex) {
301-
@Override
302-
public void innerOnResponse(Result result) {
303-
try (releasable) {
304-
onShardResult(result, shardIt);
305-
} catch (Exception exc) {
306-
onShardFailure(shardIndex, shard, shardIt, exc);
307-
}
299+
executePhaseOnShard(shardIt, shard, new SearchActionListener<>(shard, shardIndex) {
300+
@Override
301+
public void innerOnResponse(Result result) {
302+
try {
303+
releasable.close();
304+
onShardResult(result, shardIt);
305+
} catch (Exception exc) {
306+
onShardFailure(shardIndex, shard, shardIt, exc);
308307
}
308+
}
309309

310-
@Override
311-
public void onFailure(Exception e) {
312-
try (releasable) {
313-
onShardFailure(shardIndex, shard, shardIt, e);
314-
}
315-
}
316-
});
317-
} catch (final Exception e) {
318-
/*
319-
* It is possible to run into connection exceptions here because we are getting the connection early and might
320-
* run into nodes that are not connected. In this case, on shard failure will move us to the next shard copy.
321-
*/
322-
try (releasable) {
310+
@Override
311+
public void onFailure(Exception e) {
312+
releasable.close();
323313
onShardFailure(shardIndex, shard, shardIt, e);
324314
}
325-
}
315+
});
326316
}
327317

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

0 commit comments

Comments
 (0)