Source:
<code>private void processBulkIndexIngestRequest(Task task, BulkRequest original, ActionListener<BulkResponse> listener) { final long ingestStartTimeInNanos = System.nanoTime(); final BulkRequestModifier bulkRequestModifier = new BulkRequestModifier(original); ingestService.executeBulkRequest( original.numberOfActions(), () -> bulkRequestModifier, bulkRequestModifier::markItemAsFailed, (originalThread, exception) -> { if (exception != null) { logger.debug("failed to execute pipeline for a bulk request", exception); listener.onFailure(exception); } else { long ingestTookInMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - ingestStartTimeInNanos); BulkRequest bulkRequest = bulkRequestModifier.getBulkRequest(); ActionListener<BulkResponse> actionListener = bulkRequestModifier.wrapActionListenerIfNeeded(ingestTookInMillis, listener); if (bulkRequest.requests().isEmpty()) { actionListener.onResponse(new BulkResponse(new BulkItemResponse[0], 0)); } else { if (originalThread == Thread.currentThread()) { assert Thread.currentThread().getName().contains(ThreadPool.Names.WRITE); doDispatchedExecute(task, bulkRequest, actionListener); } else { threadPool.executor(ThreadPool.Names.WRITE).execute(new AbstractRunnable() { @Override public void onFailure(Exception e) { listener.onFailure(e); } @Override protected void doRun() throws Exception { <START> doDispatchedExecute(task, bulkRequest, actionListener); <END> } @Override public boolean isForceExecution() { return true; } }); } } } }, bulkRequestModifier::markItemAsDropped ); }</code><technical_language>do protect double-accounting bulk request / bulk shard requests run ingestService? Also, in case bulk request (see forwardIngestRequest), stop accounting for bytes of original bulk request soon request is sent</technical_language>

Target:
private void processBulkIndexIngestRequest(Task task, BulkRequest original, ActionListener<BulkResponse> listener) { final long ingestStartTimeInNanos = System.nanoTime(); final BulkRequestModifier bulkRequestModifier = new BulkRequestModifier(original); ingestService.executeBulkRequest( original.numberOfActions(), () -> bulkRequestModifier, bulkRequestModifier::markItemAsFailed, (originalThread, exception) -> { if (exception != null) { logger.debug("failed to execute pipeline for a bulk request", exception); listener.onFailure(exception); } else { long ingestTookInMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - ingestStartTimeInNanos); BulkRequest bulkRequest = bulkRequestModifier.getBulkRequest(); ActionListener<BulkResponse> actionListener = bulkRequestModifier.wrapActionListenerIfNeeded(ingestTookInMillis, listener); if (bulkRequest.requests().isEmpty()) { actionListener.onResponse(new BulkResponse(new BulkItemResponse[0], 0)); } else { if (originalThread == Thread.currentThread()) { assert Thread.currentThread().getName().contains(ThreadPool.Names.WRITE); doInternalExecute(task, bulkRequest, actionListener); } else { threadPool.executor(ThreadPool.Names.WRITE).execute(new AbstractRunnable() { @Override public void onFailure(Exception e) { listener.onFailure(e); } @Override protected void doRun() throws Exception { doInternalExecute(task, bulkRequest, actionListener); } @Override public boolean isForceExecution() { return true; } }); } } } }, bulkRequestModifier::markItemAsDropped ); }