Skip to content

osd: keep stretch EC writes recoverable when a zone returns - #55

Merged
aainscow merged 5 commits into
stretchy-Cfrom
wip-stretchy-C-unfound-fix
Oct 8, 2026
Merged

aainscow merged 5 commits into
stretchy-Cfrom
wip-stretchy-C-unfound-fix

Conversation

@aainscow

@aainscow aainscow commented Oct 8, 2026

Copy link
Copy Markdown
Owner

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 that calc_ec_acting() applies to every EC pool on main:

  1. Acting never gives up a usable up[i] or acting[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.
  2. Only an 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, and activate() 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:

  • test/osd: share the zone block swap steps of TestECStretchPeering. Fixture helpers for trimming the log, applying a pg-upmap and a pg_temp, and faking backfill progress and completion, used by the existing zone block swap tests and the new ones.
  • test/osd: demonstrate a returning zone leaving stretch EC writes unfound. An end-to-end test that drives the peering state machines through the PG 2.39 sequence, and two calc_ec_acting_stretch() decisions from that run. All three fail on stretchy-C.
  • osd/PeeringState: stretch EC zone choice prefers up and acting shards. After the relative shards served, assignments rank by the positions they fill from usable up[i] or acting[i], then from up[i], and only then by shards held. Among assignments serving as many relative shards, strays then fill only positions that up and acting cannot.
  • test/osd: check a complete stretch EC backfill target is not restarted. An end-to-end test where the OSD of a complete up shard restarts during a zone block move; it fails until the next commit. Also two static tests: a minimised case from a simulation of the peering rules, and 20000 random states checked for pg_temp ping-pong and the Recovered assertion.
  • osd: keep complete stretch EC backfill targets current from the log. For multi-zone EC pools only, 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 fixes update_calc_stats() and an on_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:

  • A vstart_chaos fix for upmap_items on a PG with no up OSDs.
  • A latent bug, also on main: EC's pending_roll_forward is 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 usable up[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-zone min_size does not count.

Testing

  • Built on stretchy-C ba7dcb2, which includes the per-zone min_size of osd, mon: support per-zone replica min_size for stretch pools #35. unittest_ec_acting_stretch (38), unittest_ec_with_crush (30), unittest_stretch_ec_min_size (21), unittest_peeringstate (48), unittest_osdmap (46) and unittest_ecfailover_with_peering (423) pass.
  • The new tests of each test commit fail without the fix commit after it, and the existing zone block swap tests pass after the helper commit.
  • 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.
  • A Python simulation of the peering rules ran 9000 random fault sequences of a 2+1 two-zone pool. With this PR there were no lost writes, restarts of complete targets, pg_temp ping-pong, Recovered assertions or moves away from up within the failure budget. 2830 complete targets were caught up from the log, 756 of them holding data acting still needed. Within the failure budget, the old code lost writes in 6 runs and the zone fix alone in 12.
  • Fault-injection runs on a vstart cluster (2-zone EC 2+1, same seed, about 2.5 hours each): the old code had 4 real acting flips in 442 cycles, and the zone fix with an earlier backfill rule had 0 in 445 cycles, with no unfound objects. A run with an earlier version of this PR's code (before an unreachable check was removed) stopped after 12 minutes on the test host's free-disk guard; in its 46 cycles (3 zone failovers, 920 peering intervals) there were no acting flips, crashes, asserts or unfound objects.

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.

🤖 Generated with Claude Code

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
aainscow marked this pull request as ready for review October 8, 2026 11:00
@aainscow
aainscow merged commit cb8c701 into stretchy-C Oct 8, 2026
4 of 5 checks passed
@aainscow
aainscow deleted the wip-stretchy-C-unfound-fix branch October 8, 2026 13:19
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
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