Skip to content

Commit 7cd189b

Browse files
committed
Trace log all shard failures if an exception is attached.
1 parent 44382ae commit 7cd189b

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/main/java/org/elasticsearch/action/search/type/TransportSearchTypeAction.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -279,33 +279,32 @@ void onFirstPhaseResult(final int shardIndex, @Nullable ShardRouting shard, @Nul
279279
}
280280
} else {
281281
ShardRouting nextShard = shardIt.nextOrNull();
282-
if (nextShard != null) {
283-
// trace log this exception
284-
if (logger.isTraceEnabled()) {
285-
if (t != null) {
286-
if (shard != null) {
287-
logger.trace(shard.shortSummary() + ": Failed to execute [" + request + "]", t);
288-
} else {
289-
logger.trace(shardIt.shardId() + ": Failed to execute [" + request + "]", t);
290-
}
291-
}
292-
}
282+
final boolean lastShard = nextShard == null;
283+
// trace log this exception
284+
if (logger.isTraceEnabled() && t != null) {
285+
logger.trace(executionFailureMsg(shard, shardIt, request, lastShard), t);
286+
}
287+
if (!lastShard) {
293288
performFirstPhase(shardIndex, shardIt, nextShard);
294289
} else {
295290
// no more shards active, add a failure
296-
if (logger.isDebugEnabled()) {
291+
if (logger.isDebugEnabled() && !logger.isTraceEnabled()) { // do not double log this exception
297292
if (t != null && !TransportActions.isShardNotAvailableException(t)) {
298-
if (shard != null) {
299-
logger.debug(shard.shortSummary() + ": Failed to execute [" + request + "]", t);
300-
} else {
301-
logger.debug(shardIt.shardId() + ": Failed to execute [" + request + "]", t);
302-
}
293+
logger.debug(executionFailureMsg(shard, shardIt, request, lastShard), t);
303294
}
304295
}
305296
}
306297
}
307298
}
308299

300+
private String executionFailureMsg(@Nullable ShardRouting shard, final ShardIterator shardIt, SearchRequest request, boolean lastShard) {
301+
if (shard != null) {
302+
return shard.shortSummary() + ": Failed to execute [" + request + "] lastShard [" + lastShard + "]";
303+
} else {
304+
return shardIt.shardId() + ": Failed to execute [" + request + "] lastShard [" + lastShard + "]";
305+
}
306+
}
307+
309308
/**
310309
* Builds how long it took to execute the search.
311310
*/

0 commit comments

Comments
 (0)