java.lang.Object
org.elasticsearch.compute.operator.DriverContext
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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA snapshot of the driver context.static enumIndicates the behavior Evaluators of this context should use for reporting warnings -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanaddReleasable(org.elasticsearch.core.Releasable releasable) Adds a releasable to this context.breaker()TheCircuitBreakerto use to track memory.voidChecks if the Driver associated with this DriverContext has been cancelled or early terminated.voidfinish()Finishes this context.static DriverContextRetrieves the snapshot of the driver context after it has been finished.voidInitializes the early termination or cancellation checker for this DriverContext.booleanTells whether this context is finished.voidbooleanremoveReleasable(org.elasticsearch.core.Releasable releasable) Removes a releasable from this context.voidwaitForAsyncActions(ActionListener<Void> listener) Evaluators should use this function to decide their warning behavior.
-
Constructor Details
-
DriverContext
-
-
Method Details
-
getLocalDriver
-
bigArrays
-
breaker
TheCircuitBreakerto use to track memory. -
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
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
-
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
Initializes the early termination or cancellation checker for this DriverContext. This method should be called when associating this DriverContext with a driver. -
warningsMode
Evaluators should use this function to decide their warning behavior.- Returns:
- an appropriate
DriverContext.WarningsMode
-