-
Notifications
You must be signed in to change notification settings - Fork 110
FlatMapPipelinedCursor
starts background calculations of pipelined inner cursors
#3072
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -267,6 +267,7 @@ private synchronized void addEntryToPipeline(PipelineQueueEntry pipelineQueueEnt | |
if (closed) { | ||
pipelineQueueEntry.close(); | ||
} | ||
pipelineQueueEntry.getNextInnerPipelineFuture(); | ||
pipeline.add(pipelineQueueEntry); | ||
} | ||
|
||
|
@@ -295,20 +296,26 @@ public PipelineQueueEntry(RecordCursor<V> innerCursor, | |
this.priorOuterContinuation = priorOuterContinuation; | ||
this.outerResult = outerResult; | ||
this.outerCheckValue = outerCheckValue; | ||
// start calculating the next result in the background. | ||
setInnerFuture(); | ||
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. As a matter of style, I think it would be better not to fire off this future in the constructor. There are some security implications in general if this can throw an error (see: https://www.baeldung.com/java-constructors-exceptions, see "Security concerns"), but also, it's counter-intuitive for users of the API, who don't expect constructing an object to have side-effects like this. If we really want to always fire off this future when we make a new element, I think we should make a static initializer, which removes the security concern and is less likely to surprise API consumers (which, granted, is just us because this is a private class) |
||
} | ||
|
||
@Nonnull | ||
public CompletableFuture<PipelineQueueEntry> getNextInnerPipelineFuture() { | ||
if (innerFuture == null) { | ||
if (innerCursor == null) { | ||
innerFuture = CompletableFuture.completedFuture(RecordCursorResult.exhausted()); | ||
} else { | ||
innerFuture = innerCursor.onNext(); | ||
} | ||
setInnerFuture(); | ||
} | ||
return innerFuture.thenApply(vignore -> this); | ||
} | ||
|
||
private void setInnerFuture() { | ||
if (innerCursor == null) { | ||
innerFuture = CompletableFuture.completedFuture(RecordCursorResult.exhausted()); | ||
} else { | ||
innerFuture = innerCursor.onNext(); | ||
} | ||
} | ||
|
||
public boolean doesNotHaveReturnableResult() { | ||
if (innerCursor == null || // Hit sentinel, so we have a returnable result | ||
innerFuture == null || // Inner future hasn't been started yet. | ||
|
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.
Do we need both this change and the change in the
PipelineQueueEntry
constructor? If I'm reasoning about this correctly, it seems like we only need one of the two (that this is extraneous if the next future is fired off during the constructor, and the constructor call is extraneous if the future is created here)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.
Correct, this was an oversight, let me remove that.