Skip to content

cephfs_mirror: fix incremental sync after directory rename - #70757

Merged
kotreshhr merged 2 commits into
ceph:mainfrom
LiShengG:wip-cephfs-mirror-rename-snapdiff
Oct 1, 2026
Merged

kotreshhr merged 2 commits into
ceph:mainfrom
LiShengG:wip-cephfs-mirror-rename-snapdiff

Conversation

@LiShengG

@LiShengG LiShengG commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Incremental (snapdiff-based) sync silently loses every unmodified descendant of
a renamed directory. The remote copy is left with the old name deleted and the
new name present but incomplete, the sync is reported as successful, and no
later snapshot repairs it.

Reproduced deterministically on main (9b679b22366) with a two-cluster vstart
setup:

snap1:  dirB/fb                      -> replicated, checksums match
        mv dirB dirB-renamed         (fb itself untouched)
snap2:  source   dirB-renamed/fb
        target   dirB-renamed/       <- empty, fb lost
        peer status: last_synced_snap=snap2, state=idle, failure_count=0
snap3:  target   dirB-renamed/fb still missing (no self-heal)

Control cases behave correctly, which isolates the defect to directory rename:
modifying a child after the rename syncs it, and a file-level rename copies the
file under its new name.

Root cause

Three layers combine into a silent hole:

  1. snapdiff is inode-scoped. Renaming a directory only changes the parent's
    dentry; the renamed directory keeps its inode and its children's dentries see
    no version split, so the recursive diff for the new path is empty.
  2. ceph_open_snapdiff() tolerates the path being absent in the older snapshot
    and falls back to opening only the current side (src/libcephfs.cc:888-897).
    That is intended for genuinely new directories, but after a rename it turns
    the empty diff into a successful, empty result instead of an error.
  3. PeerReplayer therefore purges the old name on the remote, creates the new
    name, and recurses with a diff that reports nothing. dirty_snap_id still
    matches the synced snapshot, so there is no remote-scan fallback either.

SnapDiffSync's existing pic (purged_or_itype_changed) machinery does not
cover this: a rename appears as "old name deleted, new name created", and the
new name is not in m_deleted[parent], so pic stays false.

Fix

Before trusting snapdiff for a directory, stat the same path in the previous
snapshot:

  • absent -> traverse the current snapshot in full;
  • present with a different type or inode -> purge the remote entry first (so old
    and new contents cannot merge on the target), then traverse in full.

The decision propagates to descendants through
SyncEntry::set_purged_or_itype_changed(), and files below such a subtree are
queued with sync_check=false so they are copied whole.

Both stat calls go through the same mount: SnapDiffSync is only used when
fh.p_mnt == m_local_mount, so stx_ino from the two snapshots is directly
comparable. The inode comparison is defense in depth; normal same-name
replacements are reported delete-before-create and are already selected for full
traversal by m_deleted.

Cost is one extra statxat() per changed directory, and none inside a subtree
that is already being traversed in full.

Tests

src/test/libcephfs/snapdiff.cc and qa/tasks/cephfs/test_mirroring.py
currently have no directory-rename coverage at all, which is why this went
unnoticed. The new integration test covers, against the same mirrored directory:

  • a same-parent rename with a nested unchanged descendant
    (dirB/sub/deeper/unchanged), which also exercises propagation of the full
    traversal decision to descendants;
  • a cross-parent rename (d1/X -> d2/Y);
  • a same-name directory replacement (rm -rf replace/B; mv replace/A replace/B),
    asserting that the previously replicated replace/B/old-only does not survive
    on the target.

Every round compares full source/target snapshot checksums, so the test fails
without the fix. Pending writes are synced before each snapshot: otherwise
delayed writeback can move a baseline file into a later snapdiff change set and
mask the regression.

Contribution Guidelines

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

16 similar comments
@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@github-actions github-actions Bot added cephfs Ceph File System tests labels Aug 1, 2026
@LiShengG LiShengG changed the title Wip cephfs mirror rename snapdiff cephfs_mirror: fix incremental sync after directory rename Aug 1, 2026
@vshankar
vshankar requested review from a team and kotreshhr September 2, 2026 05:38
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@LiShengG
LiShengG force-pushed the wip-cephfs-mirror-rename-snapdiff branch from 560710c to 8df6e82 Compare September 7, 2026 11:01
@kotreshhr kotreshhr self-assigned this Sep 7, 2026
@kotreshhr

Copy link
Copy Markdown
Contributor

Good catch!

@kotreshhr

Copy link
Copy Markdown
Contributor

Triggered teuthology test against main to validate if the added test fails without the fix
https://pulpito-ng.ceph.com/khiremat-2026-09-22_11:31:51-fs:mirror-main-distro-default-trial/

@kotreshhr

Copy link
Copy Markdown
Contributor

The only down side is that the rename directory would re-sync all the children freshly. If it's a deep directory, it would take a lot of time. But detecting as a rename and syncing it as remote rename doesn't work in all the cases with snapdiff e.g, cross directory renames, swaps (snap1: dir1 (ino1) dir2(ino2) , snap2: dir2(ino1) dir1 (ino2)) etc

But there should be a way detect at least the simple cases and do remote rename in such cases. But I wouldn't block this PR for that and do it as an optimisation.
cc:@vshankar

@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

Recursive snapdiff can return no entries for a directory that is new at
its current path. This omits unchanged descendants from the remote
snapshot.

Use a full traversal when the path is absent from the previous snapshot.
Also detect same-name directory replacements by inode and purge stale
remote contents before traversing them in full.

The inode check is defense in depth. Normal same-name replacements are
reported delete-before-create, so m_deleted selects a full traversal
before the inode comparison is reached.

Fixes: https://tracker.ceph.com/issues/78910
Signed-off-by: Li Sheng <[email protected]>
Add coverage for unchanged nested descendants across same-parent and
cross-parent directory renames, and for same-name directory
replacement.

Sync pending writes before every snapshot. This prevents delayed
writeback from turning a baseline file into a later snapdiff change and
masking the regression.

Fixes: https://tracker.ceph.com/issues/78910
Signed-off-by: Li Sheng <[email protected]>
@LiShengG

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main and resolved the test insertion conflict, preserving both tests. No changes to the fix logic. Thanks for the review!

@kotreshhr

Copy link
Copy Markdown
Contributor

@kotreshhr

Copy link
Copy Markdown
Contributor

The only down side is that the rename directory would re-sync all the children freshly. If it's a deep directory, it would take a lot of time. But detecting as a rename and syncing it as remote rename doesn't work in all the cases with snapdiff e.g, cross directory renames, swaps (snap1: dir1 (ino1) dir2(ino2) , snap2: dir2(ino1) dir1 (ino2)) etc

But there should be a way detect at least the simple cases and do remote rename in such cases. But I wouldn't block this PR for that and do it as an optimisation. cc:@vshankar

Created the tracker - https://tracker.ceph.com/issues/80957
cc: @vshankar

@kotreshhr
kotreshhr requested review from a team and vshankar September 28, 2026 06:40
@kotreshhr

Copy link
Copy Markdown
Contributor

This PR has been added to main integration testing by khiremat started 2026-09-28-12:15.

@kotreshhr

Copy link
Copy Markdown
Contributor

@vshankar vshankar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Nice catch!

@kotreshhr
kotreshhr merged commit 362754d into ceph:main Oct 1, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants