@@ -91,19 +91,18 @@ public static class Handler implements Releasable {
9191 public static final BulkRequest .IncrementalState EMPTY_STATE = new BulkRequest .IncrementalState (Collections .emptyMap (), true );
9292
9393 private final Client client ;
94- private final IndexingPressure indexingPressure ;
9594 private final ActiveShardCount waitForActiveShards ;
9695 private final TimeValue timeout ;
9796 private final String refresh ;
9897
9998 private final ArrayList <Releasable > releasables = new ArrayList <>(4 );
10099 private final ArrayList <BulkResponse > responses = new ArrayList <>(2 );
100+ private final IndexingPressure .Coordinating coordinatingOperation ;
101101 private boolean closed = false ;
102102 private boolean globalFailure = false ;
103103 private boolean incrementalRequestSubmitted = false ;
104104 private boolean bulkInProgress = false ;
105105 private Exception bulkActionLevelFailure = null ;
106- private IndexingPressure .Coordinating coordinatingOperation ;
107106 private BulkRequest bulkRequest = null ;
108107
109108 protected Handler (
@@ -114,10 +113,10 @@ protected Handler(
114113 @ Nullable String refresh
115114 ) {
116115 this .client = client ;
117- this .indexingPressure = indexingPressure ;
118116 this .waitForActiveShards = waitForActiveShards != null ? ActiveShardCount .parseString (waitForActiveShards ) : null ;
119117 this .timeout = timeout ;
120118 this .refresh = refresh ;
119+ this .coordinatingOperation = indexingPressure .markCoordinatingOperationStarted (0 , 0 , false );
121120 createNewBulkRequest (EMPTY_STATE );
122121 }
123122
@@ -152,8 +151,7 @@ public void onFailure(Exception e) {
152151 }
153152 }, () -> {
154153 bulkInProgress = false ;
155- coordinatingOperation .close ();
156- coordinatingOperation = null ;
154+ coordinatingOperation .releaseCurrent ();
157155 toRelease .forEach (Releasable ::close );
158156 nextItems .run ();
159157 }));
@@ -194,8 +192,7 @@ public void onFailure(Exception e) {
194192 errorResponse (listener );
195193 }
196194 }, () -> {
197- coordinatingOperation .close ();
198- coordinatingOperation = null ;
195+ coordinatingOperation .releaseCurrent ();
199196 toRelease .forEach (Releasable ::close );
200197 }));
201198 } else {
@@ -208,13 +205,13 @@ public void onFailure(Exception e) {
208205 public void close () {
209206 closed = true ;
210207 coordinatingOperation .close ();
211- coordinatingOperation = null ;
212208 releasables .forEach (Releasable ::close );
213209 releasables .clear ();
214210 }
215211
216212 private void shortCircuitDueToTopLevelFailure (List <DocWriteRequest <?>> items , Releasable releasable ) {
217213 assert releasables .isEmpty ();
214+ assert coordinatingOperation .currentSize () == 0 ;
218215 assert bulkRequest == null ;
219216 if (globalFailure == false ) {
220217 addItemLevelFailures (items );
@@ -263,8 +260,7 @@ private boolean internalAddItems(List<DocWriteRequest<?>> items, Releasable rele
263260 return true ;
264261 } catch (EsRejectedExecutionException e ) {
265262 handleBulkFailure (incrementalRequestSubmitted == false , e );
266- coordinatingOperation .close ();
267- coordinatingOperation = null ;
263+ coordinatingOperation .releaseCurrent ();
268264 releasables .forEach (Releasable ::close );
269265 releasables .clear ();
270266 return false ;
@@ -275,7 +271,6 @@ private void createNewBulkRequest(BulkRequest.IncrementalState incrementalState)
275271 assert bulkRequest == null ;
276272 bulkRequest = new BulkRequest ();
277273 bulkRequest .incrementalState (incrementalState );
278- coordinatingOperation = indexingPressure .markCoordinatingOperationStarted (0 , 0 , false );
279274
280275 if (waitForActiveShards != null ) {
281276 bulkRequest .waitForActiveShards (waitForActiveShards );
0 commit comments