Skip to content

mgr/mirroring: fix directory rebalance after mirror daemon restart - #70942

Merged
kotreshhr merged 2 commits into
ceph:mainfrom
karthik-us1:mirror-rebalace-issue
Nov 6, 2026
Merged

kotreshhr merged 2 commits into
ceph:mainfrom
karthik-us1:mirror-rebalace-issue

Conversation

@karthik-us1

@karthik-us1 karthik-us1 commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

can_shuffle_dir() incorrectly treated DirectoryState as a dict (dir_state['mapped_time']), so rejoin-time shuffle raised TypeError, was swallowed by the Finisher, and left dirs stuck on the surviving daemon. Failover still worked because dead-instance removal force-shuffles without can_shuffle_dir().

Use dir_state.mapped_time. Even with that fix, dirs remapped during failover get a fresh mapped_time and stay under the 300s shuffle throttle, so an immediate add_instances() on rejoin often selects nothing. Shuffle only ran on instance add/remove, so the imbalance could persist indefinitely.

After add/remove, if the map is still uneven, arm a one-shot deferred rebalance for throttle_remaining() - time until the most recently mapped dir clears the 300s window. When it fires, rebalance() retries add_instances([]). So after rejoin, reshuffle is either immediate (dirs already past throttle) or automatically once that window elapses.

Uneven means max(live dir counts) - min(live dir counts) > 1. For example 5 dirs on 2 daemons can never be "balanced" (always 3+2), so deferred rebalance would keep moving one dir back and forth every throttle period. Allowing a difference of one treats 3+2 as done.

Re-arm only while dirs are still throttled or SHUFFLING is in flight. If shuffle returns nothing and the throttle has already elapsed, do not arm a ~1s retry loop (a no-op spin that wakes forever without moving dirs); wait for the next instance change instead.

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

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.

@karthik-us1

Copy link
Copy Markdown
Contributor Author

Will add the qa in the next update. Rebalance succeeded in the local testing after the remaining DIR_SHUFFLE_THROTTLE_INTERVAL in case of rejoin of mirror daemon before that interval elapsed.

@karthik-us1
karthik-us1 force-pushed the mirror-rebalace-issue branch from 12a017d to f8a3ab1 Compare August 19, 2026 11:33
@github-actions github-actions Bot added cephfs Ceph File System tests labels Aug 19, 2026
@vshankar

Copy link
Copy Markdown
Contributor

Use dir_state.mapped_time. Even with that fix, dirs remapped during failover get a fresh mapped_time and stay under the 300s shuffle throttle, so an immediate add_instances() on rejoin often selects nothing. Shuffle only ran on instance add/remove, so the imbalance could persist indefinitely.

mgr/mirroring should re-shuffle after DIR_SHUFFLE_THROTTLE_INTERVAL interval, right? (defaults to 300s).

@karthik-us1

karthik-us1 commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Use dir_state.mapped_time. Even with that fix, dirs remapped during failover get a fresh mapped_time and stay under the 300s shuffle throttle, so an immediate add_instances() on rejoin often selects nothing. Shuffle only ran on instance add/remove, so the imbalance could persist indefinitely.

mgr/mirroring should re-shuffle after DIR_SHUFFLE_THROTTLE_INTERVAL interval, right? (defaults to 300s).

Ideally it should have, but it is not. The throttle interval was introduced in e253f68 and it returns false from can_shuffle_dir when an add_instance request comes and the interval has not elapsed yet. There is no deferred rebalance logic to trigger it after it elapses.

@kotreshhr kotreshhr self-assigned this Oct 6, 2026
@vshankar
vshankar self-requested a review October 21, 2026 06:07

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

Detailed review is still pending

can_shuffle_dir() incorrectly treated DirectoryState as a dict
(dir_state['mapped_time']), so rejoin-time shuffle raised TypeError,
was swallowed by the Finisher, and left dirs stuck on the surviving
daemon. Failover still worked because dead-instance removal
force-shuffles without can_shuffle_dir().

Use dir_state.mapped_time. Even with that fix, dirs remapped during
failover get a fresh mapped_time and stay under the 300s shuffle
throttle, so an immediate add_instances() on rejoin often selects
nothing. Shuffle only ran on instance add/remove, so the imbalance
could persist indefinitely.

After add/remove, if the map is still uneven, schedule a deferred
rebalance via rebalance_at — a deadline checked by the existing
timer_task / process_updates() upkeep loop — for
throttle_remaining() (time until the most recently mapped dir clears
the 300s window). When due, rebalance() retries add_instances([]).
So after rejoin, reshuffle is either immediate (dirs already past
throttle) or automatically once that window elapses.

Uneven means max(live dir counts) - min(live dir counts) > 1. For
example 5 dirs on 2 daemons can never be "balanced" (always 3+2),
so deferred rebalance would keep moving one dir back and forth every
throttle period. Allowing a difference of one treats 3+2 as done.

Re-arm only while dirs are still throttled or SHUFFLING is in flight.
If shuffle returns nothing and the throttle has already elapsed, do
not keep a spinning deadline (a no-op that would wake forever without
moving dirs); wait for the next instance change instead.

Fixes: https://tracker.ceph.com/issues/79010
Signed-off-by: Karthik U S <[email protected]>
@karthik-us1
karthik-us1 force-pushed the mirror-rebalace-issue branch from f8a3ab1 to 33d4da0 Compare October 30, 2026 12:37
@karthik-us1
karthik-us1 requested a review from a team as a code owner October 30, 2026 12:37

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

lgtm. Good work!

Add test coverage for mirror directory rebalance across three HA
daemons, including initial distribution, failover/rejoin and
post-throttle stability checks.

After failover, assert directory concentration on surviving instances
rather than max-min > 1 — even dir counts can settle evenly on the
survivors (e.g. 4 dirs -> [2, 2]).

Fixes: https://tracker.ceph.com/issues/79010
Signed-off-by: Karthik U S <[email protected]>
@karthik-us1
karthik-us1 force-pushed the mirror-rebalace-issue branch from 33d4da0 to f6b7ef6 Compare November 3, 2026 16:23
@karthik-us1

Copy link
Copy Markdown
Contributor Author

@kotreshhr

Copy link
Copy Markdown
Contributor

This PR has been added to main integration testing by khiremat started 2026-11-01-06:48.

@kotreshhr

Copy link
Copy Markdown
Contributor

jenkins retest this please

@kotreshhr

Copy link
Copy Markdown
Contributor

@kotreshhr
kotreshhr merged commit 29dab52 into ceph:main Nov 6, 2026
14 checks passed
@yuriw

yuriw commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

This PR broke teuthology with the fs suite.

Heads up — this file's comment on line 14 has a Unicode em-dash (—) instead of a plain hyphen:

# Method paths only — loading the class would also run ~80 inherited

That breaks teuthology-suite's yaml merge for any branch carrying this file — it fails with:

yaml.reader.ReaderError: unacceptable character #x0080: special characters are not allowed
  in "<unicode string>", position 263

Result: the fs suite silently schedules 0 jobs on any branch that includes this commit (confirmed on wip-yuri16-testing, SHA1 ffb8c98d8e). Simple fix — swap the — for - or -- in that comment.

Fix: #73797

yuriw added a commit to yuriw/ceph that referenced this pull request Nov 11, 2026
A Unicode em-dash in a comment on this file (added in ceph#70942) makes
teuthology-suite's yaml merge fail with:

  yaml.reader.ReaderError: unacceptable character #x0080: special
  characters are not allowed

This silently schedules 0 jobs for the fs suite on any branch that
carries this file (confirmed on wip-yuri16-testing, SHA1 ffb8c98).

Swap the em-dash for a plain hyphen.

Signed-off-by: Yuri Weinstein <[email protected]>
Assisted-by: Claude Sonnet 5
@karthik-us1
karthik-us1 deleted the mirror-rebalace-issue branch November 12, 2026 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants