Repository navigation
mds: do not replicate an xlocked dentry whose linkage is projected - #72790
Conversation
handle_discover lets a path_locked discover replicate an xlocked
dentry. The exception exists for the xlocker's own witnesses, which
traverse the paths before the xlocker projects anything: a rename leader
sends rename_prep only after it holds all locks, and calls
_rename_prepare only after every witness has acked. MDiscover does not
carry a request id, though, so any peer that traverses with
MDS_TRAVERSE_PATH_LOCKED gets the exception, including one working for an
unrelated request. open_remote_dentry with want_xlocked, as used by
handle_peer_rename_prep and handle_peer_rmdir_prep, discovers the primary
dentry of the inode it is opening that way.
If that dentry belongs to a rename that has already projected its new
linkage and is waiting for its journal entry, the new replica gets the
old linkage and is not a witness. When the rename commits,
_rename_finish sends MDentryLink for destdn to every replica that did not
witness it, on the assumption that such a replica is null. A replica of a
rename-over destdn is not null, so handle_dentry_link fails its assertion
that the replica is null. A late replica of srcdn is never told that the
name became null, which can trip the same assert the next time the name
is linked.
early_reply already relies on this not happening. It leaves a rename's
dentry xlocks undone for exactly this reason:
// so do not set xlocks on dentries "done", the xlocks prevent dentries
// that have projected linkages from getting new replica.
The path_locked exception bypasses that.
One way to get there: a client renames over the primary link of a hard
linked inode. The rename has no journaled peers, so it gets an early
reply. Its inode xlocks become xlockdone, and the same client can take
them over at once; without the early reply the two renames would
serialize on those xlocks. The client then renames over another link of
the same inode. A rank that witnesses this second rename and does not
have the inode in cache opens it, discovers the primary dentry, still
xlocked by the first rename, and receives its pre-rename linkage. A
moment later the first rename commits and sends that rank MDentryLink.
If both renames move links of one source inode, as when a tool replaces
every link of a set with links to a new inode, that witness is not the
source inode's auth: such a witness journals, so the first rename would
not have been early-replied. It is a witness because it still holds a
replica of srcdn or destdn, for example one left behind after the
directory's subtree was exported, while it no longer has the inode
itself in cache.
Reproduced on v18.2.7 with two active ranks and one client. /d is
pinned to rank 1 and /d/C to rank 0; /d/A/f is the primary link of
inode O, /d/B/f1 a remote link to O, /d/C/u the primary link of U and
/d/B/.stg1 a remote link to U. With mds_log_pause set on rank 1,
renaming /d/A/T over /d/A/f gets an early reply, and renaming
/d/B/.stg1 over /d/B/f1 makes rank 0, the auth of U, a witness. Its
rename_prep opens O, and rank 1 logs "handle_discover allowing discovery of xlocked
[dentry #0x1/d/A/f ... pv=16 v=8 ...]". When the log is unpaused,
_rename_finish sends MDentryLink for /d/A/f, and rank 0 fails the
assertion in handle_dentry_link. With this change, rank 1 logs
"handle_discover blocking on xlocked" for /d/A/f, the second rename
completes once the first commits, and neither rank aborts.
Allow the path_locked exception only while the dentry has no projected
linkage. After that, block on the xlock the same way a normal discover
does. The xlocker no longer depends on any peer, so it will finish and
drop the xlock, and the discover is retried against the committed
linkage. The xlocker's own witnesses are unaffected because they never
discover after it projects. Nudge the log when blocking: an
early-replied xlocker defers its journal flush, and the discover, and
any peer request waiting behind it, should not wait for the next tick.
Also drop the comments about tail items. They have been stale since
commit cac3c01, "mds: change MDCache::discover_path()'s
wants_xlocked semantic", made the exception apply at every depth.
Signed-off-by: Anthony D'Atri <[email protected]>
Assisted by Claude Opus-5.5
|
Thanks for the patch @anthonyeleven. This is pending on me for review. |
Awesome, thanks for your attention. As you might deduce, this bit me in production. |
Got it and its under review now. |
|
Thanks for the detailed write-up. I reviewed the change and tested it; it looks good to me. TestingBuilt from main (0fab663) with and without this PR. vstart cluster on a VM: 2 active ranks, 1 standby, one kernel client, 1. The reproducer from the commit message, with
2. Stress test, no log pause. 300 rounds. In each round O is a fresh inode created on rank 1 (
Latency of the second rename with the PR, in ms (single run, n=300):
3. Recovery and cleanup. Without the PR, the new rank 0 replayed the half-done second rename ( 4. qa via vstart_runner (
@anthonyeleven Locally I wrote a qa reproducer in 267feae, you can just included it in this PR or you write a new one if you like. Each run takes about 52 seconds. |
|
Forgive my cluelessness please: you mention having written a reproducer but don’t I already have one in the pr? Is more needed for approval? |
I mean a qa test which also includes the reproducer in it. Usually for the bug fix we'd better have one qa test together with it. |
With two active ranks, rename a file over the primary link of a hard linked inode on rank 1 while rank 1's journal is paused, so the rename gets an early reply and keeps its new linkage projected. Then rename a remote link of an inode on rank 0 over another link of the same inode. Rank 0 is a witness of that rename, and its rename_prep discovers the primary dentry still xlocked by the first rename. Check that rank 0 is still running, with the same gid, after the journal is unpaused, and that both renames took effect. Without the fix, the discover returns the pre-rename linkage, and the first rename's MDentryLink fails ceph_assert(dnl->is_null()) on rank 0. Fixes: https://tracker.ceph.com/issues/81730 Assisted-by: LLM Signed-off-by: Xiubo Li <[email protected]>
|
Thanks, I've included your qa test 267feae as-is (your authorship) in this PR. |
vshankar
left a comment
There was a problem hiding this comment.
The fix is correct. I will do a sample run of the test with a branch that does not have this fix. The MDS should hit that assert.
So, LGTM, but deferring approval till I validate the test.
|
Reproduces like a piece of cake on a branch without the fix. See: https://pulpito.ceph.com/vshankar-2026-11-02_13:53:46-fs:functional-wip-vshankar-oft-load-shrink-journal-oob-distro-default-trial/705437/ 2026-11-02T14:01:49.942 INFO:teuthology.orchestra.run:Running command with timeout 300 2026-11-02T14:01:49.943 DEBUG:teuthology.orchestra.run.trial031:> (cd /home/ubuntu/cephtest/mnt.0 && exec mv d/B/.stg1 d/B/f1) 2026-11-02T14:01:55.087 DEBUG:teuthology.orchestra.run.trial191:> sudo adjust-ulimits ceph-coverage /home/ubuntu/cephtest/archive/coverage timeout 300 ceph --cluster ceph --admin-daemon /var/run/ceph/ceph-mds.b.asok --format=json config set mds_log_pause false 2026-11-02T14:01:55.176 INFO:tasks.ceph.mds.d.trial191.stderr:/ceph/rpmbuild/BUILD/ceph-22.0.0-270-ge66c451f/src/mds/MDCache.cc: In function 'void MDCache::handle_dentry_link(ceph::cref_t&)' thread 7f50fa3f66c0 time 2026-11-02T14:01:55.176707+0000 2026-11-02T14:01:55.176 INFO:tasks.ceph.mds.d.trial191.stderr:/ceph/rpmbuild/BUILD/ceph-22.0.0-270-ge66c451f/src/mds/MDCache.cc: 11587: FAILED ceph_assert(dnl->is_null()) 2026-11-02T14:01:55.177 INFO:tasks.ceph.mds.d.trial191.stderr: ceph version 22.0.0-270-ge66c451f (e66c451fd13cc7276e554eca2419e33b1ab59269) vampire (dev - RelWithDebInfo) 2026-11-02T14:01:55.177 INFO:tasks.ceph.mds.d.trial191.stderr: 1: ceph-mds(+0xbefce) [0x5562cf0e6fce] 2026-11-02T14:01:55.177 INFO:tasks.ceph.mds.d.trial191.stderr: 2: (MDCache::dispatch(boost::intrusive_ptr const&)+0x30a) [0x5562cf2e4e0a] 2026-11-02T14:01:55.177 INFO:tasks.ceph.mds.d.trial191.stderr: 3: (MDSRank::handle_message(boost::intrusive_ptr const&)+0x223) [0x5562cf165c83] 2026-11-02T14:01:55.177 INFO:tasks.ceph.mds.d.trial191.stderr: 4: (MDSRank::_dispatch(boost::intrusive_ptr const&, bool)+0x553) [0x5562cf167ee3] 2026-11-02T14:01:55.177 INFO:tasks.ceph.mds.d.trial191.stderr: 5: (MDSRankDispatcher::ms_dispatch(boost::intrusive_ptr const&)+0x53) [0x5562cf168313] 2026-11-02T14:01:55.177 INFO:tasks.ceph.mds.d.trial191.stderr: 6: (MDSDaemon::ms_dispatch2(boost::intrusive_ptr const&)+0x13c) [0x5562cf151fdc] 2026-11-02T14:01:55.177 INFO:tasks.ceph.mds.d.trial191.stderr: 7: (DispatchQueue::entry()+0x50f) [0x7f50ffbf2eff] 2026-11-02T14:01:55.177 INFO:tasks.ceph.mds.d.trial191.stderr: 8: /usr/lib64/ceph/libceph-common.so.2(+0x4879f1) [0x7f50ffc879f1] 2026-11-02T14:01:55.177 INFO:tasks.ceph.mds.d.trial191.stderr: 9: /lib64/libc.so.6(+0x958bf) [0x7f50ff2bc8bf] 2026-11-02T14:01:55.177 INFO:tasks.ceph.mds.d.trial191.stderr: 10: /lib64/libc.so.6(+0x10643c) [0x7f50ff32d43c] 2026-11-02T14:01:55.177 INFO:tasks.ceph.mds.d.trial191.stderr:2026-11-02T14:01:55.176+0000 7f50fa3f66c0 -1 /ceph/rpmbuild/BUILD/ceph-22.0.0-270-ge66c451f/src/mds/MDCache.cc: In function 'void MDCache::handle_dentry_link(ceph::cref_t&)' thread 7f50fa3f66c0 time 2026-11-02T14:01:55.176707+0000 |
|
This PR has been added to main integration testing by vshankar started 2026-11-04-08:50. |
A rename into a directory on another rank of a file the client has just written waits a full mds_tick_interval (5 s). Two waits in that path are for an update that is already submitted to the journal but not flushed, and nothing asks for a flush, so the update is only journaled by the next tick: - handle_peer_rename_prep() freezes the renamed inode on the rank that owns it. When the client flushes its dirty caps on the file, at the same time or just before, _do_cap_update() holds an auth pin on the inode until the update is journaled, and the freeze waits for it. Flush the log when the freeze has to wait, and have _do_cap_update() ask for a flush when the inode is being frozen, for a cap flush that arrives after the freeze started. - The other rank discovers the just-created source dentry, and handle_discover() blocks on its xlock, which the create holds until it is journaled. d0a7454 ("mds: do not replicate an xlocked dentry whose linkage is projected", ceph#72790) already nudges the log there. On a vstart cluster with two active ranks, renaming a just-written 4 KiB or 1 MiB file from a directory on rank 0 into one on rank 1 took a median of 2.8-5.0 s with a kernel client and 3.5-4.6 s with ceph-fuse, and about 1.5 s with mds_tick_interval set to 1. With this change it takes 140-210 ms with either client, against 3 ms (kernel) and 37 ms (ceph-fuse) within one rank. Measured on Reef 18.2.8. On main, with ceph-fuse, the same renames took 4.9-5.0 s before and 16-110 ms after; with mds_tick_interval at 10 they took 10 s before and 80-100 ms after. Fixes: https://tracker.ceph.com/issues/82190 Assisted-by: Claude-Code-v2.1.303:claude-opus-5-5 Signed-off-by: Dan van der Ster <[email protected]>
Fixes: https://tracker.ceph.com/issues/81730
handle_discoverlets apath_lockeddiscover replicate an xlocked dentry. The exception is meant for the xlocker's own witnesses, butMDiscovercarries no request id, so a peer working on another request gets it too, for examplehandle_peer_rename_prepopening a remote dentry's inode. If the dentry belongs to a rename that has already projected its new linkage, such as an early-replied rename waiting on its journal entry, the new replica gets the old linkage and is not a witness. When the rename commits,_rename_finishsendsMDentryLinkto that replica, and the peer failsceph_assert(dnl->is_null())inMDCache::handle_dentry_link.This change allows the exception only while the dentry has no projected linkage. Otherwise the discover blocks on the xlock as a normal discover does, and the log is nudged so an early-replied xlocker does not hold it until the next tick. The xlocker's own witnesses all traverse before it projects, so they are unaffected.
Testing: reproduced deterministically on v18.2.7 with two active ranks, one kernel client and
mds_log_pauseon the rename leader. The reproducer script, debug_mds 20 logs from both ranks and the sequence are on the tracker. Without this change the peer rank aborted in 2 of 2 runs. With it, cherry-picked onto v18.2.7, it aborted in 0 of 2: the auth rank logshandle_discover blocking on xlocked, and the second rename completes once the first commits. The diff is identical on main.Contribution Guidelines
To sign and title your commits, please refer to Submitting Patches to Ceph.
If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.
When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist
Show available Jenkins commands
jenkins test classic perfJenkins Job | Jenkins Job Definitionjenkins test crimson perfJenkins Job | Jenkins Job Definitionjenkins test signedJenkins Job | Jenkins Job Definitionjenkins test make checkJenkins Job | Jenkins Job Definitionjenkins test make check arm64Jenkins Job | Jenkins Job Definitionjenkins test submodulesJenkins Job | Jenkins Job Definitionjenkins test dashboardJenkins Job | Jenkins Job Definitionjenkins test dashboard cephadmJenkins Job | Jenkins Job Definitionjenkins test apiJenkins Job | Jenkins Job Definitionjenkins test docsReadTheDocs | Github Workflow Definitionjenkins test ceph-volume allJenkins Jobs | Jenkins Jobs Definitionjenkins test windowsJenkins Job | Jenkins Job Definitionjenkins test rook e2eJenkins Job | Jenkins Job DefinitionYou must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.
Signed-off-by: Anthony D'Atri [email protected]
Assisted by Claude Opus-5.5