Skip to content

mon, crush/CrushWrapper: Create default crush rule for replicated stretch mode - #68666

Closed
Ericmzhang wants to merge 15 commits into
ceph:mainfrom
Ericmzhang:wip-autogenerate-stretch-crush-rule
Closed

Ericmzhang wants to merge 15 commits into
ceph:mainfrom
Ericmzhang:wip-autogenerate-stretch-crush-rule

Conversation

@Ericmzhang

@Ericmzhang Ericmzhang commented Apr 28, 2026 •

Copy link
Copy Markdown
Contributor

Motivation: To support EC stretch mode, we need to automatically generate stretch crush rules (starting with replicated pools first)

Solution: Add a cli command to create CRUSH rules for replica pools in stretch mode.

 ceph osd crush rule create-stretch-replicated [{name}] [{root}] [{zone-failure-domain}]
   [{osd-failure-domain}] [{zones}] [{num_replica_per_zone}] [--force] [{class}]

Create a wrapper function CrushWrapper::add_simple_stretch_rule_at to create the default replica stretch rule

rule stretch_rule {
  id 2
  type replicated
  step take default
  step choose firstn 0 type datacenter
  step chooseleaf firstn 2 type host
  step emit
}

This wrapper function will in the future be used to also create EC stretch rules.

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

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.

@Ericmzhang
Ericmzhang force-pushed the wip-autogenerate-stretch-crush-rule branch 2 times, most recently from 342344a to 69f5c9f Compare April 29, 2026 15:15
@Ericmzhang

Copy link
Copy Markdown
Contributor Author

Added tracker to commit messages.

Comment thread doc/rados/operations/crush-map.rst Resolved
local dir=$1
shift

export CEPH_MON="127.0.0.1:7133" # git grep '\<7133\>' : there must be only one

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.

Not unique!

qa/standalone/mon/mon-bind.sh: export MONB_PUBLIC=7133 # git grep '<7133>' ; there must be only one

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to 7159

Comment thread src/crush/CrushWrapper.cc Outdated
crush_rule_set_step(
rule, step++,
CRUSH_RULE_CHOOSELEAF_FIRSTN,
2,

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.

Probably want to be able to pass this value in as a parameter. Here you are creating a stretched replica pool crush rule that supports 2 copies at each site. It would be nice to be able to generalize the number of copies you have at each site rather than only supporting 2.

I suspect you'll be able to further generalize this code to support either firstn or indep so that it can generate rules for stretch EC pools as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added num_osds_per_zone cli arg to support multiple copies per site.

@Ericmzhang
Ericmzhang force-pushed the wip-autogenerate-stretch-crush-rule branch from 69f5c9f to 737107a Compare April 29, 2026 21:07
@Ericmzhang

Copy link
Copy Markdown
Contributor Author

Made suggested changes from above.

@kamoltat kamoltat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pushing the change! I left some comments, mostly nits and maybe some unit-test additions if time permits.

Comment thread src/crush/CrushWrapper.cc
Comment on lines +2512 to +2514
if(ret < 0) {
*err << "failed to add rule " << rno << " because " << cpp_strerror(ret);
free(rule);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets guard err

if (err) {
*err << "failed to add rule " << rno << " because " << cpp_strerror(ret);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread src/mon/MonCommands.h Outdated
"name=zone_failure_domain,type=CephString,req=false,goodchars=[A-Za-z0-9-_.] "
"name=osd_failure_domain,type=CephString,req=false,goodchars=[A-Za-z0-9-_.] "
"name=zones,type=CephInt,range=0,req=false "
"name=num_osds_per_zone,type=CephInt,range=0,req=false "

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets change the num_osds_per_zone to num_replica_per_zone

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread src/crush/CrushWrapper.cc Outdated
for (auto child : children) {
std::vector<int> osd_failure_domains;
get_children_of_type(child, osd_type, &osd_failure_domains, false);
if (int(osd_failure_domains.size()) < num_osds_per_zone) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should change num_osds_per_zone to num_replica_per_zone

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread src/mon/OSDMonitor.cc
bool force = false;
cmd_getval(cmdmap, "force", force);
string device_class;
cmd_getval(cmdmap, "class", device_class);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stretch mode replica doesn't support device classes just yet, we might want to support that, but that might require some re-work.

Comment thread src/crush/CrushWrapper.cc
<< zone_failure_domain_name << " is less than num_failure_domains " << num_failure_domains;
return -EINVAL;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets add a check for num_failure_domains > 0 and num_replicas_per_zone > 0, we want to prevent the user from doing something silly

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

Comment thread doc/rados/operations/crush-map.rst Outdated
.. prompt:: bash $

ceph osd crush rule create-stretch-replicated [{name}] [{root}] [{zone-failure-domain}]
[{osd-failure-domain}] [{zones}] [{num_osds_per_zone] [--force] [{class}]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[{num_osds_per_zone}]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines +1 to +81
#!/usr/bin/env bash

source $CEPH_ROOT/qa/standalone/ceph-helpers.sh

function run() {
local dir=$1
shift

export CEPH_MON="127.0.0.1:7159" # git grep '\<7159\>' : there must be only one
export CEPH_ARGS
CEPH_ARGS+="--fsid=$(uuidgen) --auth-supported=none "
CEPH_ARGS+="--mon-host=$CEPH_MON "
#
# Disable auto-class, so we can inject device class manually below
#
CEPH_ARGS+="--osd-class-update-on-start=false "

local funcs=${@:-$(set | sed -n -e 's/^\(TEST_[0-9a-z_]*\) .*/\1/p')}
for func in $funcs ; do
setup $dir || return 1
$func $dir || return 1
teardown $dir || return 1
done
}

function TEST_stretch_replicated() {
local dir=$1
run_mon $dir a || return 1
run_osd $dir 0 || return 1
run_osd $dir 1 || return 1
run_osd $dir 2 || return 1
run_osd $dir 3 || return 1

ceph osd crush add-bucket site1 datacenter
ceph osd crush add-bucket site2 datacenter
ceph osd crush move site1 root=default
ceph osd crush move site2 root=default
ceph osd tree
ceph osd crush rule create-stretch-replicated
ceph osd crush rule create-stretch-replicated 2>&1 | grep "Error EINVAL: zone site1 has only 0 items of type host" || return 1

ceph osd crush add-bucket host1 host
ceph osd crush move host1 datacenter=site1
ceph osd crush rule create-stretch-replicated 2>&1 | grep "Error EINVAL: zone site1 has only 1 items of type host" || return 1

ceph osd crush add-bucket host2 host
ceph osd crush move host2 datacenter=site1
ceph osd crush rule create-stretch-replicated 2>&1 | grep "Error EINVAL: host host1 has no OSDs" || return 1

ceph osd crush set osd.0 1.0 host=host1
ceph osd crush rule create-stretch-replicated 2>&1 | grep "Error EINVAL: host host2 has no OSDs" || return 1

ceph osd crush set osd.1 1.0 host=host2
ceph osd crush rule create-stretch-replicated 2>&1 | grep "Error EINVAL: zone site2 has only 0 items of type host" || return 1

ceph osd crush add-bucket host3 host
ceph osd crush move host3 datacenter=site2
ceph osd crush rule create-stretch-replicated 2>&1 | grep "Error EINVAL: zone site2 has only 1 items of type host" || return 1

ceph osd crush add-bucket host4 host
ceph osd crush move host4 datacenter=site2
ceph osd crush rule create-stretch-replicated 2>&1 | grep "Error EINVAL: host host3 has no OSDs" || return 1


ceph osd crush set osd.2 1.0 host=host3
ceph osd crush rule create-stretch-replicated 2>&1 | grep "Error EINVAL: host host4 has no OSDs" || return 1

ceph osd crush set osd.3 1.0 host=host4

ceph osd crush rule create-stretch-replicated || return 1

ceph osd crush rule dump stretch_rule | jq '.steps[1].op' | grep "choose_firstn" || return 1
ceph osd crush rule dump stretch_rule | jq '.steps[1].num' | grep "0" || return 1
ceph osd crush rule dump stretch_rule | jq '.steps[1].type' | grep "datacenter" || return 1

ceph osd crush rule dump stretch_rule | jq '.steps[2].op' | grep "chooseleaf_firstn" || return 1
ceph osd crush rule dump stretch_rule | jq '.steps[2].num' | grep "2" || return 1
ceph osd crush rule dump stretch_rule | jq '.steps[2].type' | grep "host" || return 1
}

main crush-stretch "$@"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe name it crush-stretch-replicated, unless you are planning to add crush-stretch-ec into this as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I was planning to add test for stretch-ec as well.

Comment thread qa/standalone/crush/crush-stretch.sh Outdated
Comment on lines +34 to +35
ceph osd crush add-bucket site1 datacenter
ceph osd crush add-bucket site2 datacenter

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets move away from "site" and use "dc1" and "dc2" since Alex mentioned in the stretch EC document that we want to move away from site

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for creating this standalone teuthology test. One of the things I have started doing for any new stretch mode PRs is creating more unit tests, since it is cheaper and the chance of it running is 100% because it is triggered in make check. Sometimes, let’s say the teuthology rados suite runs this script—what if there is an orchestration error or just a machine error in folio or trial? Then maybe we don’t get to trigger this script. If time permits, maybe adding a unittest is also a good idea. See: https://github.com/ceph/ceph/pull/68409/changes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added unit test case to test/CrushWrapper.cc

@Ericmzhang
Ericmzhang force-pushed the wip-autogenerate-stretch-crush-rule branch from 737107a to 823dcaf Compare May 1, 2026 17:11
@Ericmzhang
Ericmzhang force-pushed the wip-autogenerate-stretch-crush-rule branch 2 times, most recently from 253563f to 10fa769 Compare May 5, 2026 22:45
@Ericmzhang

Copy link
Copy Markdown
Contributor Author

Made changes to review above. Added unit test to test/CrushWrapper.cc. Extracted handling in "osd crush create-replicated" and "osd crush create-stretch-replicated" to helper function crush_rule_create_replica()

@Ericmzhang
Ericmzhang force-pushed the wip-autogenerate-stretch-crush-rule branch from 10fa769 to 1d5db48 Compare May 5, 2026 23:39
aainscow added 8 commits May 6, 2026 13:36
Previously bitset set did not exploit its bit-set nature by providing
bitshift and other logical operators.

Here we add <<, >>, <<=, >>=, &, |, &=

Signed-off-by: Alex Ainscow <[email protected]>
Previously, there was no way of swapping out a transaction intended for
one shard and applying it a different shard.

This kind of functionality is very useful for EC stretched mode, as we
often want to send the same transaction to two different shards.

Due to the way transactions store a table of objects, it turns out that
this is surprisingly simply process!

Signed-off-by: Alex Ainscow <[email protected]>
This commit reflects an old design. We put the num_zones in the profile.

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

# Conflicts:
#	src/test/osd/ECPeeringTestFixture.cc
#	src/test/osd/ECPeeringTestFixture.h
#	src/test/osd/MockPGBackendListener.h
#	src/test/osd/OSDMapTestHelpers.h
#	src/test/osd/PGBackendTestFixture.h
#	src/test/osd/TestECFailoverWithPeering.cc
@Ericmzhang
Ericmzhang force-pushed the wip-autogenerate-stretch-crush-rule branch from 85a5b26 to a38c009 Compare May 6, 2026 22:29
@Ericmzhang

Copy link
Copy Markdown
Contributor Author

Was only adding a stretch crush rule instead of adding crush rule based on num_zones

@Ericmzhang
Ericmzhang force-pushed the wip-autogenerate-stretch-crush-rule branch from a38c009 to b27cfdd Compare May 6, 2026 22:42
@kamoltat

kamoltat commented May 7, 2026

Copy link
Copy Markdown
Member

@Ericmzhang Think we are missing a Signed-off-by on: 637c3295e1bee02947502519daa590103d04adc1

Comment thread doc/rados/operations/crush-map.rst Outdated
:Default: ``2``

``num_replica_per_zone``
:Description: The expected number of osds per zone.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe: "The expected number of replica failure-domain to choose per zone"

Comment thread doc/rados/operations/crush-map.rst Outdated
.. prompt:: bash $

ceph osd crush rule create-stretch-replicated [{name}] [{root}] [{zone-failure-domain}]
[{osd-failure-domain}] [{zones}] [{num_replica_per_zone] [--force] [{class}]

@kamoltat kamoltat May 7, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[{osd-failure-domain}] [{zones}] [{num_replica_per_zone] [--force] [{class}]
[{osd-failure-domain}] [{zones}] [{num_replica_per_zone}] [--force] [{class}]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@Ericmzhang
Ericmzhang force-pushed the wip-autogenerate-stretch-crush-rule branch from b27cfdd to a752d83 Compare May 7, 2026 15:53
@Ericmzhang

Copy link
Copy Markdown
Contributor Author

Made doc changes above

aainscow and others added 7 commits May 8, 2026 09:10
Extended the relative shard logic to ScrubBackend::match_in_shards, and
ScrubBackend::setup_ec_digest_map. When populating the digests map during
shard comparison, the function now:

1. Converts absolute shard IDs to relative shards using get_rel_shard()
2. Checks if a relative shard entry already exists in the digests map
3. If it exists, compares the CRC values byte-by-byte
4. Reports a scrub error (sets digest_match = false) if CRCs don't match

This ensures consistent CRC verification across zones for the same relative
shard positions during the object comparison phase of scrubbing.

Tested: All OSD unit tests pass (18/18)

The scrubber was using absolute shard IDs when calling get_version_for_shard(),
which caused false 'object info inconsistent' errors in EC pools with zone
duplication. The issue occurred because get_version_for_shard() expects relative
shard IDs (shard % (k+m)), not absolute shard IDs.

Fixed by converting absolute shard IDs to relative shard IDs using
get_ec_sinfo().get_rel_shard() for EC pools before calling get_version_for_shard().
This conversion is only needed for EC pools; replicated pools continue to use
the shard ID directly.

Signed-off-by: Alex Ainscow <[email protected]>
Add wrapper function add_simple_stretch_rule for default replicated stretch crush rule
rule stretch_replicated_rule {
        id 2
        type replicated
        step take default
        step choose firstn 0 type datacenter
        step chooseleaf firstn 2 type host
        step emit
}

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

Signed-off-by: Eric Zhang <[email protected]>
Added  "osd crush rule create-stretch-replicated" command and handling for it.
Advanced flags:
--zones Default Value: 2
--zone_failure_domain Default Value: datacenter
--crush_root Default Value: The cluster root (default).
--osd_failure_domain Default Value: host
--force Default Value: false

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

Signed-off-by: Eric Zhang <[email protected]>
…e Test validation for zones >= num_failure_domain, osd_failure_domain>=2,

at least one osd per host

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

Signed-off-by: Eric Zhang <[email protected]>
@Ericmzhang
Ericmzhang force-pushed the wip-autogenerate-stretch-crush-rule branch from a752d83 to 02c556d Compare May 11, 2026 21:37
@github-actions

Copy link
Copy Markdown

Config Diff Tool Output


! changed: osd_pool_default_erasure_code_profile: old: plugin=isa technique=reed_sol_van k=2 m=2 (global.yaml.in)
! changed: osd_pool_default_erasure_code_profile: new: plugin=isa technique=reed_sol_van k=2 m=2 num_zones=1 (global.yaml.in)

The above configuration changes are found in the PR. Please update the relevant release documentation if necessary.
Ignore this comment if docs are already updated. To make the "Check ceph config changes" CI check pass, please comment /config check ok and re-run the test.

@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

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs for another 30 days.
If you are a maintainer or core committer, please follow-up on this pull request to identify what steps should be taken by the author to move this proposed change forward.
If you are the author of this pull request, thank you for your proposed contribution. If you believe this change is still appropriate, please ensure that any feedback has been addressed and ask for a code review.

@github-actions github-actions Bot added the stale label Jul 18, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been automatically closed because there has been no activity for 90 days. Please feel free to reopen this pull request (or open a new one) if the proposed change is still appropriate. Thank you for your contribution!

@github-actions github-actions Bot closed this Aug 17, 2026
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.

4 participants