Skip to content

rgw: skip writing ObjectCache when incoming obj_version is stale - #69748

Merged
anrao19 merged 4 commits into
ceph:mainfrom
SaravananPalanisamyRWTH:wip-77554-race-condition-in-cache-write
Aug 7, 2026
Merged

anrao19 merged 4 commits into
ceph:mainfrom
SaravananPalanisamyRWTH:wip-77554-race-condition-in-cache-write

Conversation

@SaravananPalanisamyRWTH

@SaravananPalanisamyRWTH SaravananPalanisamyRWTH commented Jun 25, 2026 •

Copy link
Copy Markdown

Problem:

ObjectCache::put() always overwrites a cached entry without checking if a newer version is already stored. When two updates for the same key arrive nearly simultaneously, last write wins.

The cache serves stales data for upto rgw_cache_expiry_interval

Fix:

Guard ObjectCache::put(), if both the existing and incoming entries carry CACHE_FLAG_OBJV with the same tag, skip the write when the incoming ver is lower than the cached ver. Different tags (object recreated) and missing CACHE_FLAG_OBJV bypass the guard.

Fixes: https://tracker.ceph.com/issues/77554

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.

@SaravananPalanisamyRWTH
SaravananPalanisamyRWTH requested a review from a team as a code owner June 25, 2026 19:24
@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.

@cbodley cbodley changed the title Wip 77554 race condition in cache write rgw: skip writing ObjectCache when incoming obj_version is stale Jun 29, 2026

@cbodley cbodley 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.

Comment thread src/rgw/rgw_cache.cc Resolved
Comment thread src/rgw/rgw_cache.cc Resolved
@smanjara

Copy link
Copy Markdown
Contributor

@SaravananPalanisamyRWTH thank you. would you mind adding the multisite reproducer as a test in tests.py? some of the necessary methods for creating users, buckets etc. are already there.

@SaravananPalanisamyRWTH
SaravananPalanisamyRWTH force-pushed the wip-77554-race-condition-in-cache-write branch from e57ec59 to 532676f Compare June 30, 2026 08:44
@SaravananPalanisamyRWTH

Copy link
Copy Markdown
Author

@smanjara

@SaravananPalanisamyRWTH thank you. would you mind adding the multisite reproducer as a test in tests.py? some of the necessary methods for creating users, buckets etc. are already there.

Thank you for the suggestion.
However, I think the multisite test cannot reliably reproduce the exact race condition from external tests alone.

The bug requires distribute_cache notification to arrive at the cache after a new version written in it.

The unit test in src/test/rgw/test_rgw_cache.cc which simulates the scenario by calling ObjectCache::put() sequentially with a lower version after a higher one.

To deterministically trigger the stale overwrite from an integration test, I think we would need a new keyword (Eg: rgw_inject_distribute_cache_delay_ms ) in distribute_cache() similar to rgw_inject_delay_sec.
I can add rgw_inject_distribute_cache_delay_ms if you'd prefer a test that deterministically exercises the bug path. Let me know.

Comment thread src/rgw/rgw_cache.cc Resolved
Comment thread src/rgw/services/svc_sys_obj_cache.cc Resolved
Comment thread src/rgw/services/svc_sys_obj_cache.cc Resolved
ObjectCache::put() always overwrote the cache version without checking
if a newer one was already stored. Guard the write: when both the
existing and incoming entries carry CACHE_FLAG_OBJV with the same tag,
skip the put, if the incoming version is lower

Fixes: https://tracker.ceph.com/issues/77554

Signed-off-by: Saravanan Palanisamy <[email protected]>
@SaravananPalanisamyRWTH
SaravananPalanisamyRWTH force-pushed the wip-77554-race-condition-in-cache-write branch from e9da4c2 to b6fa0f4 Compare July 8, 2026 20:25
Inject a configurable sleep in distribute_cache() before the watch/notify
is sent, to hold a cache notification in-flight and reproduce timing-
sensitive races in integration tests. Reuses the shared
rgw_inject_delay_sec / rgw_inject_delay_pattern fault-injection framework
(pattern "delay_distribute_cache"). Do not use in production.

Signed-off-by: Saravanan Palanisamy <[email protected]>
@SaravananPalanisamyRWTH
SaravananPalanisamyRWTH force-pushed the wip-77554-race-condition-in-cache-write branch from b6fa0f4 to a6d239e Compare July 8, 2026 22:07
@smanjara
smanjara self-requested a review July 14, 2026 18:04
@anrao19

anrao19 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

This PR has been added to main integration testing by anuchaithra started 2026-07-17-06:18.

@anrao19

anrao19 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

This PR has been added to main integration testing by anuchaithra started 2026-07-17-06:18.

pr testing completed and approved by @ivancich

@anrao19

anrao19 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

jenkins test make check

@anrao19

anrao19 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

jenkins test make check arm64

@yuvalif

yuvalif commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

jenkins test signed

@yuvalif

yuvalif commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

jenkins test submodules

@BBoozmen

BBoozmen commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

@SaravananPalanisamyRWTH / @smanjara / @cbodley -> this one might be causing a regression for our multisite tests: please see Bug #80389 qa/rgw/multisite - multiple testcase failures: ObjectCache::put() obj_version guard can leave the cache ahead of RADOS on secondary zones, stalling metadata sync for rgw_cache_expiry_interval for details. These 3 testcases failed in an un-related (not multisite related) testing of mine.

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.

8 participants