Skip to content

osd/PeeringState: cap pwlc at the log head when the primary activates - #72290

Merged
SrinivasaBharath merged 2 commits into
ceph:mainfrom
aainscow:wip-ec-pwlc-cap
Nov 21, 2026
Merged

SrinivasaBharath merged 2 commits into
ceph:mainfrom
aainscow:wip-ec-pwlc-cap

Conversation

@aainscow

@aainscow aainscow commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

In an optimized EC pool, a partial-write-last-complete (pwlc) range can outlive
the write it covers when peering rolls that write back. A nonprimary shard then
moves its last_update and log head to a version that no longer exists. The next
write reuses that version number, and the shard aborts in
PGLog::IndexedLog::add (e.version.version > head.version). Alternatively, the
shard is later chosen as the log source and is never recovered.

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

What goes wrong

After a peered-only interval keeps a sub-stripe write, the unwritten nonprimary
shards get a pwlc range ending at that write. When the next interval rolls the
write back, the stale range survives in two places:

  • On the primary. The new primary merges peers' pwlc in update_peer_info()
    during GetInfo, before GetLog has chosen the log. It therefore takes a range
    ending at the write that is about to be rolled back. Nothing trims the
    primary's own copy afterwards. When the primary is its own log source,
    proc_master_log() does not run. activate() then stamps the range with the
    new epoch, which makes it win every later merge, and sends it to the shards.
  • On a nonprimary shard. Each one keeps its own copy and re-applies it in
    update_peer_info(). If no primary-capable shard of the new interval saw the
    write, the primary sends no range for it. The shard then re-applies its stale
    copy right after the primary's MInfoRec has rewound its log.

The tracker has a step-by-step trace from the unit test.

Fix

The primary's log is authoritative once it activates, so no pwlc range may end
past its head.

  • activate() trims pwlc to pg_log.get_head() before it stamps the epoch and
    sends the ranges. That also covers ranges merged in WaitUpThru, and ranges from
    peers whose log head already matched.
  • A nonprimary shard trims its own pwlc to the primary's last_update in
    update_peer_info() before applying it.
  • When a replica applies the range for its own shard from an MLogRec, that range
    is capped at the sender's last_update. With the activate() change a primary
    no longer sends such a range, so this cap is defensive: it protects replicas
    during an upgrade, when the primary may still run older code.

The cap must come after all the merges and before the epoch is stamped. pwlc
epochs are unchanged, so the tie-break in update_peer_info() is unchanged too.

Why #71579 is not enough

#71579 trims the copy of the range that the primary holds for each peer with
divergent entries, in proc_replica_log(). It does not trim:

  • the primary's own merged copy, which it took from those peers in GetInfo
    before the rollback was known;
  • the copy each nonprimary shard keeps for itself.

In a trace of the k4m2 test on main, #71579 rolls the peers' ranges back from 5'2
to 5'1. The primary still activates with (5'1, 5'2] for shards 1-3.

Testing

New tests in unittest_ecfailover_with_peering:

  • RolledBackPeeredWriteLeavesNoStalePwlc: the primary-side case.
  • RolledBackPeeredWriteLeavesNoStaleReplicaPwlc: the nonprimary-side case. The
    write reaches no other primary-capable shard.

Both raise min_size to k + 1, so that losing two shards leaves the PG peered but
not active. They check pwlc and every shard's log head before the next write, so a
regression fails the test rather than aborting the binary. They skip k2m1
configurations, as intended. The test commit also adds
OSDMapTestHelpers::set_pool_min_size() and ECPeeringTestFixture::set_pool_min_size().

Results:

  • With the fix: all non-skipped configurations pass, and the whole binary passes
    (206 passed, 24 skipped).
  • With the PeeringState change reverted: all 16 non-skipped configurations fail
    on the intended checks. The stale range ends past the head, and a nonprimary
    log head differs from the primary's.

The tests do not deep-scrub the object afterwards. Shard 0 is down by then, and on
main a deep scrub of an ISA pool with a data shard missing reports data-digest
errors even for an object that was never partially written. That looks like a
separate bug and will be raised on its own.

Backport: tentacle, umbrella. The fix applies cleanly to both. Neither has #71579
yet, so backport that too.

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.

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

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

@bill-scales

Copy link
Copy Markdown
Contributor

jenkins test make check

@bill-scales bill-scales left a comment

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.

LGTM

Comment thread src/osd/PeeringState.cc Resolved
Comment thread src/osd/PeeringState.cc Resolved
Comment thread src/osd/PeeringState.cc Resolved
Comment thread src/osd/PeeringState.cc Resolved
@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been added to wip-bharath17-testing-20261016.230103-main.

@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

@ljflores

ljflores commented Nov 5, 2026

Copy link
Copy Markdown
Member

@aainscow just confirming, the latest changes were just to resolve the conflicts?

@aainscow

aainscow commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

@aainscow just confirming, the latest changes were just to resolve the conflicts?

@ljflores Confirmed

@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

In an optimized EC pool, a sub-stripe write gives the shards it does not
touch a partial_writes_last_complete (pwlc) range ending at that write.
If peering later rolls the write back, a pwlc range that still ends at
it is stale, and applying it moves a nonprimary shard's last_update and
log head to a version that no longer exists.

ceph#71579 ("osd: pwlc was able to retain values larger than the
last_update") trims the pwlc copies the primary holds for divergent
peers in proc_replica_log, but the primary's own copy is not trimmed.
The new primary merges each peer's pwlc in update_peer_info() during
GetInfo, before GetLog has decided the authoritative log, so it keeps a
range ending at a write that peering then rolls back. proc_master_log()
would trim it, but does not run when the primary is its own log source.
activate() then stamps the stale range with a new epoch, making it the
definitive copy, and sends it to the peers. The nonprimary shards apply
it and move their last_update and log head to the rolled-back version,
so the next write to them, which reuses that version number, asserts in
IndexedLog::add; a shard left with such a last_update can also be picked
later as the log source and then never be recovered.

The primary's log is authoritative once it activates, so no pwlc range
may end past its head. activate() now trims pwlc to the head before
stamping the epoch, which also covers ranges merged after GetLog in
WaitUpThru and from peers whose log head already matched.

A nonprimary shard keeps its own pwlc too, and update_peer_info()
applies its own range after merging only the ranges the primary sends.
When no primary-capable shard of the new interval saw a partial write
that skipped it, the primary sends no range for it, so the shard applies
its stale range again right after the primary's MInfoRec has rewound
its log. update_peer_info() now trims a nonprimary shard's pwlc to the
primary's last_update before applying it.

The range for its own shard that a replica applies from an MLogRec
before merging the log is capped at the sender's last_update the same
way. With the activate() change a primary no longer sends such a range;
the cap is defensive, for mixed-version clusters during an upgrade where
the primary still runs older code.

Tested by TestECFailoverWithPeering.RolledBackPeeredWriteLeavesNoStalePwlc
and RolledBackPeeredWriteLeavesNoStaleReplicaPwlc in the following commit.

Fixes: https://tracker.ceph.com/issues/81283
Assisted-by: Claude Code

Signed-off-by: Alex Ainscow <[email protected]>
Tests "osd/PeeringState: cap pwlc at the log head when the primary
activates".

A sub-stripe write kept by a peered interval gives the unwritten
nonprimary shards a pwlc range ending at that write. When the
primary-capable shard that missed the write returns, the write is rolled
back. RolledBackPeeredWriteLeavesNoStalePwlc checks that the new primary
does not keep, stamp and send the old range it merged from another
primary-capable shard, so the nonprimary shards do not move their
last_update and log head to the rolled-back version, and the next write,
which reuses that version number, succeeds.

A nonprimary shard also keeps its own copy of that range.
RolledBackPeeredWriteLeavesNoStaleReplicaPwlc covers a write that
reaches no other primary-capable shard, so no primary of the next
interval has a range for the nonprimary shards, and checks that they do
not re-apply their own copy after the new primary's MInfoRec rewinds
them.

Both tests raise the pool's min_size to k + 1 so that losing two shards
leaves the PG peered but not active. They check the state before the
next write so a regression fails the test rather than aborting the
binary.

The tests do not deep-scrub the object afterwards: shard 0 is down by
then, and a deep scrub of an ISA pool with a data shard missing reports
data digest errors even for an object that was never partially written.

Assisted-by: Claude Code

Signed-off-by: Alex Ainscow <[email protected]>
@aainscow

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (head 5759603), trivial rebase: main gained new tests and test-fixture helpers in src/test/osd/TestECFailoverWithPeering.cc at the two places where the test commit adds its own (a fixture helper and a test), so I kept both blocks; no code was changed to resolve it. git range-diff shows both commits' patches unchanged apart from diff-hunk context. This was not compiled or run locally, CI will build it; the code and the tests are otherwise the same as the ones that were QA'd.

@Naveenaidu

Copy link
Copy Markdown
Contributor

@aainscow
aainscow requested a review from rzarzynski November 18, 2026 07:49
@aainscow

Copy link
Copy Markdown
Contributor Author

jenkins test this please

@aainscow

Copy link
Copy Markdown
Contributor Author

jenkins retest this please

@SrinivasaBharath
SrinivasaBharath merged commit 921cf42 into ceph:main Nov 21, 2026
19 of 22 checks passed
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.

6 participants