Class AsyncExternalSourceBuffer
java.lang.Object
org.elasticsearch.xpack.esql.datasources.AsyncExternalSourceBuffer
Thread-safe buffer for async external source data.
Modeled after
ExchangeBuffer.
This buffer provides:
- Thread-safe page queue for cross-thread communication
- Byte-based backpressure control proportional to actual memory usage
- Notification via SubscribableListener when data becomes available
- Lifecycle management (finished state tracking)-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longDefault byte limit for the buffer, preserving the original "10 normal-sized pages" intent. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCompletionListener(ActionListener<Void> listener) Adds a listener that will be notified when this buffer is finished.voidAdd a page to the buffer.longReturns the current number of bytes buffered, as measured byPage.ramBytesUsedByBlocks().failure()voidfinish(boolean drainingPages) Mark the buffer as finished.booleanbooleanvoidMark the buffer as failed.pollPage()Poll a page from the buffer.intsize()Returns anIsBlockedResultthat completes when the buffer has data for reading.Returns aSubscribableListenerthat completes when the buffer has space for writing.Returns anIsBlockedResultthat completes when the buffer has space for writing.
-
Field Details
-
DEFAULT_MAX_BUFFER_BYTES
public static final long DEFAULT_MAX_BUFFER_BYTESDefault byte limit for the buffer, preserving the original "10 normal-sized pages" intent.
-
-
Constructor Details
-
AsyncExternalSourceBuffer
public AsyncExternalSourceBuffer(long maxBufferBytes)
-
-
Method Details
-
addPage
Add a page to the buffer. Called by the background reader thread. -
pollPage
Poll a page from the buffer. Called by the operator (driver thread).- Returns:
- the next page, or null if no pages available
-
waitForWriting
Returns anIsBlockedResultthat completes when the buffer has space for writing. Used by background reader for backpressure. -
waitForSpace
Returns aSubscribableListenerthat completes when the buffer has space for writing. This is the preferred method for producers to use for backpressure coordination.Unlike
waitForWriting()which returns anIsBlockedResult, this method returns aSubscribableListenerthat can be used directly with ES async patterns.- Returns:
- a listener that completes when space is available, or an already-completed listener if space exists
-
waitForReading
Returns anIsBlockedResultthat completes when the buffer has data for reading. Used by operator to signal driver when waiting for data. -
finish
public void finish(boolean drainingPages) Mark the buffer as finished. Called when reading is done or an error occurs. -
onFailure
Mark the buffer as failed. Called when the background reader encounters an error. -
isFinished
public boolean isFinished() -
noMoreInputs
public boolean noMoreInputs() -
size
public int size() -
addCompletionListener
Adds a listener that will be notified when this buffer is finished. -
failure
-
bytesInBuffer
public long bytesInBuffer()Returns the current number of bytes buffered, as measured byPage.ramBytesUsedByBlocks().
-