Repository navigation
osd: keep stretch EC writes recoverable when a zone returns - #55
Merged
Merged
Conversation
Trimming the log so that the up OSDs of a remap need backfill, applying a pg-upmap and a pg_temp, and faking a backfill target's progress and completion become TestECStretchPeering helpers. The two zone block swap tests use them, and the tests that follow repeat these steps. Assisted-by: Claude Code
A pg-upmap moves a stretch EC PG's zone blocks to the other datacenters while a pg_temp keeps the acting set on the pre-upmap up set. A zone failure, then one more OSD failure, can leave only the k up shards of one block, and those take every write. When the zone returns, calc_ec_acting_stretch() serves the blocks from the datacenters of the pre-upmap up set again, which hold more usable shards while the other block's up shards are still being backfilled. The up shards holding the newest writes become backfill targets, because their datacenter is the goal for their block, and activate() restarts them from last_backfill MIN. Recovery does not use a backfill target's objects, so the writes held only there become unfound and backfill cannot start. Two fault-injection runs on a test cluster ended this way, with 79 and 9 objects unfound and every OSD up. TestECStretchPeering.ReturningZone_NewestWritesNotUnfound drives the peering state machines through the whole sequence: the pg-upmap with the pg_temp, the zone failure and the backfill of the surviving zone's up shards, one more OSD down so the k remaining up shards of one block take every write, the pg-upmap removed while the PG writes on without those shards, and the pg-upmap back with the whole zone. It expects the writes to stay recoverable. Two TestECActingStretch tests check calc_ec_acting_stretch() decisions from the run that left 9 writes of PG 2.39 unfound, with the run's OSD ids mapped onto the fixture: - ReturningEmptyUpShard_KeepsUpActingZones, epoch 6256: up = acting with block 0 in dc0 after a pg-upmap, and one up OSD returning empty. The zone choice swaps both zone blocks back onto the strays of the layout before the pg-upmap, because they hold six shards against five. - ReturningZone_CurrentShardsKeepTheirZone, epoch 6369: the PG ran on the k shards 0(1) and 2(2) while the other zone was down. When it returns, the zone choice again moves acting onto the behind strays of the old layout (four shards against two), leaving the only shards with the newest writes as strays. All three fail today. Assisted-by: Claude Code
calc_ec_acting() never gives up a usable up[i] or acting[i]: position i takes up[i] when it is usable, otherwise acting[i], and only otherwise a stray. So acting only moves towards up, and only when up has the data. calc_ec_acting_stretch() must serve each zone block from one zone, so it scores whole assignments of zone blocks to zones. After the relative shards served (capped at k) it ranked them by the number of usable shards held, counting strays the same as up and acting shards, and looked at up and acting only to break ties. An assignment onto the strays of an earlier layout therefore beat the one acting was using whenever the strays held more shards, however far behind they were. In a fault-injection run PG 2.39's acting set switched between the layouts before and after a pg-upmap six times in four minutes. At epoch 6256 one returning empty up shard (5 shards against 6) swapped both zone blocks back onto the layout before the pg-upmap. At epoch 6369 a returning zone (2 shards against 4) moved acting off 0(1) and 2(2), which held the only copies of the writes made while the other zone was down, onto strays 1,641 versions behind; 9 of those writes later became unfound. Rank assignments, after the relative shards served, by the positions they fill from usable up[i] or acting[i], then from up[i], and only then by the shards held. Among assignments serving as many relative shards, strays then only fill positions that up and acting cannot. The goal assignment, which decides which up OSDs are backfilled, counts want as the acting set, since want is what acting becomes. As before, a completed backfill makes up's assignment fill as many positions as want's and win on up[i], so Recovered moves to up. When acting is pinned by pg_temp to a layout that fills more positions than up can (for example up moving a zone block onto the zone serving the other block, with the other block's up OSDs gone), acting now stays and nothing is backfilled, instead of the PG moving to up: it keeps four shards in two zones, undersized until the map changes, rather than moving to three shards in one zone. The static and end-to-end tests for that case are restated: the static one now expects acting to stay, and the end-to-end one checks Recovered dropping the pg_temp after a full zone block swap. TestECStretchPeering.ReturningZone_NewestWritesNotUnfound passes. Assisted-by: Claude Code
calc_ec_acting_stretch() makes a complete, usable up OSD a backfill target when its zone block will move to it, so that it keeps getting writes. activate() restarts every complete backfill target that is not at the head (last_backfill MIN): it is backfilled again from scratch, and recovery does not use its objects meanwhile. When acting is still recovering an object that only such shards hold, the object becomes unfound. calc_ec_acting() never backfills a usable shard, so main does not hit this. TestECStretchPeering.ZoneBlockSwap_RestartedUpShardKeptCurrent swaps the zone blocks of a 2+1 stretch EC PG with a pg-upmap while a pg_temp keeps the old acting set. All but one of the new up shards finish backfill; then the OSD of a complete one, x, restarts and misses a few writes, and more writes follow than the PG log keeps. It expects x to be caught up from the log rather than restarted, to keep getting writes, and the PG to move to up when the last backfill finishes. It fails today: x is restarted. Two TestECActingStretch tests check which up shards calc_ec_acting_stretch() backfills. Both pass today. - ReturningZone_BehindUpShardsKeptAsTargets is a minimised case found by a simulation of the peering rules: a zone returns while acting (block 1 in dc0) is recovering an object that only dc1 holds, and dc1's complete up shards are one write behind. They become backfill targets with the empty up shards, so they keep getting writes. - RandomStates_StableWantAndBackfill checks random up sets, acting sets and shard states: the chosen want is chosen again once it is acting (no pg_temp ping-pong), want == up comes without backfill, and the call from Recovered either moves on or keeps the same backfill targets, which choose_acting() asserts. Assisted-by: Claude Code
An up shard of a multi-zone EC pool can be complete but behind while its zone block is still served from another zone, for example when its OSD restarts during a zone block move. It cannot join acting by itself: a block is served from one zone, so it has to wait until the other up shards of its zone are backfilled. calc_ec_acting_stretch() makes it a backfill target, so that it keeps getting writes, and activate() then restarts it (last_backfill MIN), because it is a complete backfill target that is not at the head. It is backfilled again from scratch, and its objects stop counting as recovery sources, which can leave writes that only it holds unfound. Keep it a backfill target, and have activate() catch a complete backfill target of a multi-zone EC pool up from the log instead of restarting it. activate() still restarts one that is not contiguous with the log. Other pools are unchanged. Leaving such a shard out of the backfill targets instead would keep its objects but send it no writes. During a long backfill it falls off the PG log. Recovered still counts it as usable, because the primary's peer_info keeps the log tail from activation, and moves the block to up; the next interval then leaves its position empty while it is backfilled from scratch. Such a target has an accurate missing set and needs no backfill, so update_calc_stats() counts its missing objects from that set, and PrimaryLogPG::on_activate_complete() sets up backfill only when a target needs it (it asserted when every target was complete). As for any acting shard, a client write to an object such a target is still missing waits until the object is recovered to it. TestECStretchPeering.ZoneBlockSwap_RestartedUpShardKeptCurrent passes. Assisted-by: Claude Code
aainscow
marked this pull request as ready for review
October 8, 2026 11:00
aainscow
added a commit
that referenced
this pull request
Oct 12, 2026
…plugin Follow-up to "osd/PeeringState: stretch EC zone choice prefers up and acting shards" (#55, merged), for issue 1 of a review comment made on that PR after it merged: the zone choice in calc_ec_acting_stretch() was hard to follow. It kept its five counters in an unnamed array h[N], compared shard counts against k instead of asking the erasure code plugin whether shards can recover, and did not say what its recursive assign() does. - The counters are now the named members of zone_fit_t, declared in the order they are compared in. - Whether the shards served by a zone choice, or held by one zone for a block, can recover is now decided by the backend's IsPGRecoverablePredicate, which choose_acting() passes in. For ISA-L and jerasure this is the same as holding k relative shards. A choice that cannot recover the PG no longer prefers more served shards; such a PG cannot go active whichever choice is made. - A comment says what assign() searches and which choice it keeps. No other change in behaviour. The TestECActingStretch tests pass the mock predicate of a 2+1 pool. Assisted-by: Claude Code
aainscow
added a commit
that referenced
this pull request
Oct 12, 2026
Follow-up to "osd: keep complete stretch EC backfill targets current from the log" (#55, merged), for issues 2 and 3 of a review comment made on that PR after it merged. Issue 2: activate() caught every complete backfill target of a multi-zone EC pool up from the log. On main, a complete backfill target is one that was not contiguous with the auth log, so choose_acting() did not use it, while it can still be contiguous with the primary's longer log; activate() then backfills it again from scratch. That case also happens in a multi-zone EC pool, so only a complete backfill target that was usable when acting was chosen (complete and contiguous with the auth log), and is only waiting for its zone block to move to it, may be caught up from the log. choose_acting() now records those targets in usable_backfill_targets when it sets backfill_targets, and activate() restarts every other complete backfill target, as on main. Issue 3: update_calc_stats() takes the missing objects of a backfill target caught up from the log from peer_missing. GetMissing does fetch the log and missing set of a complete backfill target that is contiguous with the primary's log (it skips only empty ones, those not contiguous and those with last_backfill MIN), and activate() adds the entries it sends, so that set is accurate. num_objects - peer_num_objects is not: the peer's num_objects is from before it missed writes, so an overwrite it missed is not counted, and nothing updates it as objects are recovered to it. With main's formula, a target that missed one overwrite reports 0 missing objects instead of 1. The check now uses usable_backfill_targets instead of last_backfill MAX, so the formula is again used for every other backfill target, as on main. TestECStretchPeering.ZoneBlockSwap_UpShardBehindAuthLogRestarted fails without this change (last_backfill is MAX instead of MIN) and passes with it. TestECStretchPeering.ZoneBlockSwap_RestartedUpShardMissingCounted passes before and after; with update_calc_stats() using main's check it fails (0 missing instead of 1). Assisted-by: Claude Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the stretch EC bug behind the unfound objects in two fault-injection runs: 79 objects in 2 PGs, then 9 in PG 2.39, each time with every OSD up. The September 30 rework of
calc_ec_acting_stretch()(in stretchy-C as 6d88fb6) dropped two rules thatcalc_ec_acting()applies to every EC pool on main:up[i]oracting[i]for a stray. The zone choice ranked whole zone assignments by the usable shards they held, counting strays the same as up and acting shards. Acting therefore jumped back onto the strays of an earlier layout whenever they outnumbered the current shards. PG 2.39 switched between the layouts before and after a pg-upmap six times in four minutes, and at epoch 6369 it moved off the only two shards holding the newest writes.up[i]that is not usable is backfilled.calc_ec_acting_stretch()also makes complete up shards backfill targets when their zone block will move to them, andactivate()restarts every complete backfill target that is not at the head. Recovery then stops using its objects, so writes held only there become unfound.Commits:
calc_ec_acting_stretch()decisions from that run. All three fail on stretchy-C.up[i]oracting[i], then fromup[i], and only then by shards held. Among assignments serving as many relative shards, strays then fill only positions that up and acting cannot.activate()catches a complete backfill target up from the log instead of restarting it, so the target keeps its objects as recovery sources and gets every write. It still restarts a target that is not contiguous with the log. Also fixesupdate_calc_stats()and anon_activate_complete()assert for such targets.calc_ec_acting_stretch()already makes such shards backfill targets and is unchanged by this commit.Cost of the last commit: a complete up shard that is behind takes a backfill reservation although it needs only log recovery, and its commit adds to write latency. A client write to an object it is still missing waits until that object is recovered to it, as for any acting shard. One option, not in this PR, is to treat such a target like an async recovery target on the write path, so those writes do not wait.
Not included:
upmap_itemson a PG with no up OSDs.pending_roll_forwardis keyed by shard id, so when two OSDs hold the same shard, one of them misses the idle roll-forward kick.Known limitation: assignments are ranked over all zone blocks together, so when the up shards of one block claim the zone that acting serves the other block from, acting can move onto up shards that are complete but behind, as
calc_ec_acting()does on main for any usableup[i]. With both zones up, the other block still holds every write and the returning shards are caught up from the log. With the other zone down, the newest writes are left only on strays, which are not restarted and remain recovery sources. Getting there takes a zone block move in progress, a site failure and two failures in the surviving zone, one of them an OSD that holds only an up shard, which per-zonemin_sizedoes not count.Testing
unittest_ec_acting_stretch(38),unittest_ec_with_crush(30),unittest_stretch_ec_min_size(21),unittest_peeringstate(48),unittest_osdmap(46) andunittest_ecfailover_with_peering(423) pass.PrimaryLogPG::on_activate_complete()is not run by the unit-test harness, which mocks it. A pre-merge review traced the path of a complete backfill target through activation, recovery, backfill, the write path, log trimming and stats in the classic OSD and found no assert or stuck state.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
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist
Show available Jenkins commands
jenkins test classic perfJenkins Job | Jenkins Job Definitionjenkins test crimson perfJenkins Job | Jenkins Job Definitionjenkins test signedJenkins Job | Jenkins Job Definitionjenkins test make checkJenkins Job | Jenkins Job Definitionjenkins test make check arm64Jenkins Job | Jenkins Job Definitionjenkins test submodulesJenkins Job | Jenkins Job Definitionjenkins test dashboardJenkins Job | Jenkins Job Definitionjenkins test dashboard cephadmJenkins Job | Jenkins Job Definitionjenkins test apiJenkins Job | Jenkins Job Definitionjenkins test docsReadTheDocs | Github Workflow Definitionjenkins test ceph-volume allJenkins Jobs | Jenkins Jobs Definitionjenkins test windowsJenkins Job | Jenkins Job Definitionjenkins test rook e2eJenkins Job | Jenkins Job DefinitionYou must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.
🤖 Generated with Claude Code