Skip to content

Live PAR takes articles finishing during a cache flush from RAM, not from disk; par-rs 2524277 - #740

Draft
xbmc4lyfe wants to merge 1 commit into
mainfrom
live-par-handover
Draft

xbmc4lyfe wants to merge 1 commit into
mainfrom
live-par-handover

Conversation

@xbmc4lyfe

Copy link
Copy Markdown
Collaborator

Why live PAR still read articles back

After #729, a 3.3 GB set on 6790 still had par-rs read 437 articles (335.8 MB) back from disk: "437 article(s) read from their file by par-rs, 0 waited for the cache flush, 0 handed over with the bytes written". prybar's 4 GiB audit saw 0.2-0.3x of every set read back, clean sets included.

Cause: at line speed the article cache flushes the file being downloaded almost all the time (DirectWrite keeps at most a 32 MB burst, and extraction-order download puts every connection on one or two files). The live PAR snapshot of a cached article (qfile.rs cache sub-op 1) refused to copy while its file was flush-locked. So every article that finished while its file was being flushed was "taken as written", and par-rs read it back once its slice completed. Its later write then kept a copy that no capture ever took, charged to ParBuffer until the file completed.

It was not the par2 index arriving late (the 6790 session started with the job, 0 bytes kept before the session) and not DirectWrite skipping the hook.

Change

  • Snapshot during a flush (qfile.rs). The copy is allowed while the flush lock is set. The two frees that could race with it now run under the cache content lock the snapshot holds: the flush discard (sub-op 6) and file completion (output op 9/5). The 9/5 free was already an unlocked race with snapshots before this PR. The other frees (ClearArticles, reset, file free) run under the daemon queue lock, which both capture sites hold.
  • File completion hands bytes over (articledl.rs, streaming_session_articles_completed). A data file's cached articles written at completion are kept for captures still to come, as a flush does. They are not marked readable, because the write may still be buffered. Completion also skips the back-fill hold, which it keeps itself.
  • No stale copies. A capture taken as written marks the article, so a later write of it keeps nothing.
  • Bounded pre-session buffer, logged. Bytes kept before the session past the 64 MB cap are logged once per job; par-rs reads those back.
  • New I/O counter: "N copied from the cache during a flush (all jobs)".
  • par-rs b60bfd1 -> 2524277 (par-rs Port DirectUnpack, Cleanup, UnpackController, UrlCoordinator, FeedCoordinator, and RemoteServer hot paths to Rust #145, at the coordinator's request). A slice read before its article reaches the file waits instead of counting as damaged. Its three requirements already hold:
    • The crc32 passed is the article's calculated CRC. With CrcCheck=no it is the yEnc header CRC, so a corrupt article's slice waits and is then rebuilt.
    • Staged slices are completed after each flush: staged_due triggers complete_staged_slices on the next drain.
    • Every session has at least 1 preallocated slot and a recovery plan.
    • The boundary test a_committed_range_reported_before_its_write_waits_for_it now expects the wait, then the verify after the write.
  • Test hook RUSTYGET_TEST_FLUSH_HOLD_MS (logged when set; costs one load when unset) and the scenario liveparflushrace: 1 MB cache, 16 connections, 150 ms flush hold. It asserts source_bytes_read 0, no article read back, and at least one copy taken during a flush.
    • On main plus the hook (control commit 4ca7e683/b5a0c736), it fails: 40 flushes, 201 misses, 35 articles read back, 2.5 MB.

Validation

Head: bccb220 (rebased on main e00226f).

(farm run on bccb220 pending)

macOS (m5air): (pending)

Pre-rebase head ea56206d, farm both architectures: cargo_exit=0, daemon_exit=0, 434/434 on x86_64 and on arm64.

Review

Clean-room review of f1be381..ea56206d: G2G, with 4 non-blocking findings, all fixed in this head:

  • Completion copies are not marked readable.
  • The new counter proves liveparflushrace reaches the changed boundary.
  • The hook logs when it is set.
  • A misplaced doc comment was moved.

Deployment / measurement

Deploy through the 6790 queue and measure source reads before and after on a 3+ GB set: (pending)

🤖 Generated with Claude Code

https://claude.ai/code/session_01LG44gYUGuwLMB2hw7HQGbM

…from disk; par-rs 2524277

At line speed the article cache flushes the file being downloaded almost
constantly. Its snapshot for live PAR (cache sub-op 1) refused to copy
while the file was flush-locked, so every article that finished during a
flush of its file was taken as written and par-rs read it back from disk
(6790: 437 articles, 335.8 MB of a 3.3 GB set), and its later write kept a
copy that no capture ever took.

- qfile.rs: the snapshot copies while a flush runs. The segment frees that
  could race with it (flush discard, sub-op 6; file completion, output op
  9/5) now run under the cache content lock the snapshot holds. The 9/5
  free was an unlocked race with snapshots before.
- File completion hands a data file's cached articles to live PAR before
  freeing them (streaming_session_articles_completed), as a flush does, but
  not as readable (the write may still be buffered) and without the
  back-fill hold the completion keeps itself.
- A capture taken as written marks the article, so a later write keeps no
  stale copy charged to ParBuffer.
- Bytes kept before the session past the 64 MB cap: logged once per job.
- I/O line: "N copied from the cache during a flush (all jobs)".
- par-rs b60bfd1 -> 2524277 (#145): a slice read before its article reaches
  the file waits instead of counting as damaged; the boundary test now
  expects the wait and the verify after the write.
- Test hook RUSTYGET_TEST_FLUSH_HOLD_MS (logged when set) and scenario
  liveparflushrace: 1 MB cache, 16 connections, 150 ms flush hold; asserts
  source_bytes_read 0 and no article read back. On main it reads 35
  articles (2.5 MB) back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LG44gYUGuwLMB2hw7HQGbM

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant