Skip to content

crush/CrushWrapper: fix verify_upmap for multi-take rules with device classes - #71053

Open
next0262 wants to merge 2 commits into
ceph:mainfrom
next0262:wip-verify-upmap-multitake
Open

next0262 wants to merge 2 commits into
ceph:mainfrom
next0262:wip-verify-upmap-multitake

Conversation

@next0262

@next0262 next0262 commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

verify_upmap() checks each choose/chooseleaf step against the entire up vector.
For a rule with more than one take step - hybrid device-class rules, mainly - that
counts OSDs belonging to other take scopes against the current step's constraint. On
top of that, parents are resolved through the per-class shadow trees of all of the
rule's takes, so the same physical failure domain gets counted once per device class.

The result is that for the documented hybrid layout (one ssd and one hdd per zone,
ssd take first so the primary lands there) every upmap is rejected, including the
ones that match the rule exactly:

verify_upmap number of buckets 4 exceeds desired 2

Two physical zones, seen as four buckets: dc1ssd, dc2ssd, dc1hdd, dc2hdd. The mon
cancels each pg-upmap-items entry right after it is set (check_pg_upmaps), and the
upmap balancer can never touch those pools either, since calc_pg_upmaps -> legal_swap
fails the same way. That leaves osd reweight as the only balancing tool. We hit this
in production when a node failure pushed one OSD to 90% (backfillfull) while its
same-zone peers sat at 25%, and there was no upmap we could apply to relieve it.

Fix

Defer the choose/chooseleaf checks to EMIT, where the take scope's segment of up is
known - the EMIT handler already computes that segment length for its subtree
containment check. Check only the OSDs in the current segment, and resolve their
parents within the current take subtree, which also gets rid of the cross-take
shadow-bucket double count. Nothing changes for single-take rules: there the segment
is the whole up vector and the parent search space is the same single take root as
before.

This is orthogonal to #69151, which fixes a different false rejection in the same
function (nested choose steps within one take). I checked both directions: with
#69151 applied the hybrid reproducer above still fails, and with this patch applied
the rule shape from #51729 is still rejected exactly as before (same verdicts for the
exact shape and a set of permutations). So neither patch subsumes the other. Happy to
rebase on top of it either way.

Offline reproducer

No cluster needed. Build a small map with a hybrid rule and let the balancer fill in
some upmaps, then ask osdmaptool to revalidate them:

crushtool -c hybrid.txt -o hybrid.bin
osdmaptool --createsimple 12 --with-default-pool om.bin --clobber \
    --osd-pool-default-size 4
osdmaptool om.bin --import-crush hybrid.bin
osdmaptool om.bin --mark-up-in --upmap up.txt --upmap-pool rbd \
    --upmap-max 20 --upmap-deviation 1 --save
osdmaptool om.bin --mark-up-in --upmap-cleanup cleanup.txt

Before the patch the last command rejects all 20 entries:

verify_upmap number of buckets 4 exceeds desired 2
check_pg_upmaps verify_upmap of pg 1.2 returning -22
...
$ grep -c rm-pg-upmap cleanup.txt
20

After the patch it rejects none, and cleanup.txt is empty. The crush map used above
is the rule from the tracker ticket over two zones of three hosts, one ssd and one
hdd per host.

Behavior change surface

The set of rejected mappings is a strict subset of what it was. The old code checked
every step against a superset of the OSDs (whole up instead of the scope's segment)
and resolved parents in a superset of the search space (all take roots via
find_takes_by_rule instead of the current root), and both comparisons are monotonic in
those inputs. Nothing that was accepted before can be rejected now, so stored upmaps
keep validating and no mass cancellation can happen on upgrade.

I checked that by brute force rather than by argument. Over the topology of the unit
test, every ordered mapping was fed to verify_upmap on both versions:

rule                      mappings   still accepted   newly accepted   accept->reject
hybrid (2 takes, classes)      840                0               36                0
same-root, 2 takes             840              600              160                0
single take                     42               40                0                0

Note the first row: the old code rejects all 840 mappings for a hybrid rule, so no
cluster can have a stored upmap on such a pool to begin with - there is no state to
regress. The same-root row is the intended semantic change: the newly accepted
mappings are the ones placing replicas of different take scopes on one host, which
CRUSH itself produces for those rules since the scopes are drawn independently.
Single-take rules are bit for bit unchanged.

Running osdmaptool --upmap-cleanup with both versions over a single-take pool with 30
stored upmap entries also gives identical output (nothing cancelled either way).

Tests

unittest_crush_wrapper --gtest_filter='*verify_upmap*':

  • hybrid rule, two classes, two takes:
    • the exact shape the rule produces - was -EINVAL, now passes
    • a legal replacement within the ssd scope - was -EINVAL, now passes
    • two ssd replicas on one host - still rejected
    • an hdd OSD inside the ssd scope - still rejected
  • single-take rule, accept and reject cases unchanged
  • same-root multi-take rule, covering the behavior change described above

I have a standalone test for this as well (build a hybrid rule on a live cluster, set a
rule-compliant pg-upmap-items entry, check the mon still has it a few osdmap epochs
later) but I could not run it on my machine, so I left it out rather than send
something I have not exercised. Say the word and I will get it verified and add it.

Local validation: CrushWrapper suite 26/26 on the rebased sources, and the existing
OSDMap regression suite 41/41 (including BUG_40104 / BUG_42485 / BUG_51842) relinked
with the rebased CrushWrapper. Existing build dependencies were reused; a full
project rebuild has not been run.

Fixes: https://tracker.ceph.com/issues/79493
Related: https://tracker.ceph.com/issues/51729

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)

@next0262
next0262 requested a review from a team as a code owner August 14, 2026 02:43
@next0262

next0262 commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor Author

Sorry for the direct ping — @rzarzynski @ljflores, this touches verify_upmap, the same area as #47189, so I thought you might be the right people to ask.

I tried to answer the upgrade question from #47189 up front in the description, since I imagine it comes up here too: the new code rejects a strict subset of what the old one did, and I checked that by running every ordered mapping of three rule shapes through both versions (none of the 1722 flips from accepted to rejected). There is also an osdmaptool-only reproducer in there if that is an easier place to start than the patch.

Happy to make any changes you suggest — I will turn them around quickly.

@phlogistonjohn

Copy link
Copy Markdown
Contributor

ok to test

@next0262

Copy link
Copy Markdown
Contributor Author

Thank you @phlogistonjohn, much appreciated — CI is running now.

@next0262

next0262 commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor Author

All checks are green now (make check, arm64, API and windows tests). Happy to answer any questions or make changes.

@rzarzynski
rzarzynski requested a review from ljflores August 18, 2026 19:28
@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

@github-actions

github-actions Bot commented Sep 1, 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

@next0262
next0262 force-pushed the wip-verify-upmap-multitake branch from e62f9b4 to 718b0d3 Compare September 1, 2026 13:59
@ljflores

ljflores commented Sep 1, 2026

Copy link
Copy Markdown
Member

Noted that I need to review this.

@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

@next0262
next0262 force-pushed the wip-verify-upmap-multitake branch from 718b0d3 to 66b31e2 Compare October 25, 2026 16:33
@next0262
next0262 requested a review from a team as a code owner October 25, 2026 16:33
@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

… classes

verify_upmap checks each choose/chooseleaf step of a rule against the
whole `up` vector. For rules with multiple take steps (e.g. hybrid
rules placing some replicas on one device class and the rest on
another), this counts OSDs of other take scopes against the current
step's constraint. Worse, with device classes the same physical
failure domain is counted once per class shadow bucket, so a rule like

    take default~ssd
    choose firstn 2 type zone
    chooseleaf firstn 1 type host
    emit
    take default~hdd
    choose firstn 2 type zone
    chooseleaf firstn 1 type host
    emit

always fails validation ("number of buckets 4 exceeds desired 2"): the
two physical zones are seen as four distinct buckets (dc1~ssd, dc2~ssd,
dc1~hdd, dc2~hdd). As a result every pg-upmap-items entry on pools
using such rules is cancelled by the mon right after being set, and
the upmap balancer can never optimize those pools.

Fix this by deferring the choose/chooseleaf checks to EMIT, where the
take scope's segment of `up` is known: check only the OSDs of that
segment, and resolve their parents within the current take subtree
only. Single-take rules see no behavior change.

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

Signed-off-by: Woojoong Kim <[email protected]>
@next0262
next0262 force-pushed the wip-verify-upmap-multitake branch from 66b31e2 to d5c3a45 Compare November 23, 2026 17:59
@next0262

Copy link
Copy Markdown
Contributor Author

@ljflores rebased onto main and resolved the release notes conflict. The code and tests are unchanged. Could you reapprove CI for the updated commits? Thanks!

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

3 participants