Skip to content

mon/OSDMonitor: refuse a rule that does not place a full set in each zone - #60

Closed
aainscow wants to merge 2 commits into
stretchy-Cfrom
wip-stretchy-C-num-zones-rule-check
Closed

aainscow wants to merge 2 commits into
stretchy-Cfrom
wip-stretchy-C-num-zones-rule-check

Conversation

@aainscow

@aainscow aainscow commented Oct 8, 2026

Copy link
Copy Markdown
Owner

A multi-zone pool (num_zones 2) needs a CRUSH rule that puts each zone's block of the pool in a zone of its own. For an EC pool that block is k+m shards. For a replicated pool it is the per-zone replicas. Outside global stretch mode the monitor accepted any existing rule for such a pool. Per-pool stretch mode came in with 59997c6, and f713744 checks the rule only in global stretch mode. This is on stretchy-C only, so there is no tracker.

Seen in teuthology job 611913, rados:thrash-erasure-code-stretch with the jerasure-k=2-m=2-crush facet (run). The test made its rule with osd crush rule create-erasure teuthologycrush, which builds a one-zone rule. osd pool create ... jerasure22profile teuthologycrush --num_zones 2 then succeeded. 10 of the 16 PGs had up sets that mixed the datacenters within a zone block, calc_ec_acting_stretch left holes, and stretch mode never recovered. 9af382e fixed the qa side. This PR fixes the monitor side.

The fix

OSDMonitor::validate_multi_zone_rule() reads the rule's steps. It accepts the two forms that place num_zones blocks of per_zone OSDs, each block in a different bucket of the zone type:

  • a take above the zones, a choose of the zone type that yields num_zones buckets, then choose/chooseleaf steps below it that pick per_zone OSDs in each zone. This is what add_simple_stretch_rule() builds.
  • one take/emit block per zone, each taking a different zone bucket, or a bucket or OSD inside it.

choosemsr is not accepted for the zone step, because it can move a block's OSDs to another bucket when an OSD is out.

Outside global stretch mode the check runs on osd pool create with num_zones > 1, osd pool set <pool> crush_rule on a multi-zone stretch pool, osd pool set <pool> num_zones 2, and osd pool set <pool> replica <n> when it reuses an existing <pool>-replica-<n> rule. A rule that fails gets EINVAL, for example:

crush rule one_zone does not place 4 OSDs in each of 2 datacenter buckets: it chooses host items before choosing datacenter buckets

Generated stretch rules pass, so creating a pool without a rule works as before. Global stretch mode is unchanged. The developer and user stretch documentation describe the check.

Commits

  1. qa/standalone/mon-stretch: demonstrate a multi-zone pool on a one-zone rule: adds mon-stretch-multi-zone-rule.sh, which tries each path with a one-zone rule and expects a refusal. It also checks that the generated rule, create-erasure --num_zones 2 (the rule 9af382e builds), create-stretch-replicated and a hand-built per-zone take rule are still accepted. All four test functions fail on stretchy-C.
  2. mon/OSDMonitor: refuse a rule that does not place a full set in each zone: the fix, a unit test in unittest_osd_monitor, and the documentation. mon-stretch-failed-pool-create.sh now uses a two-zone rule to reach the monitor check it tests.

Testing

  • Before the fix, a scratch script on one cluster tried seven cases: EC and replicated pool create, crush_rule and num_zones 2 on each, and the replica reuse. All seven were accepted. The EC pool on the one-zone rule had 15 of 16 PGs with a zone block that spanned both datacenters.
  • After the fix: all seven are refused with EINVAL and a reason, and mon-stretch-multi-zone-rule.sh passes.
  • All qa/standalone/mon-stretch scripts and qa/standalone/crush/crush-stretch.sh pass.
  • unittest_osd_monitor (with the new ValidateMultiZoneRule), unittest_mon_monmap, unittest_monmap_monitor and unittest_mon_election pass.

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

…e rule

A multi-zone pool needs a CRUSH rule that places each zone's block of
the pool (k+m shards, or the per-zone replicas) in a zone of its own, as
the rule that 'osd pool create --num_zones 2' builds does. Outside
global stretch mode the monitor does not check a rule it is given, so it
accepts one that chooses OSDs across the zones:

- 'osd pool create <pool> ... erasure <profile> <rule> --num_zones 2',
  and the replicated equivalent;
- 'osd pool set <pool> crush_rule <rule>' on a multi-zone pool;
- 'osd pool set <pool> num_zones 2 --crush_rule <rule>';
- 'osd pool set <pool> replica <n>' when it reuses an existing rule
  named <pool>-replica-<n>.

In teuthology job 611913 the EC pool was created on a rule made by
'osd crush rule create-erasure <rule>' from a one-zone profile. 10 of
its 16 PGs had up sets that mixed the datacenters within a zone's block
of shards, and stretch mode did not recover.

Add tests that try each of these with a one-zone rule and expect the
command to fail. They fail on stretchy-C, which accepts it. They also
check that pools are still created on rules that place a full set in
each zone: the generated rule, one from 'osd crush rule create-erasure
--num_zones 2' or 'create-stretch-replicated', and one that takes each
datacenter in turn, which the new add_zone_take_rule() builds.

Assisted-by: Claude Code
…zone

A multi-zone EC pool keeps shard s of zone z at position s + (k+m) * z,
and calc_ec_acting_stretch() serves each zone's block from one CRUSH
zone that no other block uses. A multi-zone replicated pool needs its
per-zone replicas in each zone. Outside global stretch mode the monitor
did not check that a rule it was given does this, so it accepted a rule
that chooses OSDs across the zones (see "qa/standalone/mon-stretch:
demonstrate a multi-zone pool on a one-zone rule"). In teuthology job
611913 10 of 16 PGs of such a pool got up sets that mixed the
datacenters within a zone's block.

Add OSDMonitor::validate_multi_zone_rule(), which reads the rule's steps
and accepts the two forms that place num_zones blocks of per_zone OSDs,
each block in its own bucket of the zone type:

- a take above the zones, a choose of the zone type that yields
  num_zones buckets, then choose/chooseleaf steps below the zone type
  that pick per_zone OSDs in each, as add_simple_stretch_rule() builds;
- one take/emit block per zone, each taking a different zone bucket, or
  a bucket or OSD inside it, and picking per_zone OSDs.

choosemsr is refused for the zone step, because it can move OSDs of a
block to another bucket of that step's type when an OSD is out.

Outside global stretch mode, the check runs when a multi-zone pool is
created, for 'osd pool set <pool> crush_rule' on a multi-zone stretch
pool, for 'osd pool set <pool> num_zones 2', and when
'osd pool set <pool> replica' reuses an existing <pool>-replica-<n>
rule. The command fails with EINVAL, for example:

  crush rule one_zone does not place 4 OSDs in each of 2 datacenter
  buckets: it chooses host items before choosing datacenter buckets

Generated stretch rules pass, so pool creation without a rule works as
before. Global stretch mode keeps its own check
(validate_stretch_mode_new_pool()).

mon-stretch-failed-pool-create.sh used replicated_rule to get a
multi-zone create past building a rule. It now uses a two-zone rule.

Assisted-by: Claude Code
@github-actions github-actions Bot added core documentation Improvements or additions to documentation mon tests labels Oct 8, 2026
@aainscow
aainscow requested a review from CJamesIBM October 9, 2026 11:59
@aainscow aainscow closed this Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core documentation Improvements or additions to documentation mon tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant