Skip to content

osd/SnapMapper::update_snaps() to handle a missing OBJ_ record - #68707

Merged
ronen-fr merged 1 commit into
ceph:mainfrom
ronen-fr:wip-rf-smapper-addoid
May 6, 2026
Merged

ronen-fr merged 1 commit into
ceph:mainfrom
ronen-fr:wip-rf-smapper-addoid

Conversation

@ronen-fr

@ronen-fr ronen-fr commented May 1, 2026 •

Copy link
Copy Markdown
Contributor

Update_snaps() to handle a missing OBJ_ record
by falling back to add_oid() instead of silently creating an
inconsistent state (OBJ_ without matching SNA_ entries). This
was observed on replicas that had recently recovered objects:
the snap mapper entries created during recovery were not visible
to a subsequent snap-trim repop's update_snaps() call, leaving
the clone with no snap mapper entries. Scrub would then detect
and report the inconsistency as an error.

Promote snap mapper remove_oid/clear_snaps logging to dout(10)
and add apply_op_stats tracing to aid diagnosis of any remaining
stat or snap mapper drift.

Details:

add_oid() always creates both OBJ_ and SNA_ entries.
update_snaps() only diffs against existing SNA_ entries.
When there are no existing entries, update_snaps() must
delegate to add_oid() to avoid the OBJ_/SNA_ inconsistency.

Take https://pulpito.ceph.com/rfriedma-2026-04-30_04:51:15-rados:thrash-wip-rf-stqlength-distro-default-trial/187081/
as an example. Bug scenario:

Snap Mapper Bug: Missing SNA_ entries after recovery + snap-trim
================================================================

Object: clone :138 of trial17148508-43
Snaps at recovery time: {134, 130}
Snap-trim arrives for snap 134, leaving {130}

Snap mapper stores two types of keys:
  OBJ_<oid>       → set of snapids for this clone
  SNA_<snap>_<oid> → reverse index (snap → clone)


BEFORE THE FIX
==============

1. Recovery pushes clone :138 to new replica
   on_local_recover() → add_oid(:138, {134, 130})

   OBJ_:138       = {134, 130}    ← written to transaction A
   SNA_134_:138   = (exists)      ← written to transaction A
   SNA_130_:138   = (exists)      ← written to transaction A

   Transaction A is submitted to BlueStore (commits asynchronously).

2. Transaction A commits. MapCacher cache entries released.

3. Snap-trim repop arrives (trim snap 134 → new snaps {130})
   update_snap_map() → update_snaps(:138, {130})

   get_snaps(:138) → ENOENT       ← OBJ_ key not found (*)

   update_snaps proceeds with out.snaps = {}:

   OBJ_:138       = {130}         ← set_snaps() overwrites with new value
   SNA_ removals  = (none)        ← loop over out.snaps is empty, nothing to remove
   SNA_ additions = (none)        ← update_snaps NEVER creates SNA_ entries

   Result after transaction B commits:

   OBJ_:138       = {130}         ✓ correct
   SNA_134_:138   = ???           ? may or may not survive from txn A
   SNA_130_:138   = ???           ? may or may not survive from txn A

   (*) Root cause of ENOENT is under investigation.
       The OBJ_ key written by transaction A is not visible
       to transaction B's get_snaps() read.

4. Scrub runs, checks consistency:

   OBJ_:138 says snaps = {130}
   Looks up SNA_130_:138 → NOT FOUND

   ══════════════════════════════════════════
   INCONSISTENCY: OBJ_ and SNA_ disagree
   → logs [ERR], triggers PG_DAMAGED
   ══════════════════════════════════════════

With this fix:

1–2. Same as above.

3. Snap-trim repop arrives (trim snap 134 → new snaps {130})
   update_snap_map() → update_snaps(:138, {130})

   get_snaps(:138) → ENOENT       ← same situation

   NEW CODE PATH: ENOENT detected, fall back to add_oid(:138, {130})

   add_oid creates BOTH key types:

   OBJ_:138       = {130}         ← set_snaps()
   SNA_130_:138   = (exists)      ← backend.set_keys()

   Result after transaction B commits:

   OBJ_:138       = {130}         ✓ correct
   SNA_130_:138   = (exists)      ✓ correct

4. Scrub runs, checks consistency:

   OBJ_:138 says snaps = {130}
   Looks up SNA_130_:138 → FOUND

   ══════════════════════
   CONSISTENT — no error
   ══════════════════════

@github-actions github-actions Bot added the core label May 1, 2026
@ronen-fr
ronen-fr requested a review from Matan-B May 1, 2026 05:19
@ronen-fr
ronen-fr force-pushed the wip-rf-smapper-addoid branch from 154769f to 9265eeb Compare May 1, 2026 07:53
@ronen-fr
ronen-fr marked this pull request as ready for review May 1, 2026 07:53
@ronen-fr
ronen-fr requested a review from a team as a code owner May 1, 2026 07:53

@Matan-B Matan-B 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.

lgtm

Comment thread src/osd/SnapMapper.cc Outdated
@@ -589,6 +589,13 @@ int SnapMapper::update_snaps(
// Tolerate missing keys but not disk errors
if (r < 0 && r != -ENOENT)
return r;
if (r == -ENOENT) {
// no existing mapping — create from scratch

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.

nit, more verbose version. wdyt?

// Recently recovered replicas may observe missing snap-mapper state.
// Avoid creating an inconsistent state (OBJ_ without matching SNA_ entries) that
// would be detected by scrub later on - instead rebuild the mapping from scratch.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nice. Will add.

@ronen-fr
ronen-fr force-pushed the wip-rf-smapper-addoid branch 3 times, most recently from 37cf251 to d1b041e Compare May 5, 2026 03:39
by falling back to add_oid() instead of silently creating an
inconsistent state (OBJ_ without matching SNA_ entries). This
was observed on replicas that had recently recovered objects:
the snap mapper entries created during recovery were not visible
to a subsequent snap-trim repop's update_snaps() call, leaving
the clone with no snap mapper entries. Scrub would then detect
and report the inconsistency as an error.

Promote snap mapper remove_oid/clear_snaps logging to dout(10)
and add apply_op_stats tracing to aid diagnosis of any remaining
stat or snap mapper drift.

Signed-off-by: Ronen Friedman <[email protected]>
@ronen-fr

ronen-fr commented May 5, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test windows

@ronen-fr

ronen-fr commented May 5, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

@ronen-fr

ronen-fr commented May 6, 2026

Copy link
Copy Markdown
Contributor Author

Passed Teuthology tests (multiple branch names. Latest: wip-rf-smapper-addoid-again).
I will be merging, once the CI tests are OK.

@ronen-fr

ronen-fr commented May 6, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test windows

@ronen-fr
ronen-fr force-pushed the wip-rf-smapper-addoid branch from d1b041e to ac06cb5 Compare May 6, 2026 04:19
@ronen-fr
ronen-fr merged commit 9bd2e14 into ceph:main May 6, 2026
6 checks passed
@ronen-fr

ronen-fr commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

A post-merge comment:
See https://tracker.ceph.com/issues/76458 for the reason why this issue started appearing frequently in Crimson runs. Basically - the snap-mapper in-transit cache was being deleted (and not flushed) on PG splits.
A separate PR would address that problem.

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.

2 participants