12
12
import org .elasticsearch .action .ActionListener ;
13
13
import org .elasticsearch .action .FailedNodeException ;
14
14
import org .elasticsearch .action .IndicesRequest ;
15
- import org .elasticsearch .action .NoShardAvailableActionException ;
16
15
import org .elasticsearch .action .support .ActionFilters ;
17
16
import org .elasticsearch .action .support .DefaultShardOperationFailedException ;
18
17
import org .elasticsearch .action .support .HandledTransportAction ;
@@ -120,7 +119,7 @@ public TransportBroadcastByNodeAction(
120
119
private Response newResponse (
121
120
Request request ,
122
121
AtomicReferenceArray <?> responses ,
123
- List < NoShardAvailableActionException > unavailableShardExceptions ,
122
+ int unavailableShardCount ,
124
123
Map <String , List <ShardRouting >> nodes ,
125
124
ClusterState clusterState
126
125
) {
@@ -154,7 +153,7 @@ private Response newResponse(
154
153
}
155
154
}
156
155
}
157
- totalShards += unavailableShardExceptions . size () ;
156
+ totalShards += unavailableShardCount ;
158
157
int failedShards = exceptions .size ();
159
158
return newResponse (request , totalShards , successfulShards , failedShards , broadcastByNodeResponses , exceptions , clusterState );
160
159
}
@@ -267,7 +266,7 @@ protected class AsyncAction {
267
266
private final Map <String , List <ShardRouting >> nodeIds ;
268
267
private final AtomicReferenceArray <Object > responses ;
269
268
private final AtomicInteger counter = new AtomicInteger ();
270
- private List < NoShardAvailableActionException > unavailableShardExceptions = new ArrayList <>() ;
269
+ private final int unavailableShardCount ;
271
270
272
271
protected AsyncAction (Task task , Request request , ActionListener <Response > listener ) {
273
272
this .task = task ;
@@ -294,6 +293,7 @@ protected AsyncAction(Task task, Request request, ActionListener<Response> liste
294
293
ShardsIterator shardIt = shards (clusterState , request , concreteIndices );
295
294
nodeIds = new HashMap <>();
296
295
296
+ int unavailableShardCount = 0 ;
297
297
for (ShardRouting shard : shardIt ) {
298
298
// send a request to the shard only if it is assigned to a node that is in the local node's cluster state
299
299
// a scenario in which a shard can be assigned but to a node that is not in the local node's cluster state
@@ -308,15 +308,11 @@ protected AsyncAction(Task task, Request request, ActionListener<Response> liste
308
308
}
309
309
nodeIds .get (nodeId ).add (shard );
310
310
} else {
311
- unavailableShardExceptions .add (
312
- new NoShardAvailableActionException (
313
- shard .shardId (),
314
- " no shards available for shard " + shard .toString () + " while executing " + actionName
315
- )
316
- );
311
+ unavailableShardCount ++;
317
312
}
318
- }
319
313
314
+ }
315
+ this .unavailableShardCount = unavailableShardCount ;
320
316
responses = new AtomicReferenceArray <>(nodeIds .size ());
321
317
}
322
318
@@ -409,7 +405,7 @@ protected void onCompletion() {
409
405
410
406
Response response = null ;
411
407
try {
412
- response = newResponse (request , responses , unavailableShardExceptions , nodeIds , clusterState );
408
+ response = newResponse (request , responses , unavailableShardCount , nodeIds , clusterState );
413
409
} catch (Exception e ) {
414
410
logger .debug ("failed to combine responses from nodes" , e );
415
411
listener .onFailure (e );
0 commit comments