Skip to content

fix(batch): replay hardlinks under the sorted-last data-holder - #7959

Merged
oferchen merged 2 commits into
masterfrom
fix/cross-impl-hardlink-batch
Sep 24, 2026
Merged

oferchen merged 2 commits into
masterfrom
fix/cross-impl-hardlink-batch

Conversation

@oferchen

Copy link
Copy Markdown
Owner

What

Fixes cross-implementation hardlink --read-batch -aH replay, which was broken in both directions:

  • upstream writes → oc reads: exit 0 but silent data loss — the cluster leader was dropped, its mate left unlinked.
  • oc writes → upstream reads: exit 23 — both cluster members missing.

A batch is a tee of the protocol-32 wire stream and the rsync man page requires any reader at protocol ≥ writer to replay it, so this is a fidelity obligation, not by-design non-portability. A plain network -H transfer was unaffected in both directions.

Root cause

For a hardlink cluster, upstream transfers the sorted-last member — the one match_gnums() flags FLAG_HLINK_LAST and finish_hard_link() completes — and links every other member (including the sorted-first) to it (hlink.c:113-194, hlink.c:496-565). oc diverged on two points:

  1. --write-batch shipped the cluster's single payload under the sorted-first member's NDX.
  2. The batch-replay receiver's create_hardlinks() assumed the sorted-first hlink_first member was the materialized data-holder and only linked followers to it.

oc-self replay agreed with itself, so the divergence surfaced only across implementations. The live wire path is unaffected because oc's generator makes hlink_first the transferred member there; only a recorded batch stream can place the data-holder on a different member.

Fix (two aligned changes)

  • Writer (crates/engine/.../options/batch.rs): ship the cluster payload under the sorted-last member's NDX, matching upstream's FLAG_HLINK_LAST data-holder, so upstream can replay an oc batch.
  • Receiver (create_hardlinks): during batch replay only (self.local_replay), link every absent group member — including an absent sorted-first leader — to whichever member actually materialized on disk, mirroring finish_hard_link(). The live path is deliberately unchanged: there an absent hlink_first member means its own transfer was skipped/errored (FLAG_SKIP_HLINK) and must not be resurrected, so that path keeps skipping every hlink_first member. Gating on local_replay keeps the network -H receiver and its skip/virtual-first semantics untouched.

Also un-ignores cross_impl_hardlink_batch_{pair,triple}_parity (added as a registered known divergence); they now pass both directions for 2- and 3-member clusters.

Verification (upstream 3.4.4 oracle, lxhost)

All four cells reconstruct the cluster (one inode, correct nlink) at exit 0, for 2- and 3-member clusters:

write → read before after
oc → oc ok ok
upstream → upstream ok ok
upstream → oc data loss (exit 0) ok
oc → upstream exit 23 ok

Gates (all green): oc-self --read-batch -aH regression test; the un-ignored cross-impl parity tests (both directions, 2+3 member, oracle set); cargo nextest run -p transfer (2983 passed — the create_hardlinks regression coverage, incl. create_hardlinks_promotes_present_member_when_leader_absent); -p engine (5238); -p batch; the hardlink integration tests; a plain network -H transfer against the upstream daemon (both directions); cargo fmt --all -- --check; tools/ci/check_rustfmt_all.py; cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings.

Note

Stacks on #7958 (the registered cross-impl divergence tests). Until #7958 merges this PR carries those test additions; after #7958 lands it rebases to just the fix plus un-ignoring the two cases.

upstream: hlink.c:113-194 match_gnums(), hlink.c:496-565 finish_hard_link().

Add oracle-gated cross-implementation --read-batch -aH parity cases for a
2- and 3-member hardlink cluster, both directions (upstream-writes/oc-reads
and oc-writes/upstream-reads). They assert the correct upstream-matching end
state: every cluster member present, all sharing one inode with the right
nlink, and the unlinked control independent.

Both are #[ignore]'d as a registered, owned known divergence (task #18):
oc's --write-batch ships the cluster's single payload under the sorted-first
member's NDX (the oc-self convention from #7928), while upstream ships it
under the sorted-last member - the FLAG_HLINK_LAST data-holder its generator
transfers (hlink.c:113-194 match_gnums(), hlink.c:490-565 finish_hard_link()),
and oc's batch replay decodes the follower's first_hlink_ndx with a different
base. So oc reading an upstream batch silently drops the leader (exit 0) and
upstream reading an oc batch exits 23.

A plain network -H transfer is unaffected - oc's live wire receiver follows
the sender's chosen data-holder correctly - so the divergence is specific to
the batch write and batch-replay paths, not the shared receiver.

These tests un-ignore when the batch-path fix lands (task #18); until then
they keep the verified divergence visible without a silent waiver. The
oc-self replay_hardlink_pair_parity case stays non-ignored and green.
@oferchen
oferchen enabled auto-merge (squash) September 24, 2026 15:36
@github-actions github-actions Bot added the bug Something isn't working label Sep 24, 2026
Cross-implementation hardlink batch replay was broken both directions - a
fidelity obligation, since a batch is a tee of the protocol-32 wire stream
and the rsync man page requires any reader at protocol >= writer to replay
it. Upstream reading an oc batch failed with exit 23; oc reading an upstream
batch silently dropped the cluster leader at exit 0 (data loss). A plain
network -H transfer was unaffected in both directions.

Root cause: for a hardlink cluster upstream transfers the sorted-LAST member
- the one match_gnums() flags FLAG_HLINK_LAST and finish_hard_link()
completes - and links every other member (including the sorted-first) to it
(hlink.c:113-194, hlink.c:496-565). oc's --write-batch shipped the cluster's
single payload under the sorted-FIRST member's NDX, and the batch-replay
receiver treated the sorted-first hlink_first member as the materialized
data-holder. oc-self replay agreed with itself, so the divergence surfaced
only across implementations. The live wire path is unaffected because oc's
generator makes hlink_first the transferred member; only a recorded batch
stream can place the data-holder on a different member.

Three aligned changes:

- Writer (engine local_copy batch): ship the cluster payload under the
  sorted-LAST member's NDX, matching upstream's FLAG_HLINK_LAST data-holder,
  so upstream can replay an oc batch.

- Receiver replay commit (transfer receiver/transfer/replay.rs): record the
  just-committed hardlink member as its group's data-holder in the
  HardlinkApplyTracker. Which member the batch transferred is stream-dictated
  (now the sorted-last member), so the source cannot be inferred from disk
  presence - a stale pre-existing sorted-first member would otherwise win and
  the fresh payload be discarded.

- Receiver create_hardlinks(): during batch replay only (self.local_replay),
  let every hlink member - including the sorted-first leader - resolve its
  group source through promote_hardlink_leader() (which returns the recorded
  data-holder) and the self-link guard, so an absent or stale sorted-first
  member is re-linked to the fresh data-holder. The live path is unchanged:
  there an absent hlink_first member means its own transfer was
  skipped/errored (FLAG_SKIP_HLINK) and must not be resurrected, so that path
  keeps skipping every hlink_first member. This keeps the network -H receiver
  and its skip/virtual-first semantics untouched.

Un-ignores cross_impl_hardlink_batch_{pair,triple}_parity (added earlier as a
registered known divergence); they now pass both directions for 2- and
3-member clusters. Fixes the UTS batch-only-remove-source-regression cell
(replay into a pre-existing destination whose stale cluster members must be
re-linked to the freshly transferred payload). oc-self #7956/#7928 stay green
(they assert end state, which survives the data-holder change).

upstream: hlink.c:113-194 match_gnums(), hlink.c:496-565 finish_hard_link().
@oferchen
oferchen force-pushed the fix/cross-impl-hardlink-batch branch from 7d306bf to ce71049 Compare September 24, 2026 17:00
@oferchen
oferchen merged commit e2f88d2 into master Sep 24, 2026
78 of 79 checks passed
@oferchen
oferchen deleted the fix/cross-impl-hardlink-batch branch September 24, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant