Skip to content

mds: introduce standby anti-affinity scoring matrix - #69801

Merged
vshankar merged 6 commits into
ceph:mainfrom
joscollin:wip-75892-standby-anti-affinity
Sep 1, 2026
Merged

vshankar merged 6 commits into
ceph:mainfrom
joscollin:wip-75892-standby-anti-affinity

Conversation

@joscollin

@joscollin joscollin commented Jun 29, 2026 •

Copy link
Copy Markdown
Member

This PR introduces a multi-tiered standby selection scoring matrix to the MDS Monitor to dynamically prioritise anti-affinity over software rules, protecting the cluster's failure domains.

  • Score-Based Selection Matrix: Implements a graded scoring matrix (Scores 1 to 6) across FSMap and MDSMonitor, that ensures both primary replacements and standby-replay followers are strictly barred from co-locating on the same physical host as an active or failing rank. This ensures different-host standbys strictly outrank same-host candidates.

  • Testing Coverage: Adds a dedicated unit tests verifying 6 distinct cases alongside a python functional QA task verifying live orchestration (with a scope limitation).

  • Documentation: Updates PendingReleaseNotes and standby.rst to accurately map out the new selection grid, score tiers, and state recovery behaviours.

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

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.

@joscollin

Copy link
Copy Markdown
Member Author

110/344 Test #177: unittest_mds_standby_affinity ............. Passed 0.50 sec

@joscollin
joscollin marked this pull request as ready for review June 29, 2026 12:43
@joscollin
joscollin requested review from a team as code owners June 29, 2026 12:43
@joscollin
joscollin removed the request for review from a team June 29, 2026 12:43

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

Love the new functionality. I left a few doc nit comments.

Comment thread doc/cephfs/standby.rst Resolved
Comment thread doc/cephfs/standby.rst Resolved
Comment thread doc/cephfs/standby.rst Resolved
Comment thread doc/cephfs/standby.rst Resolved
Comment thread doc/cephfs/standby.rst Resolved
Comment thread doc/cephfs/standby.rst Resolved
@joscollin
joscollin force-pushed the wip-75892-standby-anti-affinity branch 4 times, most recently from 89c15c3 to ef82056 Compare July 3, 2026 05:49
@vshankar
vshankar requested a review from a team July 7, 2026 06:44

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

Left some comments, but nothing critical. Nice enhancement to have 👍

Comment thread src/mds/FSMap.h Resolved
Comment thread src/mon/MDSMonitor.cc Resolved
};

/* Scenario A: Cross-Tier Prioritization (Same-Host Match vs. Different-Host Other FS).
* Even though Standby 1 perfectly matches the fscid, it shares a host.

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.

I think mds_join_fs should stand higher in terms of standby MDS even if it's in the same host.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@vshankar

I completely understand that mds_join_fs affinity is critical, and the new Score Matrix actually uses it as the primary guide across separate hosts. We intentionally put host isolation as the highest priority to prevent losing both the active and standby daemons at the exact same time.

If we prioritize mds_join_fs on the same host over a remote vanilla standby, a single hardware failure or an administrative reboot will kill both the active MDS and the standby. This completely defeats the purpose of having a standby and leaves us with a total outage. By keeping physical anti-affinity as the highest priority, we guarantee the standby is actually safe on a separate host. If same-host matching is needed, it still works perfectly as our fallback tier.

Let me know if that makes sense!

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.

Fair enough!

Comment thread PendingReleaseNotes
* CephFS: Added a multi-tiered scoring matrix to the MDS Monitor to dynamically
prioritize standby promotion during failover events. The `mds_join_fs` configuration
variable is now checked in combination with infrastructure topology rules to enforce
node anti-affinity constraints. An isolated, generic standby daemon (Score 5) will

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.

As I commented in the commit that introduces test for this, mds_join_fs should still be chosen over a generic standby in a different host.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

As I've mentioned in the above reply, prioritizing mds_join_fs on the same host over a remote vanilla standby creates a single point of failure during hardware failures or node reboots.

@joscollin
joscollin force-pushed the wip-75892-standby-anti-affinity branch from ef82056 to 69e2834 Compare July 16, 2026 06:05
class TestStandbyAffinity(CephFSTestCase):
MDSS_REQUIRED = 3

def test_standby_affinity_promotion(self):

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.

This test doesn't really test that the chosen standby is from a different host. Isn't that already done in test_failover.py?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You're right. test_standby_affinity_promotion doesn't check for different hosts. As mentioned in the commit message's "Note on Scope Limitation", simulating distinct physical hosts reliably in teuthology can be tricky. Teuthology environments often spin up on single test nodes and don't guarantee isolated multi-host topologies (correct me if I'm wrong). I've realized this after several failed attempts. Because of that limitation, I've decoupled the host anti-affinity matrix validation and validated it in the unit tests instead. See src/test/mds/TestStandbyAffinity.cc.

You could see ScenarioA_Cross_Tier_Prioritization and ScenarioF_Excluded_Host_Standby_Avoidance in the unit tests specifically validate that a standby on a different host outscores and overrides a same-host standby.

test_standby_affinity.py test is kept there to act as a basic integration smoke test to verify mds_join_fs triggers the correct standby promotion in a live cluster failover.

@vshankar

Copy link
Copy Markdown
Contributor

@joscollin - this change is mostly fine apart from the comment that I just posted. I also wanted to propose that we provide an option to disable this functionality (for convenience sake to folks who would rather choose to prefer mds_join_fs above everything else). WDYT?

@joscollin

Copy link
Copy Markdown
Member Author

@joscollin - this change is mostly fine apart from the comment that I just posted. I also wanted to propose that we provide an option to disable this functionality (for convenience sake to folks who would rather choose to prefer mds_join_fs above everything else). WDYT?

That makes sense. Providing an opt-out toggle is a great safeguard for users who want strict mds_join_fs enforcement regardless of host placement. Will work on it and update the PR.

Copilot AI review requested due to automatic review settings July 27, 2026 10:06
@joscollin
joscollin force-pushed the wip-75892-standby-anti-affinity branch from 69e2834 to 53dd062 Compare July 27, 2026 10:06
@joscollin
joscollin force-pushed the wip-75892-standby-anti-affinity branch from c73f38c to 9fae797 Compare August 26, 2026 10:18
@joscollin

Copy link
Copy Markdown
Member Author

@joscollin - I think existing test_failover.py needs to disable host anti affinity. See failure: https://pulpito.ceph.com/vshankar-2026-08-25_04:33:03-fs-wip-vshankar-testing-20260824.070857-distro-default-trial/511591/

@vshankar
Fixed by updating qa/suites/fs/multifs/tasks/failover.yaml

@joscollin
joscollin force-pushed the wip-75892-standby-anti-affinity branch 2 times, most recently from 3d24306 to 27e20f1 Compare August 27, 2026 11:55
@vshankar

Copy link
Copy Markdown
Contributor

jenkins retest this please

@vshankar

Copy link
Copy Markdown
Contributor

jenkins test dashboard

@vshankar

Copy link
Copy Markdown
Contributor

jenkins test dashboard cephadm e2e

@joscollin

Copy link
Copy Markdown
Member Author

jenkins test dashboard cephadm e2e

@vshankar Please see:
#70799
#70273

@vshankar

vshankar commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

jenkins test dashboard

In the past, standby selection did not account for failure domains,
allowing a standby daemon to be assigned or promoted on the exact
same physical host as the active daemon it was intended to back up.

This commit introduces a score-based anti-affinity matrix to FSMap
and updates MDSMonitor allocation loops to pass target addresses.
This strictly prioritizes remote standbys (different host) over
same-host standbys for both active replacements and standby-replay
assignments to maximize failure domain isolation. The logic handles
hot updates and cold crash recoveries by enforcing anti-affinity.

Additionally, this introduces the `standby_enable_host_anti_affinity`
per-filesystem setting (managed via `ceph fs set`, default: true) to
allow users to explicitly toggle this behavior. When set to `false`,
the selection algorithm bypasses the host isolation checks, scoring all
standbys in the `SCORE_PREF_*` tier. This effectively restores the legacy
behavior where strict `mds_join_fs` preferences win unconditionally,
regardless of physical placement.

Fixes: https://tracker.ceph.com/issues/75892
Signed-off-by: Jos Collin <[email protected]>
Introduce a dedicated test in src/test/mds/TestStandbyAffinity.cc to
directly validate the score-based selection matrix inside FSMap.

The test case evaluates three core topology distribution scenarios:
1. Cross-tier prioritization: Ensuring a remote vanilla standby
   outscores an explicit FSCID match residing on the same host.
2. Short-circuit optimization: Confirming immediate selection when a
   perfect candidate (matching FSCID + different host) is found.
3. Fallback graceful degradation: Verifying that standard affinity
   preferences are preserved if all available standbys share the
   active daemon's host.
4. Multi-active avoidance: Proving the matrix correctly avoids an
   array of multiple hosts when a filesystem has multiple active ranks.
5. Deterministic tie-breaking: Ensuring the algorithm safely and
   predictably selects a winner when multiple remote candidates share
   the exact same maximum score.
6. Excluded host standby avoidance: Verifying that the host penalty
   is correctly applied to override a filesystem match when a standby
   resides on an excluded host, safely promoting a clean vanilla candidate.
7. Feature flag disabled: Validating that disabling the filesystem's
   'standby_enable_host_anti_affinity' MDSMap flag successfully
   bypasses host penalties and restores legacy scoring logic.

Fixes: https://tracker.ceph.com/issues/75892
Signed-off-by: Jos Collin <[email protected]>
Introduce a functional integration test to validate the end-to-end configuration
and wire communication pipeline for MDS standby affinity during a live failover.

test_standby_affinity_promotion: Forces a failover scenario to ensure that an
operator's 'mds_join_fs' configuration safely propagates from a live daemon's
beacon to the MDSMonitor, correctly resulting in the priority promotion of a
preferred standby over a generic vanilla option.

Additionally, this updates the CephFS QA framework (filesystem.py) to explicitly
disable `standby_enable_host_anti_affinity` by default when creating test
filesystems. Because Teuthology densely packs MDS daemons onto limited nodes,
legacy failover tests will timeout if hardware anti-affinity is strictly enforced.
However, the feature is now safely opted-into for this specific test suite via a YAML
override in `tasks/standby-affinity.yaml`.

Scope Limitation:
This QA test is intentionally scoped as a basic integration smoke test to verify
the configuration plumbing and daemon-to-monitor protocol. Because teuthology
environments typically spin up on single test nodes or do not guarantee isolated
multi-host topologies, fine-grained scoring matrix scenarios (such as the host
anti-affinity subtraction loops where active_addrs is evaluated) are decoupled and
validated via unit test cases in src/test/mds/TestStandbyAffinity.cc instead.

Fixes: https://tracker.ceph.com/issues/75892
Signed-off-by: Jos Collin <[email protected]>
Update the file system affinity documentation to accurately detail the
multi-tiered scoring engine used by the Monitors during failover.

Explicitly documents the priority scoring matrix (Scores 1 through 6)
and clarifies how the selection engine balances software-defined
'mds_join_fs' configurations against physical host anti-affinity rules.
This includes the 'standby_enable_host_anti_affinity' per-filesystem
toggle (configured via 'ceph fs set') that allows operators to opt-out
of host penalties.

Additionally, define the behavioral distinctions across the three
core anti-affinity rules: Hot Takeovers, Stale/Purged Topology
Recovery, and Cross-FS Failover Restrictions.

Updated the PendingReleaseNotes highlighting the new tiered scoring
matrix and the per-filesystem configuration toggle used during standby
promotion cycles.

Fixes: https://tracker.ceph.com/issues/75892
Signed-off-by: Jos Collin <[email protected]>
The recent introduction of the 'standby_enable_host_anti_affinity'
per-filesystem setting added a new boolean field to the MDSMap
JSON dump.

This commit updates the __mdsmap_schema in test_health.py to
expect this new 'standby_enable_host_anti_affinity' key,
resolving the dashboard API validation failure in the CI.

Fixes: https://tracker.ceph.com/issues/75892
Signed-off-by: Jos Collin <[email protected]>
This commit fixes a long-standing race condition in test_failover.py.
Previously, the test would update the mds_join_fs configuration for a
standby daemon and immediately force an MDS rank failure. This created
a timing window where the MDSMonitor could evaluate standby candidates
using stale configuration data.

Historically, this race was masked by the legacy fallback tie-breaker
logic, which often coincidentally promoted the correct daemon. However,
with stricter, deterministic tie-breaking, this missing synchronization
barrier caused unexpected promotion failures.

By adding `self._reach_target(target)` before `self.fs.rank_fail()`,
we establish a proper synchronization barrier. This guarantees that the
Monitor has fully processed the configuration update before the failover
event is triggered, ensuring test determinism and eliminating flakiness.

Signed-off-by: Jos Collin <[email protected]>
@joscollin
joscollin force-pushed the wip-75892-standby-anti-affinity branch from 27e20f1 to b219b2b Compare September 1, 2026 08:48
@joscollin

Copy link
Copy Markdown
Member Author

@vshankar rebased.

@joscollin
joscollin removed the request for review from a team September 1, 2026 10:35
@joscollin

Copy link
Copy Markdown
Member Author

jenkins test dashboard cephadm e2e

@joscollin

Copy link
Copy Markdown
Member Author

jenkins test dashboard cephadm

@vshankar
vshankar merged commit 04d5c81 into ceph:main Sep 1, 2026
7 checks passed
@github-project-automation github-project-automation Bot moved this from Reviewer approved to Done in Ceph-Dashboard Sep 1, 2026
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

This is an automated message by src/script/redmine-upkeep.py.

I have resolved the following tracker ticket due to the merge of this PR:

No backports are pending for the ticket. If this is incorrect, please update the tracker
ticket and reset to Pending Backport state.

Update Log: https://github.com/ceph/ceph/actions/runs/33511773003

@vshankar

vshankar commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants