Repository navigation
crimson/osd: guard recovery clone overlap with try_lock_for_read - #69668
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses a Crimson replicated recovery correctness issue where clone-overlap recovery could read from a neighboring clone while it was concurrently being modified (e.g., by snap trim). It introduces a mechanism to only select neighbor clones for clone-overlap when they can be safely read-locked, and keeps those locks held for the duration of push/pull recovery.
Changes:
- Introduces
RecoveryCloneLockManagerto acquire/hold/release read locks on neighbor cloneObjectContexts used for clone-overlap recovery. - Wires clone-lock acquisition via
try_lock_for_readcallbacks intocalc_clone_subsets()/calc_head_subsets()and threads the lock manager through replicated push/pull recovery flows. - Ensures recovery paths release clone locks on completion and on error/cleanup paths.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/crimson/osd/replicated_recovery_backend.h | Extends replicated recovery APIs to pass/retain a clone lock manager across recovery operations. |
| src/crimson/osd/replicated_recovery_backend.cc | Implements lock acquisition helpers, threads lock manager through push/pull setup, and releases locks on completion/errors. |
| src/crimson/osd/recovery_backend.h | Adds RecoveryCloneLockManager and stores it in push/pull tracking structs. |
| src/crimson/osd/recovery_backend.cc | Releases clone locks during recovery backend cleanup. |
| src/crimson/osd/object_metadata_helper.h | Adds callback-based try_lock_for_read/release_locks hooks to subset-calculation helpers. |
| src/crimson/osd/object_metadata_helper.cc | Applies lock-guarded neighbor selection in clone/head subset calculations and supports early lock release when clone-overlap is abandoned. |
| src/crimson/osd/object_context.h | Exposes try_get_read_lock() / put_read_lock() helpers for ObjectContext read-lock management. |
There was a problem hiding this comment.
thanks, the fix looks right to me. locking the neighbor clones before using them as a clone_subset source is what classic does, and holding them until the push/pull completes matches ObcLockManager.
one thing i'd like to reconsider: the two std::function params on calc_clone_subsets() / calc_head_subsets(). they push the locking and the release bookkeeping down into object_metadata_helper, which i'd rather keep pure and unit-testable.
i think it reads better if calc_* just returns the candidate clones in preference order and the backend locks the first one it can. the loop already walks best-first, so we keep the "can't lock i, try i-1" behavior, and the lock policy stays in the backend:
std::optional<clone_candidate_t> commit_first_lockable( // {clone, overlap}
std::span<const clone_candidate_t> candidates, RecoveryCloneLockManager& mgr) {
for (const auto& c : candidates) {
if (!pg.get_local_missing().is_missing(c.clone) &&
mgr.try_lock_for_read(c.clone, pg.obc_registry)) {
return c;
}
}
return std::nullopt;
}then calc_* doesn't know about locks at all, and release_locks (and the return subsets; patch in the too-many-holes branch) goes away.
unrelated: can release_locks() be the destructor instead of ceph_assert(locks.empty())? the defaulted move-assign (push_info.clone_lock_manager = std::move(...)) replaces the map without unlocking, so a non-empty target would silently leak a read lock and block snap trim on that clone. unlock_for_read() just decrements and wakes on zero, so it's safe from a dtor.
not blocking, the correctness is the main thing. thanks again.
|
@tchaikov updated as you suggested. |
Crimson recovery could use a neighbor clone as a clone_subset source during osd_recover_clone_overlap without checking whether that clone was safe to read. Classic OSD takes a read lock on the neighbor clone via try_lock_for_read() before using it. Under snap trim + recovery stress, recovery could clone_range from a clone that snap trim was modifying, producing wrong object content (ceph_test_rados: incorrect buffer at pos 1462272). calc_clone_subsets() and calc_head_subsets() now return clone overlap candidates in preference order only. ReplicatedRecoveryBackend locks the first usable neighbor clone from each list and holds those read locks until push/pull recovery completes. RecoveryCloneLockManager releases locks in its destructor so move-assign cannot leak a held lock and block snap trim. Fixes: https://tracker.ceph.com/issues/76499 Signed-off-by: Kautilya Tripathi <[email protected]>
Matan-B
left a comment
There was a problem hiding this comment.
Great work!
Can we add coverage in test/crimson/test_calc_subsets.cc for the new candidate-plan behavior?
tchaikov
left a comment
There was a problem hiding this comment.
the fix looks right, so lgtm.
for a follow-up: the lock lifecycle is ported straight from classic, but crimson's tri_mutex lets it be simpler than classic can be.
classic's ObcLockManager is deliberately not RAII, its dtor asserts locks.empty(). it has to be manual, because release_object_locks() requeues the recovery / snap-trim / client ops that were blocked on the lock (queue_recovery(), TrimWriteUnblocked, requeue_ops()), and that needs PG context which a dtor doesn't have. so classic releases explicitly at every exit and asserts-empty to catch a missed one.
crimson's read unlock has no such side effect. tri_mutex::unlock_for_read() decrements and calls wake(), and seastar reschedules the blocked fibers itself. no requeue, no PG context. that's what RecoveryCloneLockManager's dtor comment already notes, and it means the read lock is dtor-safe here in a way it never is in classic.
so the explicit release_locks() at six sites, plus the dtor as a backstop, aren't needed. make the clone locks an RAII member of PushInfo/PullInfo and let destruction release them. to free the clone before the recovering entry is torn down, capture the guard in the completion continuation (.finally([locks = std::move(...)]{})) instead of releasing by hand. recalc_subsets then becomes a reassignment of the lock collection, which releases the old locks, rather than a release-then-reacquire.
on the mechanics: ObjectContextLoader::state_t already models a single obc RAII lock (obc + state + release_lock, move-only). it only lacks a sync try-read, it has lock_excl_sync() and the async blocking lock_to(RWREAD), but no non-blocking read acquire. that's one method next to lock_excl_sync:
// state_t
bool try_lock_for_read() {
if (obc->lock.try_lock_for_read()) {
state = RWState::RWREAD;
return true;
}
return false;
}with that, recovery holds a std::vector<Manager> (at most two clones, older + newer), and RecoveryCloneLockManager plus the new ObjectContext::try_get_read_lock/put_read_lock go away.
happy to take this as a follow-up so it doesn't hold up this PR. the one thing to confirm while doing it: the recovering entry is destroyed on every completion and error path, since that becomes the release boundary.
|
the reason why i propose RAII + Manager is because that the machinery introduced in this pull request is a parallel lock manager where crimson already has. but this is but a nit, so i can take care of it after this change lands. |
|
merging since qa is passing |
created #70085 |
Crimson calc_clone_subsets() and calc_head_subsets() could use a neighbor clone as a clone_subset source during recovery without checking whether that clone was safe to read. Classic OSD takes a read lock on the neighbor clone via try_lock_for_read() before using it for osd_recover_clone_overlap.
Under snap trim + recovery stress, recovery could clone_range from a clone that snap trim was modifying, producing wrong object content (ceph_test_rados: incorrect buffer at pos 1462272).
Add RecoveryCloneLockManager and wire it through replicated recovery so neighbor clones are only selected when a read lock can be taken, and hold those locks until push/pull recovery completes.
Fixes: https://tracker.ceph.com/issues/76499
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.