Repository navigation
feat: add async cursor prefetch mechanism - #20897
Conversation
| @SuppressWarnings("unused") | ||
| ListenableFuture<?> unused = gatedExec.submit(() -> { | ||
| try { | ||
| gate.await(); | ||
| } | ||
| catch (InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| } | ||
| }); |
FrankChen021
left a comment
There was a problem hiding this comment.
🟢 Approval recommended
No actionable issues found in this review. The prefetch lifecycle and shared async cursor machinery preserve bundle ownership across success, failure, and cancellation, while wrapper factories pass the same transformed specifications used by async cursor construction.
Reviewed 18 of 18 changed files.
This is an automated review by Codex GPT-5.6-Luna(max)
capistrant
left a comment
There was a problem hiding this comment.
mostly have suggested some minor javadoc tweaks (non-blocking opinions) plus some general questions about the contract of CursorPrefetch. Biggest potentially blocking concern has an inline comment in the partial cursor factory prefetch method on handling of some synchronous failures and whether it breaks the stated prefetch contract. Overall tho, seems cool
| /** | ||
| * The spec passed to the delegate: the caller's spec with {@link #policy} applied. Used by every delegating method | ||
| * here. | ||
| */ |
There was a problem hiding this comment.
nit suggestion
| /** | |
| * The spec passed to the delegate: the caller's spec with {@link #policy} applied. Used by every delegating method | |
| * here. | |
| */ | |
| /** | |
| * The caller's spec with {@link #policy} applied. | |
| */ |
There was a problem hiding this comment.
this wasn't adding much so just removed
| /** | ||
| * The spec passed to the base cursor factory: the caller's spec rewritten for the unnest input column, with only | ||
| * the base-table half of its filters (see {@link #computeFilterSplit}). Shared by every holder path, which also need | ||
| * {@code filterSplit} for the post-unnest half. | ||
| */ |
There was a problem hiding this comment.
nit suggestion
| /** | |
| * The spec passed to the base cursor factory: the caller's spec rewritten for the unnest input column, with only | |
| * the base-table half of its filters (see {@link #computeFilterSplit}). Shared by every holder path, which also need | |
| * {@code filterSplit} for the post-unnest half. | |
| */ | |
| /** | |
| * The spec passed to the base cursor factory: the caller's spec rewritten for the unnest input column, with only | |
| * the base-table half of its filters (see {@link #computeFilterSplit}). | |
| */ |
There was a problem hiding this comment.
just removed this since this one is also just delegating to another method
| /** | ||
| * The spec passed to the base cursor factory for {@code spec}, computing the filter split itself. | ||
| */ |
There was a problem hiding this comment.
nit: I'd remove this as it feels self explanatory if the reader just looks at the called delegateSpec
| /** | ||
| * The spec passed to the base cursor factory for {@code spec}; see {@link #planCursor}. | ||
| */ |
There was a problem hiding this comment.
nit: I'd consider dropping this as unneeded
| * <b>Prefetch.</b> {@link #prefetch} shares the async path's machinery but, instead of a cursor holder, produces a | ||
| * {@link CursorPrefetch} that owns the bundle holds. A later {@link #makeCursorHolderAsync} for the same spec (made | ||
| * while the prefetch is still open) plans no downloads as everything is resident. |
There was a problem hiding this comment.
What is the intended contract around starting a cursor holder build when a prefetch is not done, if any? If such a thing does happen, wouldn't the holder build plan downloads for whatever is not pre-fetched yet? I suppose it wouldn't actually be downloaded because it would realize it is resident thanks to prefetch before kicking off its own download.
There was a problem hiding this comment.
prefetch isn't required, the callers that use partial loads still must use CursorFactory#makeCursorHolderAsync so any part not present will just load on demand as part of that contract. Prefetch just makes all of the things resident in advance so that the later async step can be immediate.
| if (plan.bundles().isEmpty()) { | ||
| return CursorPrefetch.none(); | ||
| } | ||
| final PendingDownloads pending = acquireHoldsAndSubmitRuns(plan.bundles()); |
There was a problem hiding this comment.
this can throw synchronously, correct? Does it doing so violate the best effort contract of CursorPrefetch that states:
<li>The handle is ready ({@link #isReady()}) once the warm-up is complete, whether it succeeded or failed;
* {@link #get()} returns {@link Stats} on success and throws the failure otherwise.</li>
Might we want to try/catch here and create a failed prefetch?
The planCurstorPrefetch above also could fail to plan. that seems potentially different in that it may be un-recoverable at cursor build time if it can't even plan now. so maybe it throwing eagerly is ok as long as it is handled nicely?
There was a problem hiding this comment.
This didn't really matter much with how the branch i had on top of this was wiring it up, but i went ahead and changed it to be more consistent
| * <li>Keep the handle open for as long as the warmed-up parts should stay resident. Closing it after it is ready | ||
| * releases the holds that pin them. The cursor build that benefits from the warm-up takes its own pins on the | ||
| * calling thread, so close the handle only once that {@code makeCursorHolderAsync} call has returned, or the parts | ||
| * may be evicted in between and loaded twice.</li> |
There was a problem hiding this comment.
are callers going to be fully responsible for responsible use of Prefetch handles, then? No real objection here, other than it just feels like an area to keep close eye on when creating followups that use this prefetch mechanism
There was a problem hiding this comment.
yea, it is optional, but callers using it will need to close the handles to release the holds (since we do holds on the prefetch so that other prefetch don't evict what we just loaded if space is tight, the backoff from #20904 is also important to make stuff chill once the things in this patch are wired up)
| Assertions.assertTrue(base.prefetchCanceled.get(), "closing the prefetch before it's ready cancels the base"); | ||
| } | ||
| catch (Throwable t) { | ||
| prefetch.close(); |
There was a problem hiding this comment.
nit: if the final assertion fails this will clobber the assertion fail reason with an Already Closed exception
FrankChen021
left a comment
There was a problem hiding this comment.
🟡 Changes recommended
Fix failed-prefetch cleanup before merging. Failed range loads and partial setup failures can leave already-submitted deep-storage tasks running after the cursor or prefetch has failed, consuming loader capacity unnecessarily.
Reviewed 18 of 18 changed files; findings in 1 file.
Validation: git diff --check c7913041e5de0d7f9ea4b4ed19eaa127d75cfda1..5283291895807f6bc336c48320533b3683075347 passed.
| Severity | Findings |
|---|---|
| P0 | 0 |
| P1 | 0 |
| P2 | 2 |
| P3 | 0 |
| Total | 2 |
This is an automated review by Codex GPT-5.6-Luna(max)
After addressing the findings or replying to the comments, you can request another review from me to trigger a new automated review.
| private static void failHolder(List<BundleHoldRelease> holdReleases, AsyncCursorHolder asyncHolder, Throwable t) | ||
| private static void fail(List<BundleHoldRelease> holdReleases, SettableAsyncResource<?> target, Throwable t) | ||
| { | ||
| holdReleases.forEach(BundleHoldRelease::requestRelease); |
There was a problem hiding this comment.
[P2] Failed range load leaves sibling downloads running
Finding: When one range download fails, AsyncResources.collect marks the aggregate ready with the error but intentionally leaves sibling resources open. This failure path only requests hold release and completes the target; once the target is ready, its canceler is cleared, so closing the failed CursorPrefetch or AsyncCursorHolder cannot cancel sibling tasks. Already-running downloads can continue consuming deep-storage and loader capacity after the operation has failed.
Suggestion: Close or cancel the collected download resource in the shared failure path, and add a multi-run failure test that verifies sibling tasks are canceled.
There was a problem hiding this comment.
this isn't really new in this PR though moving the code around probably flagged it, but I fixed it anyway
There was a problem hiding this comment.
Verified at the current head: fail(PendingDownloads, ...) now calls PendingDownloads.unwind() before completing the target, and unwind() closes the collected download resource so sibling AsyncResources are canceled before the failed handle loses its canceler. The added multi-run failure coverage also checks sibling cancellation and exactly-once hold release. This follow-up is resolved.
| // submitDownload shutdown rejection). A run download submitted before the failure may already be in flight, so | ||
| // release every bundle hold through the handshake (requestRelease defers to the last in-flight body) rather | ||
| // than dropping it directly mid-mapFile(). | ||
| throw CloseableUtils.closeAndWrapInCatch(t, () -> holdReleases.forEach(BundleHoldRelease::requestRelease)); |
There was a problem hiding this comment.
[P2] Partial setup failure leaves submitted tasks uncanceled
Finding: If a later bundle acquisition or submitDownload call fails after earlier range tasks were submitted, the runDownloads list is scoped to the try block and discarded. The catch requests hold release only, while prefetch returns a ready failed handle with no canceler and the async cursor path throws, leaving no owner that can close the previously returned task resources.
Suggestion: Retain submitted run resources in the setup failure path and close them before releasing the acquired holds; cover partial-submission rejection in a test.
There was a problem hiding this comment.
also not new, but also fixed.
There was a problem hiding this comment.
Verified at the current head: runDownloads remains available in the setup catch path, and every submitted resource is closed before the acquired bundle holds are released. The added partial-submission rejection coverage checks both prefetch and async cursor setup. This follow-up is resolved.
FrankChen021
left a comment
There was a problem hiding this comment.
🟢 Approval recommended
No actionable issues remain at the reviewed head. Both prior P2s are resolved: failed downloads now cancel siblings, and partial setup failures cancel submitted tasks before releasing holds.
Reviewed 18 of 18 changed files. Current-head review is sufficient for normal recommendation rules; follow-up focus was the incremental cleanup change and its tests, reconciled with the full diff and surrounding async-resource lifecycle.
This is an automated review by Codex GPT-5.6-Luna(max)
Description
This PR adds
CursorFactory#prefetchwhich starts the loading that a latermakeCursorHolderAsync(spec)would otherwise do on demand for partial loading V10 segments. This is a building block for load-ahead prefetch in MSQ leaf stages (which will come in a follow-up).