Skip to content

osd/OSDMap: skip calc_pg_upmaps when an up OSD has no weight - #72503

Draft
aainscow wants to merge 1 commit into
ceph:mainfrom
aainscow:wip-osdmap-upmap-zero-weight
Draft

aainscow wants to merge 1 commit into
ceph:mainfrom
aainscow:wip-osdmap-upmap-zero-weight

Conversation

@aainscow

@aainscow aainscow commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

The mgr balancer in upmap mode can abort ceph-mgr with
OSDMap.cc: FAILED ceph_assert(osd_weight.count(oid)) in OSDMap::calc_deviations()
(https://tracker.ceph.com/issues/48896). This happens when CRUSH maps a PG to an OSD
whose CRUSH weight is 0.

How it happens. straw2 returns the first item of a bucket when every item in it has
weight 0. The chosen leaf is then checked only against the OSD's reweight (in/out), not
its CRUSH weight. Take a rule with several take steps, such as the legacy stretch-mode
rule take site1; chooseleaf ...; emit; take site2; chooseleaf ...; emit. If every OSD
of one site is crush-reweighted to 0 while it is still in, the first OSD of that site
goes into every up set. build_pool_pgs_info() counts the PGs on that OSD, but
get_osds_weight() leaves the OSD out of the weight map. The other site keeps
osd_weight_total above 0, so the existing early return does not fire, and
calc_deviations() asserts. With one OSD per take, the PGs stay full size and
active+clean, so the balancer aborts the active mgr on every run. The same core shows up
now and then in qa/standalone/mon-stretch/mon-stretch-uneven-crush-weights.sh, which
sets both OSDs of one zone to CRUSH weight 0.

When it can happen. Zero CRUSH weight alone is not enough. Adding OSDs at weight 0, or draining an OSD or a host, does not trigger it with the rules Ceph creates (take default followed by chooseleaf over hosts): straw2 never picks a zero-weight item while any sibling has weight. It also needs a manually created CRUSH rule whose take reaches only zero-weight items. Examples are a rule with one take per site (as written for stretch clusters) while a whole site is crush-reweighted to 0 but still in, or, from reading straw2 but not tested, a device-class rule whose class has only zero-weight OSDs.

Fix. calc_pg_upmaps() logs an error and returns without changes when an OSD in an
up set has no weight under the pool's rule. Upmaps cannot move those PGs to a weighted
OSD in the same subtree. total_pgs also counts the copies on the unweighted OSD, so
the targets for the rest of the pool would be wrong too. The mgr balancer and
osdmaptool --upmap call calc_pg_upmaps() for one pool at a time, so other pools are
still balanced.

Relation to #53736 (closed without merging). That
PR kept zero-weight OSDs in the weight map. As its author found while writing a test,
this only moves the abort to ceph_assert(target > 0): a zero weight gives a zero
target, and calc_deviations() divides by the target. He also could not find how a
zero-weight OSD gets into an up set, so there was no reproducer. This PR leaves the
weight map and both asserts as they are. Instead it skips the pool when its mapping does
not follow its weights, and the new unit test reproduces the trigger.

One commit, osd/OSDMap: skip calc_pg_upmaps when an up OSD has no weight, with the fix and
OSDMapTest.BUG_48896. The test builds a two-datacenter rule with one take per datacenter, sets
both OSDs of dc-0 to CRUSH weight 0 (still in), and checks that every PG still maps to osd.0. It
then runs calc_pg_upmaps() and checks that no PG is upmapped to a zero-weight OSD.

Testing (Debug build):

  • unittest_osdmap --gtest_filter=OSDMapTest.BUG_48896 without the OSDMap.cc change aborts with
    FAILED ceph_assert(osd_weight.count(oid)) in calc_deviations(). With the fix it
    passes.
  • Full unittest_osdmap with the fix: all 46 tests pass. Only the new test reaches the new
    early return.

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

calc_pg_upmaps() builds pgs_by_osd from the up sets and osd_weight from
the weights under the pool's CRUSH rule, leaving out OSDs whose weight
is 0, and calc_deviations() asserts that every OSD in pgs_by_osd has a
weight. CRUSH can still map PGs to an OSD with CRUSH weight 0: straw2
returns the first item of a bucket whose items all have weight 0. With
a rule that takes several subtrees (take site1 ... emit; take site2 ...
emit), crush-reweighting every OSD of one site to 0 while they stay in
puts the first OSD of that site into every up set, and the other site
keeps the total weight above 0. Each balancer run then aborts ceph-mgr
on ceph_assert(osd_weight.count(oid)) while those PGs are active+clean.

Return without changes in that case. Upmaps cannot move those PGs to an
OSD with weight under the same take, and total_pgs counts the copies on
the unweighted OSD, so the targets for the other OSDs would be wrong
too. The mgr balancer and osdmaptool call calc_pg_upmaps() with one
pool at a time, so other pools are still balanced.

OSDMapTest.BUG_48896 builds such a rule with one take per datacenter,
crush-reweights both OSDs of one datacenter to 0 while they stay in,
checks that every PG still maps to one of them, and checks that
calc_pg_upmaps() neither aborts nor upmaps a PG to a zero-weight OSD.
Without the fix it aborts on the assert above.

Fixes: https://tracker.ceph.com/issues/48896
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.

2 participants