Skip to content

feat(engine): plumb negotiated checksum strategy into ParallelDeltaApplier - #4616

Merged
oferchen merged 1 commit into
masterfrom
feat/parallel-applier-checksum-strategy
May 21, 2026
Merged

oferchen merged 1 commit into
masterfrom
feat/parallel-applier-checksum-strategy

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

BR-3i.b (#2498) - plumbing-only PR that threads the negotiated strong-checksum strategy into ParallelDeltaApplier so the upcoming BR-3i.c (#2499) can land the verify_chunk dispatch 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):

  • New struct field: strategy: Arc<dyn checksums::strong::strategy::ChecksumStrategy>. Arc keeps the rayon-worker hot path allocation-free; the trait is already Send + Sync (crates/checksums/src/strong/strategy/trait_def.rs:24).
  • New constructor: with_strategy(concurrency, strategy) for the negotiated path the receiver pipeline will use once BR-3i.c lands.
  • Existing constructor new(concurrency) keeps its signature and defaults to ChecksumStrategySelector::for_algorithm(ChecksumAlgorithmKind::Md5, 0), matching the protocol >= 30 fallback ChecksumFactory::from_negotiation resolves when no NegotiationResult is present. All 12 test/bench ::new call sites identified by the audit need zero changes.
  • Debug impl extended to expose algorithm_kind so the strategy is observable in logs.
  • Read-only accessor 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_chunk still returns digest_len = chunk.data.len(); the dispatch to self.strategy.compute(&chunk.data) is BR-3i.c (#2499). The new test with_strategy_does_not_change_verify_chunk_behaviour pins 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 -- --check
  • cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings
  • cargo 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)
  • Full CI (fmt+clippy, nextest, Windows, macOS, Linux musl)

Refs: #2498, #2497 (BR-3i.a audit), follow-up #2499 (BR-3i.c).

@github-actions github-actions Bot added the enhancement New feature or request label May 20, 2026
…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
oferchen force-pushed the feat/parallel-applier-checksum-strategy branch from 642a540 to 6ae01b3 Compare May 20, 2026 22:39
@oferchen
oferchen merged commit 0043cdb into master May 21, 2026
49 of 55 checks passed
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
@oferchen
oferchen deleted the feat/parallel-applier-checksum-strategy branch May 21, 2026 14:08
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant