Skip to content

rgw/multisite: rgw meta sync version check - #71058

Open
SaravananPalanisamyRWTH wants to merge 4 commits into
ceph:mainfrom
SaravananPalanisamyRWTH:wip-79311-rgw-meta-sync-version-check
Open

SaravananPalanisamyRWTH wants to merge 4 commits into
ceph:mainfrom
SaravananPalanisamyRWTH:wip-79311-rgw-meta-sync-version-check

Conversation

@SaravananPalanisamyRWTH

@SaravananPalanisamyRWTH SaravananPalanisamyRWTH commented Aug 14, 2026 •

Copy link
Copy Markdown

Incremental metadata sync spawns one coroutine per mdlog entry. This could cause race condition in two concurrent udpates on multisite sync.

`check_versions()` function is reintroduced (added in 4f9855e and removed in 8c56a23).
  • Incremental sync applies entries with APPLY_UPDATES, so RGWMetadataManager::put() compares the incoming version against the one on disk and returns STATUS_NO_APPLY for entries that are not newer.
  • Full sync currently keeps APPLY_ALWAYS
  • It also handles APPLY_NEWER, used by the admin REST metadata PUT
  • the unused APPLY_EXCLUSIVE is dropped.

Serialize metadata sync for each key within a shard (Similar to data sync commit e08eb9c), allowing one coroutine at a time. When more entries of same keys arrive concurrently, it trigger a retry of the coroutine, which will fetch master's latest update.

If the retry fetches the version already applied, the redudant apply is skipped.

Issue Tracker: https://tracker.ceph.com/issues/79311

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 August 14, 2026 09:54
@SaravananPalanisamyRWTH SaravananPalanisamyRWTH changed the title Wip 79311 rgw meta sync version check rgw/multisite: rgw meta sync version check Aug 14, 2026
Comment thread src/rgw/driver/rados/rgw_metadata.h Resolved
Comment thread src/rgw/driver/rados/rgw_metadata.h Resolved
Comment thread src/rgw/rgw_metadata.cc Resolved
Comment thread src/rgw/rgw_metadata.cc Resolved
Comment thread src/rgw/driver/rados/rgw_metadata.h Resolved
Comment thread src/test/rgw/rgw_multi/tests.py Resolved
@SaravananPalanisamyRWTH
SaravananPalanisamyRWTH force-pushed the wip-79311-rgw-meta-sync-version-check branch from 427d38a to 57b3ba4 Compare September 15, 2026 08:57
@cbodley
cbodley requested review from smanjara and removed request for smanjara September 15, 2026 13:12
@cbodley

cbodley commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

it looks like some commits may have disappeared here, but i'll add my 2c anyway. as i mentioned in discussion of https://tracker.ceph.com/issues/80389#note-3, i'm skeptical that we ever want to compare cls versions across zones

  1. for read-after-write consistency on secondary zones, requests like PutBucket* are forwarded to the master zone first and then applied locally - so both the master zone and secondary zone increment their versions. most of the time, we expect both zones to produce the exact same contents of that metadata. but some ops may have bugs or limitations, or config options may differ between the zones and lead to inconsistency. so we rely on metadata sync to eventually update the secondary with the master's result, even if both zones have the same cls_version number

  2. bucket reshards are one common example of local writes to bucket instance metadata that can lead to cls_version skew. so several reshards on a secondary zone could cause metadata sync to skip several other updates to that bucket metadata from the master

  3. even on a single zone, cls_version numbers can only be compared if the tag matches. some operations may use generate_new_write_ver() to overwrite metadata with a new tag/version. i see one example of this on the bucket entrypoint metadata in RGWBucketCtl::do_store_linked_bucket_info(). if metadata sync has to compare versions with two different tags, how would it tell which is newer?


we may be better off finding a way to prevent metadata sync from racing with itself in the first place. that's happening within a single radosgw process, so we'd just need to track outstanding calls to RGWMetaSyncSingleEntryCR in memory

for example: if we're processing the mdlog and see a metadata key that's already in progress, skip it but set a flag on the existing RGWMetaSyncSingleEntryCR. after RGWMetaSyncSingleEntryCR finishes, it would check that flag to see whether it should retry - and if RGWReadRemoteMetadataCR returns the same version as before, it can skip the RGWMetaStoreEntryCR

@smanjara

Copy link
Copy Markdown
Contributor

we may be better off finding a way to prevent metadata sync from racing with itself in the first place. that's happening within a single radosgw process, so we'd just need to track outstanding calls to RGWMetaSyncSingleEntryCR in memory

this sounds like a good approach.

for example: if we're processing the mdlog and see a metadata key that's already in progress, skip it but set a flag on the existing RGWMetaSyncSingleEntryCR. after RGWMetaSyncSingleEntryCR finishes, it would check that flag to see whether it should retry - and if RGWReadRemoteMetadataCR returns the same version as before, it can skip the RGWMetaStoreEntryCR

just one thing to add - skipping an entry makes it easy to get the marker tracker wrong, so we should be explicit about handling that. the retry flag can probably live on the tracker rather than on the CR. bucket sync in rgw_data_sync.cc already does this with RGWSyncShardMarkerTrack::set_need_retry() and try_update_high_marker(), and metadata sync uses the same base class. reuse that so a skipped entry still advances the shard marker correctly.

@SaravananPalanisamyRWTH
SaravananPalanisamyRWTH force-pushed the wip-79311-rgw-meta-sync-version-check branch from 57b3ba4 to 0ac035b Compare September 16, 2026 22:01
@SaravananPalanisamyRWTH
SaravananPalanisamyRWTH marked this pull request as draft September 16, 2026 22:03
@SaravananPalanisamyRWTH

SaravananPalanisamyRWTH commented Sep 16, 2026 •

Copy link
Copy Markdown
Author

we may be better off finding a way to prevent metadata sync from racing with itself in the first place. that's happening within a single radosgw process, so we'd just need to track outstanding calls to RGWMetaSyncSingleEntryCR in memory

this sounds like a good approach.

for example: if we're processing the mdlog and see a metadata key that's already in progress, skip it but set a flag on the existing RGWMetaSyncSingleEntryCR. after RGWMetaSyncSingleEntryCR finishes, it would check that flag to see whether it should retry - and if RGWReadRemoteMetadataCR returns the same version as before, it can skip the RGWMetaStoreEntryCR

just one thing to add - skipping an entry makes it easy to get the marker tracker wrong, so we should be explicit about handling that. the retry flag can probably live on the tracker rather than on the CR. bucket sync in rgw_data_sync.cc already does this with RGWSyncShardMarkerTrack::set_need_retry() and try_update_high_marker(), and metadata sync uses the same base class. reuse that so a skipped entry still advances the shard marker correctly.

Thank you for the suggestion @smanjara . I had already considered this approach and implemented it using the existing RGWSyncShardMarkerTrack

@SaravananPalanisamyRWTH
SaravananPalanisamyRWTH force-pushed the wip-79311-rgw-meta-sync-version-check branch from 0ac035b to 919d0f6 Compare September 16, 2026 22:20
@SaravananPalanisamyRWTH
SaravananPalanisamyRWTH marked this pull request as ready for review September 18, 2026 08:48
@SaravananPalanisamyRWTH
SaravananPalanisamyRWTH force-pushed the wip-79311-rgw-meta-sync-version-check branch from 919d0f6 to 48edd52 Compare September 18, 2026 11:33
Comment thread src/rgw/driver/rados/rgw_sync.cc Resolved
@SaravananPalanisamyRWTH
SaravananPalanisamyRWTH force-pushed the wip-79311-rgw-meta-sync-version-check branch 2 times, most recently from aaf2758 to f50285e Compare September 22, 2026 12:58
@SaravananPalanisamyRWTH
SaravananPalanisamyRWTH force-pushed the wip-79311-rgw-meta-sync-version-check branch 2 times, most recently from b115ca2 to 7342824 Compare September 23, 2026 09:44
Comment thread src/rgw/driver/rados/rgw_sync.cc Resolved
Comment thread src/rgw/driver/rados/rgw_sync.cc Resolved
Comment thread src/rgw/driver/rados/rgw_sync.cc Outdated
if (marker_tracker) {
marker_tracker->reset_need_retry(raw_key);
}
/* test-only: delay the fetch of a bucket.instance entry, so the fetch sees

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.

This test-only block is a bit hard to read inline. Could the "should I hold this entry?" decision be pulled into a small helper, along with the two ..._hold_taken flags (as function-local statics rather than file-scope)? The yield/wait loop has to stay here since it's part of the coroutine, but moving just the predicate + flag bookkeeping out would make operate() read more clearly and both (including the below one) injection points (..._hold and ..._fetch_hold) could share the one helper.

@smanjara smanjara Sep 24, 2026 •

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.

agreed. IMO its difficult to write tests for every single concurrency bug that we fix without the instrumentation code creep. and they should certainly not introduce new strings per test in the rgw codebase. while these are still useful in reproducing and verifying such bugs locally during development, they don't necessarily need to be checked in. i think its acceptable to just add a simple case to pause secondary, do both writes, then resume though it may not always execute in the order we want to test.

  • turn off sync on secondary
  • two user/metadata modifies (or two bucket links) on master
  • turn sync back on
  • checkpoint
  • assert equal

you are welcome to share any other testing ideas you may have. cc @cbodley

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@BBoozmen I moved the hold decision and its flags into a shared helper,meta_sync_should_hold().
@smanjara as you noted, pause/resume may not hit the order we want.
I agree that adding instrumentation for every race condition type introduce code creep. A hold between fetch and apply is the best way I know to force that order, based on the existing code: RGWMetaSyncSingleEntryCR already has delay_meta_sync_bucket_instance_store/_entrypoint_store using the same rgw_inject_delay_* options.

I'm open to another approach if you have one in mind. cc @cbodley

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.

As for the original comment (factoring out testpoints for easier read) is addressed/resolved, thank you.
Still leaving un-resolved to get @smanjara and @cbodley take on this in general how to approach testing.

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.

@SaravananPalanisamyRWTH, while Shilpa and Casey are still reviewing, would you mind running the tests in two extra configurations?

  1. without the skip commit (1+3+4): we'd expect test_stale_metadata_applied_after_concurrent_updates to pass and test_redundant_metadata_apply_skipped_on_retry to fail with 2 applies
  2. without either fix (3+4 only): we'd expect both tests to fail

The reason I'm asking: on the current base (before #71779) the objv_is_local gate is always false, so test_redundant_metadata_apply_skipped_on_retry only checks the final owner and passes even without the fix.

Rebasing onto main and asserting applies == 1 unconditionally should cover that.

The ordering also depends on a fixed sleep and a one-shot hold, so seeing each test fail consistently without its fix would confirm they really reproduce the issue rather than passing by accident.

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.

RGWMetaSyncSingleEntryCR already has delay_meta_sync_bucket_instance_store/_entrypoint_store using the same rgw_inject_delay_* options.

@SaravananPalanisamyRWTH I think the existing delay_meta_sync_bucket_instance_store sleep alone is enough to reproduce the race without the hold points. could you take a look at #73473 and see if that works for you?

the test does the same things - delay the first update, make a second update while it waits, and assert the secondary ends with the second owner. the difference is that it uses the existing fixed sleep instead of a hold, so rgw_sync doesn't need any additional test related code.

This mirrors commit e08eb9c ("rgw: don't spawn multiple concurrent
object sync for same object")

Concurrent RGWMetaSyncSingleEntryCR coroutines for the same key can
apply mdlog entries out of order. Track each in-flight key by mapping
key->marker in the shard's marker tracker. If sync receives another
entry of the same key concurrently, set the retry flag instead of
starting a new coroutine resulting in contention

Fixes: https://tracker.ceph.com/issues/79311
Signed-off-by: Saravanan Palanisamy <[email protected]>
A retry for a key already in-flight can re-fetch the same remote state
twice. Track the applied version and skip the redundant store when
fetched obj version matches the incoming version.

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

Signed-off-by: Saravanan Palanisamy <[email protected]>
Add two test-only hold to metadata sync of a single entry. Both can be
released by clearing rgw_inject_delay_pattern.

delay_meta_sync_bucket_instance_fetch_hold - test a redundant update by
delaying the inital fetch until a newer update for the same key is
queued. The newer state is then applied, and the queued retry skips the
store after version check find its already applied.

delay_meta_sync_bucket_instance_hold - hold a fetched entry between
fetch and apply, so that a test can have a later updated applied first
and stale one lands on top.

Tests: https://tracker.ceph.com/issues/79311
Signed-off-by: Saravanan Palanisamy <[email protected]>
1. tests stale metadata applied after concurrent update, such that newer
   update is applied first. It checks whether newer one persists

2. test queued retry fetching redundant metadata version is not applied again

Tests: https://tracker.ceph.com/issues/79311
Signed-off-by: Saravanan Palanisamy <[email protected]>
@SaravananPalanisamyRWTH
SaravananPalanisamyRWTH force-pushed the wip-79311-rgw-meta-sync-version-check branch from 7342824 to 101396b Compare October 27, 2026 07:54
@RaminNietzsche

Copy link
Copy Markdown
Member

Ceph PR triage — related open PRs

Queried #71058 against KB snapshot 2026-11-10T06:02:21 in 0.3s.
Signals are candidates for human review, not merge blockers.

Category Confidence Other PR(s) Note
competing-fix medium #73473 different authors, same tracker ticket, overlapping code; text sim 0.552; file Jaccard 0.33; 2 overlapping hunks; same tracker 79311; authors SaravananPalanisam

This comment is updated in place when the workflow re-runs (hidden HTML marker). Data: read-only GitHub + local git analysis; no labels or merges were changed.

@@ -1935,10 +2035,16 @@ class RGWMetaSyncShardCR : public RGWCoroutine {
continue;
}
tn->log(20, SSTR("log_entry: " << log_iter->id << ":" << log_iter->section << ":" << log_iter->name << ":" << log_iter->timestamp));
if (!marker_tracker->start(log_iter->id, 0, log_iter->timestamp)) {
raw_key = log_iter->section + ":" + log_iter->name;
if (!marker_tracker->index_key_to_marker(raw_key, log_iter->id)) {

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.

Should this only index COMPLETE entries (mdlog_entry.log_data.status == MDLOG_STATUS_COMPLETE && ...), same as bucket sync does before index_key_to_marker() (rgw_data_sync.cc ~5102)?

Non-COMPLETE entries return before the retry loop, so if a COMPLETE entry for the same key gets skipped while a non-COMPLETE one is in flight, its retry is cleared and the update never gets applied.

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.

7 participants