Skip to content

Commit 1282d43

Browse files
committed
review(pr69): address P1/P2 feedback — stale-link, clock-skew, refresh cursors, coverage
Addresses seven review items on PR #69 (batched link refresh on presigned-URL expiry): ### P1 — Important 1. **In-flight Downloading task uses stale-link snapshot.** The download loop cloned `entry.link` into a local before `downloader.download(&link).await`. If a concurrent `refresh_links_batch` wrote a fresh URL during the .await, the suspended download continued against the stale URL and burned a retry attempt on the failure. Fix: after a failed download, compare the cached link's URL to the URL we tried. If different (refresh ran concurrently), don't count that attempt against the retry budget — loop immediately and pick up the fresh URL on the next iteration. 2. **Proactive `is_expired()` check spins under client clock skew.** If the client clock is N seconds ahead, every freshly- issued URL appears expired. Both the proactive check and the dedupe re-check see "still expired" → RPC per schedule_downloads iteration, bounded only by RTT. Fix: after a successful refresh, if the link for the requested start_chunk_index is *still* `is_expired()` per the local clock, surface a hard error rather than loop. The error message calls out client/server clock skew as the likely cause, making the failure mode debuggable. 3. **`refetch_links_from` did not update link-fetcher continuation cursors.** Unlike `fetch_links`, the refresh path inserted into the cache but didn't touch `next_server_fetch_index` / `next_row_offset` / `all_links_fetched`. A refresh response carrying `next_chunk_index = None` (PR #68's end-of-stream sentinel) was silently dropped — the prefetch loop would keep firing past the end of the result set. Fix: mirror the cursor-update block from `fetch_links`. Use `fetch_max` so an early-window refresh doesn't rewind progress. Also runs `decode_continuation` to honour the PR #68 transition-period total_chunk_count guard. ### P2 — Minor 4. **Misleading "still missing" error message.** The error only fired when `entry.link == None`. The stale-link case (server returned a batch not including chunk_index) hit `Some(stale)` and silently burned retries. The new check in `refresh_links_batch` (P1 #2 fix) catches both cases; the download-task message is upgraded to mention clock-skew as the alternative root cause. 5. **`refresh_batch_dedups_concurrent_calls` ran on single-threaded runtime.** Switched to `#[tokio::test(flavor = "multi_thread", worker_threads = 2)]` so the TokioMutex dedupe path is exercised under genuine contention. 6. **Test coverage gaps** — added five new tests for previously uncovered paths: - `refresh_batch_preserves_cancelled_and_released_states` — terminal arms. - `refresh_batch_inserts_new_chunk_for_window_expansion` — the `else` branch that materialises previously-unseen chunks. - `refresh_batch_errors_when_server_truncates_window` — guard against the server returning a batch missing the requested chunk_index. - `refresh_batch_propagates_rpc_error` — RPC-failure path. - `refresh_batch_errors_on_stale_after_refresh_clock_skew` — P1 #2 regression guard. 7. **`refresh_links_batch` not cancellation-aware** — documented the behaviour: RPC runs to completion even if `cancel_token` fires; acceptable in practice (SEA RPCs are short and on the cancellation path no consumer is waiting); revisit if a long-RPC transport lands. ### Tests 10 refresh-batch tests pass (5 pre-existing + 5 new). Clippy clean. Stacked on PR #68's force-pushed tip (`bee7c1f`), so this PR is rebased and the merge order is now PR #68 → PR #69 cleanly. Co-authored-by: Isaac Signed-off-by: Gopal Lal <gopal.lal@databricks.com>
1 parent 4c1395c commit 1282d43

2 files changed

Lines changed: 397 additions & 4 deletions

File tree

‎src/reader/cloudfetch/link_fetcher.rs‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,36 @@ impl ChunkLinkFetcher for SeaChunkLinkFetcherHandle {
826826
self.inner.links.insert(link.chunk_index, link.clone());
827827
}
828828

829+
// Mirror the continuation cursor updates from `fetch_links`:
830+
// a refresh response is a normal `get_result_chunks`
831+
// response, just used for the expiry-recovery path. If we
832+
// drop its continuation metadata on the floor (as the
833+
// initial implementation did), the prefetch loop happily
834+
// keeps firing past the actual end of the result set when a
835+
// refresh response carries `next_chunk_index = None`. Use
836+
// `fetch_max` so an early-window refresh (start_chunk_index
837+
// < current cursor) doesn't rewind progress.
838+
if let Some(last_link) = result.links.last() {
839+
let next_row_offset = last_link.row_offset.saturating_add(last_link.row_count);
840+
self.inner
841+
.next_row_offset
842+
.fetch_max(next_row_offset, Ordering::Release);
843+
let cont = decode_continuation(last_link, self.inner.total_chunk_count_hint);
844+
if cont.used_total_chunk_count_fallback {
845+
self.inner.warn_total_chunk_count_fallback("link refresh");
846+
}
847+
if cont.eos {
848+
self.inner.all_links_fetched.store(true, Ordering::Release);
849+
} else {
850+
let advance_to = cont
851+
.next_fetch_index
852+
.max(last_link.chunk_index.saturating_add(1));
853+
self.inner
854+
.next_server_fetch_index
855+
.fetch_max(advance_to, Ordering::Release);
856+
}
857+
}
858+
829859
Ok(result.links)
830860
}
831861
}

0 commit comments

Comments
 (0)