GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Allow scheduling of CF completion - Attempt 1 by bbakerman · Pull Request #275 · graphql-java/java-dataloader Conversation
|
| private CompletableFuture<List<V>> dispatchQueueBatch(List<K> keys, List<Object> keyContexts, List<CompletableFuture<V>> queuedFutures) { | ||
| stats.incrementBatchLoadCountBy(keys.size(), new IncrementBatchLoadCountByStatisticsContext<>(keys, keyContexts)); | ||
|
|
||
| BatchLoaderEnvironment environment = mkBatchLoaderEnv(keys, keyContexts); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We now create the BatchLoaderEnvironment earlier and send it down into the other methods earlier
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Try<V> tryValue = (Try<V>) value; | ||
| if (tryValue.isSuccess()) { | ||
| future.complete(tryValue.get()); | ||
| } else { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The above is now run in the runnable and hence can be scheduled onto some other thread
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This moved the CF completions to another thread but the for loop still invokes them sequentially which is a problem if there are many keys in the batch. Could we schedule the completion for each key in a separate thread instead?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
So are you saying we pass in
public CompleableFuture<Void> completeThese(List<CompletableFuture> cfs, List<Object> values)
And the the caller could sequentially run them as today OR choose to run them in parralel themselves say?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if (value instanceof Throwable) { | ||
| stats.incrementLoadErrorCount(new IncrementLoadErrorCountStatisticsContext<>(key, callContext)); | ||
| future.completeExceptionally(tryValue.getThrowable()); | ||
| future.completeExceptionally((Throwable) value); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
diff is whacky. This has not changed
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Object context = loaderOptions.getBatchLoaderContextProvider().getContext(); | ||
| return BatchLoaderEnvironment.newBatchLoaderEnvironment() | ||
| .context(context).keyContexts(keys, keyContexts).build(); | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Called in two places - common method
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| import static org.hamcrest.Matchers.instanceOf; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| class CompletableFutureKitTest { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
never had tests
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return future; | ||
| } | ||
|
|
||
| public static <V> CompletableFuture<V> success(V v) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Isn't this the same as CompletableFuture.completedFuture(v)?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yes - but here for "completeness" ;)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Try<V> tryValue = (Try<V>) value; | ||
| if (tryValue.isSuccess()) { | ||
| future.complete(tryValue.get()); | ||
| } else { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This moved the CF completions to another thread but the for loop still invokes them sequentially which is a problem if there are many keys in the batch. Could we schedule the completion for each key in a separate thread instead?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.