Class ExchangeSourceHandler

java.lang.Object
org.elasticsearch.compute.operator.exchange.ExchangeSourceHandler

public final class ExchangeSourceHandler extends Object
An ExchangeSourceHandler asynchronously fetches pages and status from multiple RemoteSinks and feeds them to its ExchangeSource, which are created using the createExchangeSource()) method. RemoteSinks are added using the addRemoteSink(RemoteSink, boolean, Runnable, int, ActionListener)) method.
See Also:
  • Constructor Details

    • ExchangeSourceHandler

      public ExchangeSourceHandler(int maxBufferSize, Executor fetchExecutor)
      Creates a new ExchangeSourceHandler.
      Parameters:
      maxBufferSize - the maximum size of the exchange buffer. A larger buffer reduces ``pauses`` but uses more memory, which could otherwise be allocated for other purposes.
      fetchExecutor - the executor used to fetch pages.
  • Method Details

    • isFinished

      public boolean isFinished()
    • createExchangeSource

      public ExchangeSource createExchangeSource()
      Create a new ExchangeSource for exchanging data
      See Also:
    • addRemoteSink

      public void addRemoteSink(RemoteSink remoteSink, boolean failFast, Runnable onPageFetched, int instances, ActionListener<Void> listener)
      Add a remote sink as a new data source of this handler. The handler will start fetching data from this remote sink intermediately.
      Parameters:
      remoteSink - the remote sink
      failFast - determines how failures in this remote sink are handled: - If false, failures from this remote sink will not cause the exchange source to abort. Callers must handle these failures notified via listener. - If true, failures from this remote sink will cause the exchange source to abort.
      onPageFetched - a callback that will be called when a page is fetched from the remote sink
      instances - the number of concurrent ``clients`` that this handler should use to fetch pages. More clients reduce latency, but add overhead.
      listener - a listener that will be notified when the sink fails or completes. Callers must handle failures notified via this listener.
      See Also:
    • addEmptySink

      public org.elasticsearch.core.Releasable addEmptySink()
      Links this exchange source with an empty/dummy remote sink. The purpose of this is to prevent this exchange source from finishing until we have performed other async actions, such as linking actual remote sinks.
      Returns:
      a Releasable that should be called when the caller no longer needs to prevent the exchange source from completing.
    • finishEarly

      public void finishEarly(boolean drainingPages, ActionListener<Void> listener)
      Gracefully terminates the exchange source early by instructing all remote exchange sinks to stop their computations. This can happen when the exchange source has accumulated enough data (e.g., reaching the LIMIT) or when users want to see the current result immediately.
      Parameters:
      drainingPages - whether to discard pages already fetched in the exchange