Skip to content

rgw/multisite: fix metadata sync of past periods - #72670

Open
lumir-sliva wants to merge 5 commits into
ceph:mainfrom
lumir-sliva:rgw-multisite-meta-sync-past-period-bids
Open

lumir-sliva wants to merge 5 commits into
ceph:mainfrom
lumir-sliva:rgw-multisite-meta-sync-past-period-bids

Conversation

@lumir-sliva

Copy link
Copy Markdown
Contributor

Two bugs in how a secondary catches up on past periods after a master change. Both leave metadata missing on the zone while sync status reports it caught up.

More than 100 entries behind on a shard (first commit). RGWMetaSyncShardCR::incremental_sync() leaves a past period when period_marker <= mdlog_marker. But RGWCloneMetaLogCoroutine clones the remote shard up to its tip and moves mdlog_marker there, while each pass applies at most 100 entries. So on the second pass the period ends and everything after the first batch is never applied. Compare against max_marker, the position actually read, instead. This dates back to 574ff5f (2017).

The second commit adds test_multi_period_incremental_sync_backlog: the third zone is down while the master moves, 150 buckets are created whose mdlog entries all hash to the same shard, and after the master moves back the third zone must have all of them. It works with the default shard count. Without the fix it fails (3 of 3; 50 of 150 buckets missing), with it it passes (3 of 3). It takes about 8 minutes, most of it the two master changes and the checkpoints.

More than one gateway running the sync thread (third commit). RGWMetaSyncCR advances to the next period only once every shard of the past period completed in the same process. RGWMetaSyncShardCR returns -EBUSY for a shard this gateway doesn't hold the bid for (#45958), before the "finished syncing current period" check, and RGWBackoffControlCR retries that forever. So a gateway only gets out if it wins the bid on every shard, and with more than one sync gateway the secondary stays on the old period for good.

The fix:

  • a gateway that loses the bid on a past-period shard, or wins it but can't take the lease because another gateway holds it while syncing that shard in a later period, reads the shard marker from rados and treats the shard as done if the owner already reached the period marker or a later realm epoch;
  • the owner writes that marker when it finishes a past period, while it still holds the lease. That part is needed because a shard can finish a period without applying anything, in which case the marker tracker never writes (compare https://tracker.ceph.com/issues/55770). If the lease ran out while the last entries drained, the owner retries the period instead, and it never moves a marker that's already on a later realm epoch back;
  • a gateway that takes the lease with a stale marker checks the stored one first and finishes the shard without replaying the period.

This end-of-period write is why the first commit comes first: it is based on the position actually read.

Every gateway now advances through past periods on its own, and each writes the unversioned sync info, so one that finishes a period later can store an earlier, still valid period over a later one until it catches up. It's in the commit message; happy to switch that write to a version-checked one if you'd rather. The fix only fully applies once every gateway running the sync thread in the zone has it.

Tested with test_multi_period_incremental_sync (3 zones, 2 gateways per zone), which reproduces the multi-gateway stall once https://tracker.ceph.com/issues/80439 (#71707), https://tracker.ceph.com/issues/81760 and https://tracker.ceph.com/issues/81758 are fixed:

An earlier version of the third commit also passed 3 of 3 failover/failback runs on two tentacle 20.2.4 clusters with 4 sync gateways per zone.

Teuthology runs one gateway per zone, so the multisite suite can't hit the second bug; the existing test does with gateways_per_zone = 2 in the test config.

Fixes: https://tracker.ceph.com/issues/81759
Fixes: https://tracker.ceph.com/issues/81762

Backport: squid, tentacle.

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)
    • Includes unit test(s)
    • Includes integration test(s)
    • Includes bug reproducer
    • No tests

@lumir-sliva
lumir-sliva requested a review from a team as a code owner October 14, 2026 10:07
@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@github-actions

Copy link
Copy Markdown

Thank you for your contribution. Since you are not yet a member of the Ceph organization with write permissions on ceph/ceph.git, our CI will not automatically run. Any member of the Ceph organization may label this PR ci-approved to allow Jenkins CI jobs to run.

RGWMetaSyncShardCR::incremental_sync() leaves a past period when
period_marker <= mdlog_marker. mdlog_marker starts at our sync position,
but RGWCloneMetaLogCoroutine then clones the remote mdlog shard up to its
tip (it loops while the listing is truncated) and moves mdlog_marker
there, while each pass of the loop reads and applies at most
INCREMENTAL_MAX_ENTRIES (100) of the cloned entries.

So when a zone is more than 100 entries behind on a shard at the end of
a period (a zone that was down while the master moved), the first pass
applies 100 entries, the clone has already moved mdlog_marker past
period_marker, and the second pass declares the period done: the rest of
that period's entries on the shard are never applied. Users, buckets and
other metadata created in that period are missing on the zone, with no
error, and sync status reports it caught up.

Compare period_marker with max_marker, the position we've read up to.
Both start at the sync position, so a period that was already finished
still ends on the first pass; reaching period_marker while applying
entries ends it as before.

Fixes: https://tracker.ceph.com/issues/81759
Signed-off-by: Lumir Sliva <[email protected]>
Stop the third zone, move the metadata master to the second zone, create
150 buckets whose mdlog entries all hash to the same shard, move the
master back and start the third zone. Metadata sync reads a shard in
batches of 100 entries, so the third zone has to walk more than one batch
of the past period on that shard. It must end up with every bucket.

Fixes: https://tracker.ceph.com/issues/81759
Signed-off-by: Lumir Sliva <[email protected]>
…eway

RGWMetaSyncCR walks the period history one period at a time and only
advances once every shard of the past period has completed in this
process. RGWMetaSyncShardCR returns -EBUSY right away when this gateway
isn't the highest bidder for the shard, in both full_sync() and
incremental_sync(), before it gets to the "finished syncing current
period" check, and RGWBackoffControlCR retries that forever. With more
than one gateway running the sync thread, a gateway only leaves a past
period if it wins the bid for every shard that period has, so after a
master change and failback, metadata sync on the secondary stays on the
old period for good while "sync status" reports it caught up.

When a gateway loses the bid on a past-period shard, or wins it but
can't take the lease because another gateway holds it (that one keeps
the lease while it syncs the shard in a later period), read the shard
marker from rados and treat the shard as complete if its owner already
synced up to the period marker, or moved on to a later period.

For that to work the owner has to leave a trace. The marker tracker
only writes the shard marker when an entry gets applied, so a shard
that finishes the period without applying anything (the log holds
nothing past our position, e.g. the entries were trimmed after this
zone wrote them as master) keeps a marker from the previous realm
epoch. Have the owner write the shard marker with the period's realm
epoch and the period marker once it is done with the period, while it
still holds the lease. If the lease ran out while the last entries
were draining, retry the period instead. The write starts from the
stored marker, keeping the tracker's position and timestamp, and is
skipped when the stored marker already records the period as done or
is on a later realm epoch, so it never moves a marker back.

A gateway can also take the lease with a stale marker: it lost the bid
or the lease, another gateway finished the period and moved the shard
on, and then the bid came back to it. It checks the stored marker
right after taking the lease and finishes the shard without replaying
the period if it's already done.

Every gateway now advances through past periods on its own, and each
writes the metadata sync info when it does. That write isn't versioned,
so a gateway that finishes a period later than another can store an
earlier, still valid period over a later one. It rewrites it once it
catches up, but a gateway that restarts in between re-walks from the
earlier period.

Fixes: https://tracker.ceph.com/issues/81762
Signed-off-by: Lumir Sliva <[email protected]>
@lumir-sliva
lumir-sliva force-pushed the rgw-multisite-meta-sync-past-period-bids branch from 0c3eb9c to 9d8b4e6 Compare October 14, 2026 12:51
@lumir-sliva

Copy link
Copy Markdown
Contributor Author

@cbodley Rebased, please set the flag again. Thx

@ivancich

Copy link
Copy Markdown
Member

When this is ready for a review, please add the needs-review label, @lumir-sliva .

@lumir-sliva

Copy link
Copy Markdown
Contributor Author

When this is ready for a review, please add the needs-review label, @lumir-sliva .

I'm not a member of the org I cant set it :( its ready

RGWMetaSyncShardCR::incremental_sync() ends a past period once
max_marker, the position read from the cloned mdlog, reaches
period_marker. That never happens when the period's entries are gone:
a zone that was the master of a period doesn't sync it while it is
master, its peers sync it, and mdlog trimming removes the entries.
When the zone later becomes a secondary, it has to walk that period
with an empty sync marker. The clone still moves mdlog_marker to the
shard's last marker (the log header keeps it), but reading from
max_marker returns no entries, so max_marker never moves and the shard
clones and reads the same empty log forever. Metadata sync of the
whole zone stays on the old period and nothing created later reaches
it.

Also end the period when the clone has reached period_marker and the
last read found nothing more (truncated is false): everything that is
left of the period has been read. On the first pass mdlog_marker and
max_marker are both the sync position, so this can't end a period
earlier than before; with entries still to read, truncated stays true
until the last batch, which ends the period at period_marker as
before.

Seen on a two-zone lab after failover, failback, failover: the zone
that was master in the middle period stayed on it for good, with 0
entries in the period's log on both zones; the owning gateway's sync
trace showed the clone at period_marker, 0 entries read and an empty
max_marker on every pass.

Fixes: https://tracker.ceph.com/issues/81759
Signed-off-by: Lumir Sliva <[email protected]>
zone 2 is master of period 2 and doesn't sync it, the other zones do,
every zone trims the mdlog, then zone 1 becomes master again. zone 2
has to sync period 2 from a log without entries and must still reach
the current period and see the buckets created in periods 2 and 3.

Fixes: https://tracker.ceph.com/issues/81759
Signed-off-by: Lumir Sliva <[email protected]>
@lumir-sliva

Copy link
Copy Markdown
Contributor Author

Pushed two commits on top:

  • a8b472ec241 rgw/multisite: end a past period whose mdlog was trimmed
  • 401f96f12d4 qa/rgw/multisite: test a past period whose mdlog was trimmed

The Q fix as first posted can hang metadata sync for good. Details below: how we ran into it, the cause, the fix and what was tested.

How we found it

Our lab is two sites with two realms, each realm's master zone in one site and its secondary in the other, 4 gateways per zone, tentacle 20.2.4 + #71707 + this PR + #72669 + #72776/#72777/#72778. We were running failover drills on realm A:

  1. realm epoch 3: secondary promoted while the master's site was cut off, the old master came back as a secondary;
  2. epoch 4: failback, the original master zone is master again;
  3. epoch 5: secondary promoted again, this time with the old master's gateways stopped, then realm pull on the old master's side and its gateways started.

Step 3 was meant to check the new sync status wording from #72778 on a zone that missed a period. The wording was right, but it never changed:

metadata sync is on period 9a1f85b0-56f0-424c-a0a8-4e3ff1cc3cf8 (realm epoch 4)
master is on period 514c9183-f6d8-4bb6-9e62-0b3374e19d79 (realm epoch 5)
metadata is 1 period behind the master

A user and a bucket created on the new master never showed up on that zone; we waited 65 min and restarted all 4 gateways. Without #72778 this would have stayed hidden: the old radosgw-admin on the same state printed master is on a different period and then metadata is caught up with master.

Cause

Epoch 4 is the period in which that zone was the master. A master doesn't sync its own period; the other zone did, and mdlog trimming then removed the entries. mdlog list --period=<epoch 4> returned 0 entries on every shard on both zones, while mdlog status still had the header markers. With debug_rgw 20 on the shard owner, every pass looked the same:

meta sync: incremental_sync:2007: shard_id=17 mdlog_marker=1_1792416755.901532_1229.1 max_marker= sync_marker.marker= period_marker=1_1792416755.901532_1229.1
meta sync: remote mdlog, shard_id=17 num of shard entries: 0

The sync marker is cleared on the realm epoch change, the clone moves mdlog_marker to the shard's last marker from the header, and RGWReadMDLogEntriesCR from the empty max_marker returns nothing. The Q fix ends a past period only once max_marker reaches period_marker (rgw_sync.cc:1972 at 9d8b4e6ab71), so the shard clones and reads the same empty log forever. The old period_marker <= mdlog_marker check would have ended it.

Fix

The period now also ends when the clone has reached period_marker and the last read found nothing more (!truncated). On the first pass mdlog_marker and max_marker are both the sync position, so this can't end a period earlier than before. With entries left (the Q case), truncated stays true until the last batch, which ends at period_marker as before.

Testing

test_multi.py, main 04ba07e56c8 + this PR (same rgw_sync.cc as the head), 3 zones x 1 gateway, default mdlog shards:

  • test_multi_period_incremental_sync_trimmed (new): zone 2 is master of period 2, the other zones sync it, mdlog autotrim everywhere (the test asserts period 2's log is empty), zone 1 becomes master again.
    • with the fix: 2/2 pass (326 s, 323 s); all 5 period ends on a2 go through the new condition (max_marker= empty, mdlog_marker == period_marker);
    • fix reverted, test kept: 2/2 fail (510 s, 499 s), failed meta checkpoint for zone=a2, a2 loops with the same trace as the lab.
  • test_multi_period_incremental_sync_backlog (the Q test): 1/1 pass with the fix.

Lab, tentacle build with the fix, 4 gateways per zone:

  • the zone stuck on epoch 4 for 65 min moved to epoch 5 within ~1 min of restarting its gateways on the new build, sync status said caught up a minute later, and the user and bucket from an hour earlier arrived;
  • a failback afterwards (epoch 6) made the other zone walk epoch 5, which it had been master of: a user created on the new master reached it in 20 s, both zones caught up.

Not re-run on this head yet: test_multi_period_incremental_sync, and the qa suite with more than one gateway per zone.

Happy to squash these into the Q fix and the test commit if you'd rather keep the history flat.

@lumir-sliva

Copy link
Copy Markdown
Contributor Author

Ran what my last comment listed as not re-run, on the head (401f96f), main 04ba07e + this PR, 3 zones:

  • test_multi_period_incremental_sync, 1 gateway per zone: 2/2 pass (313 s, 323 s)
  • test_multi_period_incremental_sync, 2 gateways per zone: 2/2 pass (362 s, 362 s)
  • test_multi_period_incremental_sync_trimmed, 2 gateways per zone: 2/2 pass (314 s, 315 s)
  • test_multi_period_incremental_sync_backlog, 2 gateways per zone: 0/5, with and without the trimmed fix (2 + 2 runs, plus 1 on the head), always failed meta checkpoint for zone=a3

The backlog failure isn't in this PR. One of a3's two gateways never reloads after the zone restarts:

  • the test sleeps reconfigure_delay (5 s) after the last master change and then starts a3's gateways one after the other; the master's period pusher retries a3 at +2 s and +6 s, so the +6 s retry reaches the first gateway right after it starts
  • that gateway stores the new period, notifies the realm and reloads. The second gateway loaded the realm before that write and sets up its realm watch ~150 ms after the notify (all 5 runs), so it misses it
  • the push that then reaches the second gateway stops at "already have epoch" in RGWOp_Period_Post and returns 200, so it keeps realm epoch 2 as its current period. The past-period path in this PR never runs there; it holds the bid for half the shards, and the first gateway correctly waits for them in period 3

Startup loads the period in init_storage() and only sets up the realm watch at the end of init_frontends2(), after the frontends are up (rgw_appmain.cc:301, :619, :639). Filed as https://tracker.ceph.com/issues/81911 with the timings; fix and test in #72852 (re-read the period once the watch and handler are in place, reload if it moved).

So the backlog test here only claims 1 gateway per zone, where it passes. Happy to make it skip with more than one gateway per zone until the reload fix lands, if you'd rather not have it fail locally in that setup.

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.

3 participants