Repository navigation
feat: add async cursor prefetch mechanism - #20897
clintropolis wants to merge 1 commit into
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. | |
| */ |
| /** | ||
| * 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}). | |
| */ |
| /** | ||
| * 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.
| 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?
| * <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
| 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
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).