Repository navigation
fix(batch): ship hardlink payload under the sorted-first cluster NDX - #7928
Merged
Merged
Conversation
A local --write-batch synthesises the flist and delta stream from the traversal-order copy, then remaps each delta NDX to the sorted position the replaying receiver assigns after flist_sort_and_clean(). For a hardlink cluster the payload was emitted under the NDX of whichever member the walk reached first. When that member does not sort first, the receiver's match_hard_links() promotes a different member to the group leader (FLAG_HLINK_FIRST) and expects the payload there, so the real leader was never written and the follower was left unlinked - the pair replayed as a single regular file (or a missing follower) at exit 0. Ship the cluster's single payload under the sorted-first member's NDX, mirroring upstream, which transfers the FLAG_HLINK_FIRST member and links the rest to it (hlink.c:113-194 match_gnums()). Replaces the ignored replay_hardlink_parity_matches_upstream with replay_hardlink_pair_parity, which pins each implementation's own write/read-batch -aH to reproduce the linked pair (shared inode) and asserts oc's replayed tree equals upstream's.
oferchen
enabled auto-merge (squash)
September 23, 2026 07:29
This was referenced Sep 24, 2026
oferchen
added a commit
that referenced
this pull request
Sep 24, 2026
Add an oracle-free regression test for the batch hardlink data-loss fix (#7928, "ship hardlink payload under the sorted-first cluster NDX"). A local --write-batch builds the flist and delta stream in traversal order, then remaps each delta NDX to the sorted position the replaying receiver assigns after flist_sort_and_clean(). The engine's reorder_hardlink_group_holders promotes the name-sorted-last fresh cohort member to the data-holder, so it records the single payload, while the replaying receiver flags the name-sorted-first member and expects the payload under its NDX (upstream hlink.c:113-194 match_gnums()). Before #7928 the payload shipped under the holder's own sorted NDX, so the real leader received no data, was never written, and the other member was left unlinked - the cluster replayed as a single or missing file at exit 0. The only prior coverage (replay_hardlink_pair_parity in tests/batch_replay_upstream_parity.rs) skips whenever no upstream rsync oracle is installed, so a build without one has no hardlink-batch guard at all. This test drives oc's own --write-batch then --read-batch with no upstream dependency, so it always runs its assertions. The cohort names are chosen so the sorted-first member (aaa_leader.txt) is not the data-holder (zzz_holder.txt) - the exact case #7928 fixes; a same-order cohort would pass against the pre-fix code and prove nothing. Reverting the one-line emit-NDX remap makes the test fail with "replay must produce the sorted-first member aaa_leader.txt" at exit 0, confirming the guard is not vacuous. The fix lives on the write path in crates/engine, which the batch crate cannot reach (no engine dependency), so the regression is pinned by a full write -> read round-trip at the integration level rather than a batch-crate unit test.
oferchen
added a commit
that referenced
this pull request
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
added a commit
that referenced
this pull request
Sep 24, 2026
* test: register cross-impl hardlink batch replay divergence 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. * fix(batch): replay hardlinks under the sorted-last data-holder 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().
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.
Problem (regression, silent data loss at exit 0)
--write-batch -aHthen--read-batch -aHof a hardlinked pair replayed as ONE unlinked file: the follower was missing from the destination and exit was 0.Root cause
A local
--write-batchhas no real sender stream, so oc re-encodes the flist + delta stream from the traversal-order copy, remapping each delta NDX to the sorted position the replaying receiver assigns afterflist_sort_and_clean(). For a hardlink cluster the single payload was emitted under the NDX of whichever member the walk reached first. When that is not the member that sorts first, the receiver'smatch_hard_links()promotes a different member toFLAG_HLINK_FIRSTand expects the payload at that NDX — so the true leader is never written and its follower is left unlinked.Fix (single owner)
flush_batch_delta_to_batchnow ships each cluster's payload under the sorted-first member's NDX (newbatch_hlink_cluster_leader_ndx, min sorted index per group), mirroring upstream, which transfers theFLAG_HLINK_FIRST(sorted-first) member and links the rest to it. NDX is pre-resolved before the codec borrow, splitting the two&mut selfuses cleanly.Upstream:
hlink.c:113-194 match_gnums()(sorted-first member is the group leader / transfer target);flist.c:3260(ndx_start).Verification (pinned toolchain 1.89.0)
-aH): follower.txt was missing; nowleader.txt+follower.txtshare one inode (nlink=2),solo.txtnlink=1; exit 0. Byte-identical to upstream 3.5.0's own--write-batch/--read-batch -aHresult.oc: replay must produce follower.txt; restored → green.batch_replay_upstream_paritybinary: 6/6 run pass. fmt clean; clippy-p engine -p batch -p transfer -D warningsclean;nextest -p batch -p engine5384 pass.Scoped out (flagged, separate ledger item)
Cross-implementation replay of a hardlink batch (oc↔upstream) still differs: upstream's local
-aHbatch uses inc-recursionndx_start == 1(reserves NDX 0) so itsfirst_hlink_ndxgroup refs are base-1; oc's synthetic local batch is base 0. The bases disagree only for the hardlink group index — non-hardlink cells (tree/delete/itemize/stats) pass both directions. Aligning oc's synthetic-batchndx_startconvention is a distinct, higher-risk change to the inc_recurse machinery, deliberately not bundled with this regression fix.