Module org.elasticsearch.compute
Class BatchSortedExchangeSource
java.lang.Object
org.elasticsearch.compute.operator.exchange.BatchSortedExchangeSource
- All Implemented Interfaces:
Closeable,AutoCloseable,ExchangeSource
Wraps an
ExchangeSource and reorders BatchPages within each batch
to ensure they are output in sequential order based on pageIndexInBatch.
Pages may arrive out of order (e.g., due to network ordering), but consumers expect pages within a batch to arrive in order (pageIndexInBatch = 0, 1, 2, ...). This class buffers out-of-order pages and releases them in the correct sequence.
Implements ExchangeSource so it can be used polymorphically wherever an ExchangeSource is expected.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of pages waiting in the output queue.voidclose()voidfinish()Finish the underlying source.booleanReturns true if there are pages ready to be output (in correct order).booleanReturns true if all pages have been consumed.pollPage()Poll the next page in sorted order.toString()Returns anIsBlockedResultthat resolves when a page is available.Blocks until a page is ready in outputQueue OR delegate is finished.
-
Constructor Details
-
BatchSortedExchangeSource
-
-
Method Details
-
pollPage
Poll the next page in sorted order.If there are pages ready in the output queue, returns one immediately. Otherwise, polls from the delegate and sorts incoming pages.
- Specified by:
pollPagein interfaceExchangeSource- Returns:
- the next page in order, or null if no pages are available
-
waitForReading
Returns anIsBlockedResultthat resolves when a page is available.This method eagerly polls and sorts pages from the delegate until either:
- An in-order page is available in the output queue
- The delegate is blocked (returns the delegate's future)
- The delegate is finished
- Specified by:
waitForReadingin interfaceExchangeSource- Returns:
- NOT_BLOCKED if a page is available or delegate is finished, otherwise a blocked result
-
waitUntilReady
Blocks until a page is ready in outputQueue OR delegate is finished. UnlikewaitForReading(), this guaranteeshasReadyPages()== true when returning NOT_BLOCKED (unless delegate is finished with no more pages).This prevents busy-spinning when pages arrive out of order.
- Returns:
- NOT_BLOCKED if a page is ready or delegate is finished, otherwise a blocked result
-
hasReadyPages
public boolean hasReadyPages()Returns true if there are pages ready to be output (in correct order). This only counts pages in the output queue, not out-of-order pages buffered internally or pages in the delegate's buffer. -
isFinished
public boolean isFinished()Returns true if all pages have been consumed.- Specified by:
isFinishedin interfaceExchangeSource
-
bufferSize
public int bufferSize()Returns the number of pages waiting in the output queue.- Specified by:
bufferSizein interfaceExchangeSource
-
finish
public void finish()Finish the underlying source.- Specified by:
finishin interfaceExchangeSource
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
toString
-