Skip to content

osd: Fix for write ordering issue caused by error injects with scrub blocked writes - #71187

Merged
ljflores merged 1 commit into
ceph:mainfrom
JonBailey1993:out_of_order_writes_fix
Sep 23, 2026
Merged

ljflores merged 1 commit into
ceph:mainfrom
JonBailey1993:out_of_order_writes_fix

Conversation

@JonBailey1993

@JonBailey1993 JonBailey1993 commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

When running tests against Ceph, I ran into a data integrity issue. When analysing the logs for the root cause, I came across the following order of events that caused it, which I will also summarise afterwards.

  • 50.59.785: replica_scrub sets m_scrubber’s m_start to 0 and m_end to MAX (Caused by scrub starting - priority set to highest because we have failed to run 5 times already due to writes).
  • 50:59.896: ScrubMachine calls ReplicaActive::exit() due to new interval
  • 50:59.896: ScrubMachine transitions to NotActive
  • ~~~~~~~~: ScrubMachine - several transitions between ReplicaActive/ReplicaIdle and NotActive. None call through to reset_internal_state.
  • 51.14.558: Read 36354 dequeued
  • 51.14.559: Write 36357 dequeued
  • 51.14.560: Write 36357 is blocked because read 36354 holds the lock for reading.
  • 51.14.563: Read 36354 completes
  • 51.14.563: Write 36357 removed from the waiters list, but blocked by scrub due to soid being between m_start and m_end, so added to the waiting_for_scrub list.
  • 51.14.565: Write 36358 dequeued. Doesn’t get blocked by scrub as scrub is not active (checks are different between the two places)
  • 51.14.669: Write 36358 completes
  • 51.15.277: ScrubMachine Destructs PrimaryActive as part of on_new_interval, which calls through to reset_internal_state which resets m_start and m_end
  • 51.15.277: Scrub Machine transitions from PrimaryActive/PrimaryIdle to NotActive Scrub reset_internal_state caused by new epoch
  • 51:16.293 Write 36357 dequeued
  • 51:16.~~~ Write 36357 completes
  • 51:18.498: Read 36411 dequeued. Read covers the 2k which 36367 overwrote 36358. Detected as a miscompare.

To summarise what happened, scrub does not appear to be cleaning up correctly on non-primary replicas/shards. This matters specifically when cleaning up the scrubber because we have a new epoch in which that PG is transitioning from a non-primary to a primary replica/shard. When this happens, the non-cleaned up state is used as part of write_blocked_by_scrub(...) to decide if a write should be blocked, which allows writes to be re-queued even though scrub is in Non-Active state for that PG. Incoming writes have an extra layer of protection, querying write_blocked_by_scrub(...) only on PGs that are actively being scrubbed, allowing incoming IOs to progress when requeued IOs are delayed, resulting in requeued IOs being overtaken.

This commit addresses this in two ways:

  • By making all calls to check if a write should be blocked by scrub consistent so they are scheduled fairly for all writes, whether requeued or straight from the client.
  • It changes the exit process of ReplicaActive so it resets the scrubber state when it destructs so that we don't have stale data held in the scrubber for replica PGs after they transition out of ReplicaActive

I have created a tracker ticket for this PR to reference here: https://tracker.ceph.com/issues/79799

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 x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

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)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@JonBailey1993
JonBailey1993 requested a review from a team as a code owner August 20, 2026 14:04
@github-actions github-actions Bot added the core label Aug 20, 2026
@rzarzynski
rzarzynski requested a review from ronen-fr August 25, 2026 19:23

@ronen-fr ronen-fr 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.

The cleaning function must be replica_handling_done().
And - please add a detailed comment explaining the specific race condition
(the start-replica vs new-interval that necessitated the change)

Comment thread src/osd/scrubber/scrub_machine.cc Resolved
Scrub does not appear to be cleaning up correctly on non-primary replicas/shards.
This matters specifically when cleaning up the scrubber because we have a new
epoch in which that PG is transitioning from a non-primary to a primary
replica/shard. When this happens, the non-cleaned up state is used as part of
write_blocked_by_scrub(...) to decide if a write should be blocked, which allows
writes to be re-queued even though scrub is in Non-Active state for that PG.
Incoming writes have an extra layer of protection, querying
write_blocked_by_scrub(...) only on PGs that are actively being scrubbed,
allowing incoming IOs to progress when requeued IOs are delayed, resulting in
requeued IOs being overtaken.

This commit addresses this in two ways:
* By making all calls to check if a write should be blocked by scrub consistent
  so they are scheduled fairly for all writes, whether requeued or straight from
  the client.
* It changes the exit process of ReplicaActive so it resets the scrubber state
  when it destructs so that we don't have stale data held in the scrubber for
  replica PGs after they transition out of ReplicaActive

Signed-off-by: Jon Bailey <[email protected]>
Assisted-by: IBM Bob 2.0.4

@ronen-fr ronen-fr 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

@ronen-fr

Copy link
Copy Markdown
Contributor

I think this should be backported to the last 3 versions.

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been added to wip-bharath10-testing-20260910.230227-main.

@JonBailey1993

Copy link
Copy Markdown
Contributor Author

I think this should be backported to the last 3 versions.

Umbrella, Tentacle and Squid are still in support and I plan on opening backports for them once this issue has merged

@connorfawcett

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants