15
15
import org .elasticsearch .action .search .SearchShardsGroup ;
16
16
import org .elasticsearch .action .search .SearchShardsRequest ;
17
17
import org .elasticsearch .action .search .SearchShardsResponse ;
18
+ import org .elasticsearch .action .search .ShardSearchFailure ;
18
19
import org .elasticsearch .action .support .TransportActions ;
19
20
import org .elasticsearch .cluster .node .DiscoveryNode ;
20
21
import org .elasticsearch .cluster .node .DiscoveryNodeRole ;
26
27
import org .elasticsearch .index .Index ;
27
28
import org .elasticsearch .index .query .QueryBuilder ;
28
29
import org .elasticsearch .index .shard .ShardId ;
30
+ import org .elasticsearch .search .SearchShardTarget ;
29
31
import org .elasticsearch .search .internal .AliasFilter ;
30
32
import org .elasticsearch .tasks .CancellableTask ;
31
33
import org .elasticsearch .tasks .Task ;
@@ -73,6 +75,7 @@ abstract class DataNodeRequestSender {
73
75
74
76
private final TransportService transportService ;
75
77
private final Executor esqlExecutor ;
78
+ private final String clusterAlias ;
76
79
private final CancellableTask rootTask ;
77
80
private final boolean allowPartialResults ;
78
81
private final Semaphore concurrentRequests ;
@@ -87,12 +90,14 @@ abstract class DataNodeRequestSender {
87
90
DataNodeRequestSender (
88
91
TransportService transportService ,
89
92
Executor esqlExecutor ,
93
+ String clusterAlias ,
90
94
CancellableTask rootTask ,
91
95
boolean allowPartialResults ,
92
96
int concurrentRequests
93
97
) {
94
98
this .transportService = transportService ;
95
99
this .esqlExecutor = esqlExecutor ;
100
+ this .clusterAlias = clusterAlias ;
96
101
this .rootTask = rootTask ;
97
102
this .allowPartialResults = allowPartialResults ;
98
103
this .concurrentRequests = concurrentRequests > 0 ? new Semaphore (concurrentRequests ) : null ;
@@ -209,16 +214,25 @@ private void reportFailures(ComputeListener computeListener) {
209
214
}
210
215
}
211
216
212
- private List <Exception > selectFailures () {
217
+ private List <ShardSearchFailure > selectFailures () {
213
218
assert reportedFailure == false ;
214
- FailureCollector collector = new FailureCollector ();
219
+ List < ShardSearchFailure > failures = new ArrayList <> ();
215
220
Set <Exception > seen = Collections .newSetFromMap (new IdentityHashMap <>());
216
- for (ShardFailure e : shardFailures .values ()) {
217
- if (seen .add (e .failure )) {
218
- collector .unwrapAndCollect (e .failure );
221
+ for (Map .Entry <ShardId , ShardFailure > e : shardFailures .entrySet ()) {
222
+ ShardFailure failure = e .getValue ();
223
+ if (ExceptionsHelper .unwrap (failure .failure (), TaskCancelledException .class ) != null ) {
224
+ continue ;
219
225
}
226
+ if (seen .add (failure .failure ) && failures .size () < 5 ) {
227
+ failures .add (new ShardSearchFailure (failure .failure , new SearchShardTarget (null , e .getKey (), clusterAlias )));
228
+ }
229
+ }
230
+ // pick any cancellation
231
+ if (failures .isEmpty () && shardFailures .isEmpty () == false ) {
232
+ ShardFailure any = shardFailures .values ().iterator ().next ();
233
+ failures .add (new ShardSearchFailure (any .failure ));
220
234
}
221
- return collector . getFailures () ;
235
+ return failures ;
222
236
}
223
237
224
238
private void sendOneNodeRequest (TargetShards targetShards , ComputeListener computeListener , NodeRequest request ) {
0 commit comments