Class DriverContext

java.lang.Object
org.elasticsearch.compute.operator.DriverContext

public class DriverContext extends Object
A driver-local context that is shared across operators. Operators in the same driver pipeline are executed in a single threaded fashion. A driver context has a set of mutating methods that can be used to store and share values across these operators, or even outside the Driver. When the Driver is finished, it finishes the context. Finishing the context effectively takes a snapshot of the driver context values so that they can be exposed outside the Driver. The net result of this is that the driver context can be mutated freely, without contention, by the thread executing the pipeline of operators until it is finished. The context must be finished by the thread running the Driver, when the Driver is finished. Releasables can be added and removed to the context by operators in the same driver pipeline. This allows to "transfer ownership" of a shared resource across operators (and even across Drivers), while ensuring that the resource can be correctly released when no longer needed. DriverContext can also be used to track async actions. The driver may close an operator while some of its async actions are still running. To prevent the driver from finishing in this case, methods addAsyncAction() and removeAsyncAction() are provided for tracking such actions. Subsequently, the driver uses waitForAsyncActions(ActionListener) to await the completion of all async actions before finalizing the Driver.
  • Constructor Details

  • Method Details

    • getLocalDriver

      public static DriverContext getLocalDriver()
    • bigArrays

      public BigArrays bigArrays()
    • breaker

      public CircuitBreaker breaker()
      The CircuitBreaker to use to track memory.
    • blockFactory

      public BlockFactory blockFactory()
    • addReleasable

      public boolean addReleasable(org.elasticsearch.core.Releasable releasable)
      Adds a releasable to this context. Releasables are identified by Object identity.
      Returns:
      true if the releasable was added, otherwise false (if already present)
    • removeReleasable

      public boolean removeReleasable(org.elasticsearch.core.Releasable releasable)
      Removes a releasable from this context. Releasables are identified by Object identity.
      Returns:
      true if the releasable was removed, otherwise false (if not present)
    • getSnapshot

      public DriverContext.Snapshot getSnapshot()
      Retrieves the snapshot of the driver context after it has been finished.
      Returns:
      the snapshot
    • isFinished

      public boolean isFinished()
      Tells whether this context is finished. Can be invoked from any thread.
    • finish

      public void finish()
      Finishes this context. Further mutating operations should not be performed.
    • waitForAsyncActions

      public void waitForAsyncActions(ActionListener<Void> listener)
    • addAsyncAction

      public void addAsyncAction()
    • removeAsyncAction

      public void removeAsyncAction()
    • checkForEarlyTermination

      public void checkForEarlyTermination()
      Checks if the Driver associated with this DriverContext has been cancelled or early terminated.
    • initializeEarlyTerminationChecker

      public void initializeEarlyTerminationChecker(Runnable checker)
      Initializes the early termination or cancellation checker for this DriverContext. This method should be called when associating this DriverContext with a driver.
    • warningsMode

      public DriverContext.WarningsMode warningsMode()
      Evaluators should use this function to decide their warning behavior.
      Returns:
      an appropriate DriverContext.WarningsMode