Class ExternalSourceDrainUtils
CloseableIterator into an AsyncExternalSourceBuffer
with non-blocking backpressure.
Runs synchronously while the buffer has space (hot path), yields the thread when the buffer is
full, and resumes via the provided Executor when space is freed (cold path). No timeout is
needed — cancellation propagates via AsyncExternalSourceBuffer.finish(boolean) setting
noMoreInputs, which causes AsyncExternalSourceBuffer.waitForSpace() to return an
already-completed listener so the drain loop exits promptly.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voiddrainPagesAsync(CloseableIterator<Page> pages, AsyncExternalSourceBuffer buffer, Executor executor, ActionListener<Void> listener) Drains pages from iterator into buffer asynchronously.
-
Method Details
-
drainPagesAsync
public static void drainPagesAsync(CloseableIterator<Page> pages, AsyncExternalSourceBuffer buffer, Executor executor, ActionListener<Void> listener) Drains pages from iterator into buffer asynchronously. Runs synchronously while the buffer has space; yields the thread when the buffer is full and resumes viaexecutorwhen space is freed. Completion (success or failure) is reported via the listener.Iterator ownership: This method does NOT close the iterator. The caller must close it regardless of outcome (e.g. via
ActionListener.runAfter(org.elasticsearch.action.ActionListener<Response>, java.lang.Runnable)).Executor contract: The
executormust be a real thread-pool executor (e.g.generic), neverDIRECT_EXECUTOR_SERVICE. Continuations resume on this executor to avoid running producer I/O on the Driver thread. The executor captures and restores thread context at submission time, so no explicit context-preserving wrapper is needed.Cancellation: No timeout. Cancellation comes from
buffer.finish(true)settingnoMoreInputs, which causeswaitForSpace()to return an already-completed listener.
-