java.lang.Object
org.elasticsearch.compute.operator.Driver
All Implemented Interfaces:
Closeable, AutoCloseable, Describable, Releasable
Direct Known Subclasses:
BatchDriver

public class Driver extends Object implements Releasable, Describable
A driver operates single-threadedly on a simple chain of Operators, passing Pages from one operator to the next. It also controls the lifecycle of the operators. The operator chain typically starts with a source operator (i.e. an operator that purely produces pages) and ends with a sink operator (i.e. an operator that purely consumes pages). More details on how this integrates with other components can be found in the package documentation of org.elasticsearch.compute
  • Field Details

    • DEFAULT_TIME_BEFORE_YIELDING

      public static final TimeValue DEFAULT_TIME_BEFORE_YIELDING
    • DEFAULT_MAX_ITERATIONS

      public static final int DEFAULT_MAX_ITERATIONS
      See Also:
    • DEFAULT_STATUS_INTERVAL

      public static final TimeValue DEFAULT_STATUS_INTERVAL
      Minimum time between updating status.
    • shortDescription

      protected final String shortDescription
      Description of the driver. This description should be short and meaningful as a grouping identifier. We use the phase of the query right now: "data", "node_reduce", "final".
    • activeOperators

      protected List<Operator> activeOperators
  • Constructor Details

    • Driver

      public Driver(String sessionId, String shortDescription, String clusterName, String nodeName, long startTime, long startNanos, DriverContext driverContext, Supplier<String> description, SourceOperator source, List<Operator> intermediateOperators, SinkOperator sink, TimeValue statusInterval, Releasable releasable)
      Creates a new driver with a chain of operators.
      Parameters:
      sessionId - session Id
      shortDescription - Description of the driver. This description should be short and meaningful as a grouping identifier. We use the phase of the query right now: "data", "node_reduce", "final".
      driverContext - the driver context
      source - source operator
      intermediateOperators - the chain of operators to execute
      sink - sink operator
      statusInterval - minimum status reporting interval
      releasable - a Releasable to invoked once the chain of operators has run to completion
  • Method Details

    • driverContext

      public DriverContext driverContext()
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Releasable
    • abort

      public void abort(Exception reason, ActionListener<Void> listener)
      Abort the driver and wait for it to finish
    • onNoPagesMoved

      protected void onNoPagesMoved()
      Called when no pages were moved in a loop iteration. Subclasses can override this to detect when the driver is idle/empty.
    • closeEarlyFinishedOperators

      protected int closeEarlyFinishedOperators(ListIterator<Operator> operators, LongSupplier currentTimeNanosSupplier, long lastStatusUpdate)
    • finishAllActiveOperators

      protected void finishAllActiveOperators()
      Finish all active operators. This is used before throwing DriverEarlyTerminationException to ensure all operators are properly finished and can be closed.
    • cancel

      public void cancel(String reason)
    • start

      public static void start(ThreadContext threadContext, Executor executor, Driver driver, int maxIterations, ActionListener<Void> listener)
    • finishEarly

      public boolean finishEarly()
      Requests that this driver wind down at its next iteration by treating the operator chain as if its sink had closed. Existing callers wire this to ExchangeSinkOperator completion, so we keep its semantics narrow — the early-termination checker throws DriverEarlyTerminationException and operator teardown discards anything that has not already crossed the sink. Source operators that want STOP to drain in-flight pages rather than drop them should register a stop hook instead.
    • runStopHooks

      public boolean runStopHooks()
      Fires any non-destructive stop hooks operators registered on this driver's DriverContext. Operators use this to interrupt their input side (e.g. close a buffer's producer) while leaving already-buffered pages reachable to the driver loop, so the response contains every row the source had already produced when STOP arrived. Returns true when at least one hook reported it cut a still-running unit of work, which the async stop action uses as an honest signal to flag is_partial=true.
    • drainAndCloseOperators

      protected void drainAndCloseOperators(@Nullable Exception e)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • describe

      public String describe()
      Description copied from interface: Describable
      Returns a description of the component. This description can be more specific than Object::toString.
      Specified by:
      describe in interface Describable
      Returns:
      the description
    • sessionId

      public String sessionId()
    • status

      public DriverStatus status()
      Get the last status update from the driver. These updates are made when the driver is queued and after every processing batch.
    • profile

      public DriverProfile profile()
      Build a "profile" of this driver's operations after it's been completed. This doesn't make sense to call before the driver is done.