-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Track Engine sync code execution #3876
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a224614
adding a counter to ExecutionContext that tracks if the engine is run…
andimarek 18fa1fa
Update src/main/java/graphql/execution/SubscriptionExecutionStrategy.…
bbakerman 7d5308a
use util method
andimarek 75fe340
fix exception handling,
andimarek a2e42f3
Added tests for EC is running
bbakerman 82c4ef3
add an observer for the running state
andimarek 339f657
increase accuracy of engine running
andimarek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/graphql/execution/EngineRunningObserver.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package graphql.execution; | ||
|
|
||
| import graphql.ExperimentalApi; | ||
| import graphql.GraphQLContext; | ||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| @ExperimentalApi | ||
| @NullMarked | ||
| public interface EngineRunningObserver { | ||
|
|
||
|
|
||
| String ENGINE_RUNNING_OBSERVER_KEY = "__ENGINE_RUNNING_OBSERVER"; | ||
|
|
||
| void runningStateChanged(ExecutionId executionId, GraphQLContext graphQLContext, boolean runningState); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,12 +22,15 @@ | |
| import graphql.util.FpKit; | ||
| import graphql.util.LockKit; | ||
| import org.dataloader.DataLoaderRegistry; | ||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Locale; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
| import java.util.function.Consumer; | ||
| import java.util.function.Supplier; | ||
|
|
@@ -63,10 +66,13 @@ public class ExecutionContext { | |
| private final Supplier<ExecutableNormalizedOperation> queryTree; | ||
| private final boolean propagateErrorsOnNonNullContractFailure; | ||
|
|
||
| private final AtomicInteger isRunning = new AtomicInteger(0); | ||
|
|
||
| // this is modified after creation so it needs to be volatile to ensure visibility across Threads | ||
| private volatile DataLoaderDispatchStrategy dataLoaderDispatcherStrategy = DataLoaderDispatchStrategy.NO_OP; | ||
|
|
||
| private final ResultNodesInfo resultNodesInfo = new ResultNodesInfo(); | ||
| private final EngineRunningObserver engineRunningObserver; | ||
|
|
||
| ExecutionContext(ExecutionContextBuilder builder) { | ||
| this.graphQLSchema = builder.graphQLSchema; | ||
|
|
@@ -93,6 +99,7 @@ public class ExecutionContext { | |
| this.dataLoaderDispatcherStrategy = builder.dataLoaderDispatcherStrategy; | ||
| this.queryTree = FpKit.interThreadMemoize(() -> ExecutableNormalizedOperationFactory.createExecutableNormalizedOperation(graphQLSchema, operationDefinition, fragmentsByName, coercedVariables)); | ||
| this.propagateErrorsOnNonNullContractFailure = builder.propagateErrorsOnNonNullContractFailure; | ||
| this.engineRunningObserver = builder.engineRunningObserver; | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -141,7 +148,9 @@ public Supplier<NormalizedVariables> getNormalizedVariables() { | |
|
|
||
| /** | ||
| * @param <T> for two | ||
| * | ||
| * @return the legacy context | ||
| * | ||
| * @deprecated use {@link #getGraphQLContext()} instead | ||
| */ | ||
| @Deprecated(since = "2021-07-05") | ||
|
|
@@ -184,6 +193,7 @@ public ValueUnboxer getValueUnboxer() { | |
| * @return true if the current operation should propagate errors in non-null positions | ||
| * Propagating errors is the default. Error aware clients may opt in returning null in non-null positions | ||
| * by using the `@experimental_disableErrorPropagation` directive. | ||
| * | ||
| * @see graphql.Directives#setExperimentalDisableErrorPropagationEnabled(boolean) to change the JVM wide default | ||
| */ | ||
| @ExperimentalApi | ||
|
|
@@ -338,6 +348,7 @@ public DataLoaderDispatchStrategy getDataLoaderDispatcherStrategy() { | |
| * the current values and allows you to transform it how you want. | ||
| * | ||
| * @param builderConsumer the consumer code that will be given a builder to transform | ||
| * | ||
| * @return a new ExecutionContext object based on calling build on that builder | ||
| */ | ||
| public ExecutionContext transform(Consumer<ExecutionContextBuilder> builderConsumer) { | ||
|
|
@@ -349,4 +360,59 @@ public ExecutionContext transform(Consumer<ExecutionContextBuilder> builderConsu | |
| public ResultNodesInfo getResultNodesInfo() { | ||
| return resultNodesInfo; | ||
| } | ||
|
|
||
| @Nullable | ||
| EngineRunningObserver getEngineRunningObserver() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return engineRunningObserver; | ||
| } | ||
|
|
||
| @Internal | ||
| public boolean isRunning() { | ||
| return isRunning.get() > 0; | ||
| } | ||
|
|
||
| public void incrementRunning() { | ||
| if (isRunning.incrementAndGet() == 1 && engineRunningObserver != null) { | ||
| engineRunningObserver.runningStateChanged(executionId, graphQLContext, true); | ||
| } | ||
| } | ||
|
|
||
| public void decrementRunning() { | ||
| if (isRunning.decrementAndGet() == 0 && engineRunningObserver != null) { | ||
| engineRunningObserver.runningStateChanged(executionId, graphQLContext, false); | ||
| } | ||
| } | ||
bbakerman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public void incrementRunning(CompletableFuture<?> cf) { | ||
| cf.whenComplete((result, throwable) -> { | ||
| incrementRunning(); | ||
| }); | ||
| } | ||
|
|
||
| public void decrementRunning(CompletableFuture<?> cf) { | ||
| cf.whenComplete((result, throwable) -> { | ||
| decrementRunning(); | ||
| }); | ||
|
|
||
| } | ||
|
|
||
| public <T> T call(Supplier<T> callable) { | ||
| incrementRunning(); | ||
| try { | ||
| return callable.get(); | ||
| } finally { | ||
| decrementRunning(); | ||
| } | ||
| } | ||
|
|
||
| public void run(Runnable runnable) { | ||
| incrementRunning(); | ||
| try { | ||
| runnable.run(); | ||
| } finally { | ||
| decrementRunning(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
executionContext.finished() before the Async.eachSequentially ?