Repository navigation
feat(engine): plumb negotiated checksum strategy into ParallelDeltaApplier - #4616
Merged
Merged
Conversation
…DeltaApplier (BR-3i.b) Adds a `strategy: Arc<dyn ChecksumStrategy>` field plus a `with_strategy(concurrency, strategy)` constructor so the receiver pipeline can thread the negotiated algorithm into the per-chunk verify step without re-boxing on every rayon worker. `new(concurrency)` keeps its existing signature and defaults to MD5 (seed 0), matching the protocol >= 30 fallback `ChecksumFactory::from_negotiation` resolves when no `NegotiationResult` is present, so the 12 test/bench callers identified by the BR-3i.a audit need zero changes. `verify_chunk` still returns `digest_len = chunk.data.len()` - the dispatch to `self.strategy.compute(&chunk.data)` lands as a one-function-body change in BR-3i.c (#2499). This commit is wiring only. Adds three unit tests: - `new_defaults_strategy_to_md5` pins the default algorithm. - `with_strategy_threads_negotiated_algorithm` verifies the Arc handle round-trips through the constructor. - `with_strategy_does_not_change_verify_chunk_behaviour` proves the stub is byte-identical regardless of the configured strategy. Refs: #2498
oferchen
force-pushed
the
feat/parallel-applier-checksum-strategy
branch
from
May 20, 2026 22:39
642a540 to
6ae01b3
Compare
4 tasks
oferchen
added a commit
that referenced
this pull request
May 21, 2026
…-3i.c) (#4640) Replace the length-only verify stub with a real strong-checksum dispatch through the negotiated `ChecksumStrategy` plumbed in BR-3i.b (#4616). Chunks may opt into per-chunk verification by attaching an `expected_strong: ChecksumDigest` through the new `with_expected_strong` builder; the applier computes the digest of `chunk.data` on the rayon worker and compares byte-for-byte before the per-file write happens. Mismatches surface as a typed `ParallelApplyError::ChecksumMismatch` carrying ndx, sequence, algorithm, and both hex digests, then convert into `io::Error` at the public boundary so the receiver can fall back to a phase-2 redo or abort the file without committing corrupt bytes. Chunks with no expected digest still compute the digest (keeping the parallel-verify CPU cost stable across both shapes) but skip the comparison, preserving backward compatibility for existing call sites. The wire format is unchanged - `DeltaChunk` is purely a receiver-side staging structure and the expected digest is held in-memory only. This closes the GA-blocking gap on `parallel-receive-delta` that was called out in the README feature table; the only remaining GA gap is the outer `Mutex<HashMap<FileNdx, _>>` (BR-3j.a-f, in flight on #4634). Adds five regression tests, including BR-3i.e parity: - happy-path verification for MD5 and XXH3 - single-chunk mismatch surfaces typed error and skips the writer - batch mismatch short-circuits with typed error - parallel apply with real digests is byte-identical to sequential - ChecksumMismatch -> io::Error conversion carries the typed message
6 tasks done
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
…DeltaApplier (BR-3i.b) (#4616) Adds a `strategy: Arc<dyn ChecksumStrategy>` field plus a `with_strategy(concurrency, strategy)` constructor so the receiver pipeline can thread the negotiated algorithm into the per-chunk verify step without re-boxing on every rayon worker. `new(concurrency)` keeps its existing signature and defaults to MD5 (seed 0), matching the protocol >= 30 fallback `ChecksumFactory::from_negotiation` resolves when no `NegotiationResult` is present, so the 12 test/bench callers identified by the BR-3i.a audit need zero changes. `verify_chunk` still returns `digest_len = chunk.data.len()` - the dispatch to `self.strategy.compute(&chunk.data)` lands as a one-function-body change in BR-3i.c (#2499). This commit is wiring only. Adds three unit tests: - `new_defaults_strategy_to_md5` pins the default algorithm. - `with_strategy_threads_negotiated_algorithm` verifies the Arc handle round-trips through the constructor. - `with_strategy_does_not_change_verify_chunk_behaviour` proves the stub is byte-identical regardless of the configured strategy. Refs: #2498
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
…-3i.c) (#4640) Replace the length-only verify stub with a real strong-checksum dispatch through the negotiated `ChecksumStrategy` plumbed in BR-3i.b (#4616). Chunks may opt into per-chunk verification by attaching an `expected_strong: ChecksumDigest` through the new `with_expected_strong` builder; the applier computes the digest of `chunk.data` on the rayon worker and compares byte-for-byte before the per-file write happens. Mismatches surface as a typed `ParallelApplyError::ChecksumMismatch` carrying ndx, sequence, algorithm, and both hex digests, then convert into `io::Error` at the public boundary so the receiver can fall back to a phase-2 redo or abort the file without committing corrupt bytes. Chunks with no expected digest still compute the digest (keeping the parallel-verify CPU cost stable across both shapes) but skip the comparison, preserving backward compatibility for existing call sites. The wire format is unchanged - `DeltaChunk` is purely a receiver-side staging structure and the expected digest is held in-memory only. This closes the GA-blocking gap on `parallel-receive-delta` that was called out in the README feature table; the only remaining GA gap is the outer `Mutex<HashMap<FileNdx, _>>` (BR-3j.a-f, in flight on #4634). Adds five regression tests, including BR-3i.e parity: - happy-path verification for MD5 and XXH3 - single-chunk mismatch surfaces typed error and skips the writer - batch mismatch short-circuits with typed error - parallel apply with real digests is byte-identical to sequential - ChecksumMismatch -> io::Error conversion carries the typed message
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BR-3i.b (#2498) - plumbing-only PR that threads the negotiated strong-checksum strategy into
ParallelDeltaApplierso the upcoming BR-3i.c (#2499) can land theverify_chunkdispatch as a one-function-body change.Recipe taken straight from the BR-3i.a audit (
docs/audits/br-3i-a-verify-chunk-audit-2026-05-20.md, section 4):strategy: Arc<dyn checksums::strong::strategy::ChecksumStrategy>.Arckeeps the rayon-worker hot path allocation-free; the trait is alreadySend + Sync(crates/checksums/src/strong/strategy/trait_def.rs:24).with_strategy(concurrency, strategy)for the negotiated path the receiver pipeline will use once BR-3i.c lands.new(concurrency)keeps its signature and defaults toChecksumStrategySelector::for_algorithm(ChecksumAlgorithmKind::Md5, 0), matching the protocol >= 30 fallbackChecksumFactory::from_negotiationresolves when noNegotiationResultis present. All 12 test/bench::newcall sites identified by the audit need zero changes.Debugimpl extended to exposealgorithm_kindso the strategy is observable in logs.strategy() -> &Arc<dyn ChecksumStrategy>so BR-3i.c (and future logging/parity assertions) can read the negotiated kind.verify_chunk stub unchanged - BR-3i.c lands the dispatch
This commit is wiring only.
verify_chunkstill returnsdigest_len = chunk.data.len(); the dispatch toself.strategy.compute(&chunk.data)is BR-3i.c (#2499). The new testwith_strategy_does_not_change_verify_chunk_behaviourpins this invariant so the next PR is the one that observably changes verify output.The applier remains feature-gated behind
parallel-receive-delta, so no default-build path observes any change. Production receivers continue to drive the sequential apply loop.Test plan
cargo fmt --all -- --checkcargo clippy --workspace --all-targets --all-features --no-deps -- -D warningscargo nextest run -p engine --features parallel-receive-delta -E 'test(parallel_apply) | test(arc_drain_panic_recovery)'(16 tests pass, 3 new)cargo bench -p engine --features parallel-receive-delta --bench parallel_receive_delta_perf --no-run(bench compiles, no caller change)Refs: #2498, #2497 (BR-3i.a audit), follow-up #2499 (BR-3i.c).