Skip to content

rgw: reload when the period changed while the gateway started - #72852

Open
lumir-sliva wants to merge 3 commits into
ceph:mainfrom
lumir-sliva:rgw-realm-reload-startup
Open

lumir-sliva wants to merge 3 commits into
ceph:mainfrom
lumir-sliva:rgw-realm-reload-startup

Conversation

@lumir-sliva

@lumir-sliva lumir-sliva commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A radosgw that is still starting when a new period reaches its zone can miss the realm reload and keep running the old period until it's restarted. With more than one gateway per zone, another gateway takes the period push, stores it and notifies, while the starting one isn't watching the realm yet. If the change made the starting gateway's zone the master, the zone that was master before never hears about it either.

Problem

Startup order (rgw_appmain.cc at ce66551):

  • init_storage() loads the realm and its current period (site.load(), line 301). The gateway runs with that period until its next reload.
  • init_frontends2() starts the frontends (line 619), so the gateway already takes requests, period pushes included.
  • Only then is the realm watch set up (create_realm_watcher(), line 639, watch2() in realm_watcher.cc:101), and the period pusher and the reload handler are added after that (add_watcher(...), lines 642 and 661).

A period change in between is stored in rados but doesn't reload this gateway:

  • a notify before watch2() reaches no watcher;
  • one between watch2() and add_watcher() finds no handler and is dropped: "Failed to find a watcher for notify type 1" (realm_watcher.cc:64);
  • a later push of the same period stops at "already have epoch" in RGWOp_Period_Post (rgw_rest_realm.cc:172-178) and returns 200 without notifying.

RGWRealmReloader::reload() already guards against this for a reload in progress (rgw_realm_reloader.cc:110, "or we could miss some updates"); startup doesn't.

The notify carries two things, ZonesNeedPeriod for the period pusher and Reload for the reloader (driver/rados/config/realm.cc, realm_notify_new_period). Both are lost. The pusher built in init_frontends2() reads the period the driver started with (rgw_period_pusher.cc:177), so when the change in the window promoted this zone to master, nobody pushes the new period to the old master: it keeps running as master until the next commit.

Found with test_multi_period_incremental_sync_backlog from #72670 at 3 zones x 2 gateways: 5 of 5 runs fail because one of zone 3's gateways never reloads after the zone restarts. The test sleeps reconfigure_delay (5 s) and starts zone 3's gateways one after the other, and the master's period pusher retries at +2 s and +6 s, so the +6 s retry lands between the two starts every time.

Fix

Once the last init step is done, AppMain::reload_if_period_changed() reads the realm's current period and its latest epoch again. If either differs from what init_storage() loaded, it does what the lost notify would have done, in the same order: it hands the period to the period pusher, which sends it on to the zones that still need it when this zone is its master, and schedules a reload. A zone that the current period did not contain yet runs on its local zonegroup, which is how a new zone starts out; for it, the check reloads once the current period contains the zone. The epoch matters too: an epoch-only change (a zonegroup or zone modify) goes through the reflect path and notifies the same way.

The check runs from main() and RGWLib::init() after the last init step, not inside init_frontends2(), because the reload replaces env.driver and RGWLib::init() still runs init_lua() and init_dedup() against it after init_frontends2() returns. It compares against a record of what init_storage() loaded rather than against the site configuration, which a reload that a notify triggered in the meantime may already be rewriting; if such a reload already loaded the new period, the check schedules one more, which is harmless. RGWRealmReloader::schedule_reload() is split out of handle_notify() for this, and the reloader keeps its CephContext instead of reading it through env.driver.

The second commit adds rgw_inject_delay_pattern=delay_realm_watch, which holds a starting gateway with its frontends up but before it watches the realm, until the pattern is cleared or rgw_inject_delay_sec elapses.

Test

Two tests in rgw_multi/tests.py. Both hold zone 2's gateways with delay_realm_watch, change the period while they are held, and clear the pattern to let them continue:

  • test_period_change_during_gateway_startup: zone 2's redirect_zone is set to zone 1. Each held gateway must still answer NoSuchKey for an object only zone 1 has, which shows the commit landed in the window; released, each must reload and answer 301.
  • test_master_change_during_gateway_startup: zone 2 is made the master, committed on its own cluster. Zone 1's cluster must still have the old period while zone 2 is held; released, zone 2's gateways must send the new period on, and zone 1's cluster must have it within 60 s.

Both work with one gateway per zone. main 04ba07e + this PR (same diff as the branch), vstart, test_multi.py, 3 zones:

test gateways per zone result
test_period_change_during_gateway_startup 1 2/2 pass (215 s, 216 s)
test_period_change_during_gateway_startup 2 1/1 pass (229 s)
test_master_change_during_gateway_startup 1 2/2 pass (91 s, 89 s)
test_master_change_during_gateway_startup 2 1/1 pass (97 s)
both, then test_multi_zone_redirect, one run 1 3/3 pass (358 s)
test_period_change_during_gateway_startup, recheck disabled 1 fails: still on the old period (got NoSuchKey, expected 301)
test_master_change_during_gateway_startup, pusher replay removed 1 fails: zone 1 never got the period that made zone 2 the master

New-zone case, scripted: two clusters, zone zg1-3 created on the second one without a commit, its gateway started held, the period that adds the zone committed, gateway released. With the fix the gateway logs realm's current period ... now contains zone zg1-3, it did not while starting up, reloading and an object written to the master afterwards is readable through it 15 s later. Without the recheck it never reloads and the object stays unreadable (AccessDenied, no metadata sync on the local zonegroup) until the next period commit.

Also reproduced without the injection point, with gdb holding one of two gateways of the secondary zone (non-stop mode, only the main thread halted) while redirect_zone is committed, 2 zones x 2 gateways:

held at main 04ba07e + this PR
rgw::AppMain::init_frontends2 (before frontends and watch) NoSuchKey, still after 60 s 301
RGWPeriodPusher constructor (after watch2(), before handlers) NoSuchKey, still after 60 s 301
not held (control) 301

And on a tentacle 20.2.4 multisite cluster with two zones of four gateways each: one master-zone gateway restarted held before its realm watch, period update --commit while held (epoch bump), released. With the delay point only it stays on the old epoch, no reload. With this PR:

rgw main: realm's current period changed from 306bc61f-...:4 to 306bc61f-...:5 while starting up, reloading
rgw period pusher: Zone master pushing period 306bc61f-... epoch 5 to 1 other zones
rgw realm reloader: Pausing frontends for realm update...
rgw period pusher CR thread: push to 6048f6e1-... succeeded
rgw realm reloader: using period configuration: 306bc61f-...:5

The held gateway received none of the period pushes itself in any run; another gateway of the zone took them, which is the shape of the bug. The reproducer script and the logs of the first round are attached to the tracker.

The branch builds commit by commit on ce66551.

Related: https://tracker.ceph.com/issues/79869 (a reload that arrives during startup pauses the frontends for good: same window, opposite outcome; not addressed here). The reload this PR schedules comes after the last init step.

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

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)

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

init_storage() loads the realm and its current period, and the gateway
runs with that period until its next reload. The realm watch that
triggers reloads is only set up at the end of init_frontends2(), after
the frontends are already up, and the reload handler is added to it
after that. A period change in between is stored in rados but notifies
nobody: before watch2() the notify reaches no watcher, between watch2()
and add_watcher() it finds no handler and is dropped. A later push of
the same period stops at "already have epoch" in RGWOp_Period_Post and
doesn't notify again, so the gateway keeps the old period until it is
restarted.

With more than one gateway per zone this happens whenever one of them
starts while a new period reaches the zone: another gateway takes the
push, stores the period and notifies before the starting one watches.

Once the last init step is done, read the realm's current period and
its latest epoch again. If either differs from the one the site
configuration was loaded with, do what the lost notify would have
done: hand the period to the period pusher, which sends it on to the
zones that still need it when this zone is its master (the pusher only
knows the period the driver started with), and schedule a reload. A
zone that the current period did not contain yet runs on its local
zonegroup, which is how a new zone starts out; for it, reload once the
current period contains the zone. RGWRealmReloader gets
schedule_reload() for that, split out of handle_notify().

The check is called from main() and RGWLib::init() rather than from
init_frontends2(), because the reload replaces env.driver and
RGWLib::init() still runs init_lua() and init_dedup() against it after
init_frontends2() returns. It compares against a record of what
init_storage() loaded rather than against the site configuration,
which a reload that a notify triggered in the meantime may already be
rewriting.

Fixes: https://tracker.ceph.com/issues/81911
Signed-off-by: Lumir Sliva <[email protected]>
rgw_inject_delay_pattern=delay_realm_watch holds a starting gateway
with its frontends up but before it watches the realm, for up to
rgw_inject_delay_sec seconds or until the pattern is cleared, so a test
can land a period change in that window and release the gateway when
it is ready, without depending on timing.

Fixes: https://tracker.ceph.com/issues/81911
Signed-off-by: Lumir Sliva <[email protected]>
Zone 2's gateways are held with delay_realm_watch, after their
frontends are up but before they watch the realm, and the period
changes while they are held.

test_period_change_during_gateway_startup sets zone 2's redirect_zone
to zone 1. Each held gateway must still answer NoSuchKey for an object
that only zone 1 has, which shows the change landed in the window.
Released, each must reload and answer 301; one that missed the reload
stays on the old period and keeps answering NoSuchKey.

test_master_change_during_gateway_startup makes zone 2 the master. The
commit on zone 2's cluster notifies nobody there, and only zone 2's
gateways would send the new period on to zone 1. Released, they must
do so: zone 1's cluster must get the period that made zone 2 the
master.

Both work with one gateway per zone.

Fixes: https://tracker.ceph.com/issues/81911
Signed-off-by: Lumir Sliva <[email protected]>
@lumir-sliva
lumir-sliva force-pushed the rgw-realm-reload-startup branch from 0e39507 to 2e7915c Compare October 20, 2026 01:05
@lumir-sliva

Copy link
Copy Markdown
Contributor Author

Force-pushed a reworked version (0e39507 -> 2e7915c), description updated. The first one crashed the librgw path (the reload it scheduled replaced env.driver while RGWLib::init() was still using it), skipped a zone the current period didn't contain yet, and didn't replay the lost ZonesNeedPeriod to the period pusher, which left two masters when the change in the window was a master-zone promotion. Second qa test covers that case.

@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

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.

1 participant