Skip to content

Skip undersized PGs in balance() instead of aborting the run - #71

Open
lhns wants to merge 1 commit into
TheJJ:masterfrom
lhns:fix/balance-skip-undersized-pg
Open

lhns wants to merge 1 commit into
TheJJ:masterfrom
lhns:fix/balance-skip-undersized-pg

Conversation

@lhns

@lhns lhns commented Apr 30, 2026 •

Copy link
Copy Markdown
Contributor

Symptom: balance aborts on the first undersized PG it considers as a move candidate with

File "placementoptimizer.py", line 2702, in __init__
    raise RuntimeError(f"not as many roots as shards! root_order={root_order} osds={self.pg_osds}")
RuntimeError: not as many roots as shards! root_order=['default~nvme', 'default~nvme', 'default~nvme'] osds=[32, 4]

raised from PGMoveChecker.init via balance() at line 4809.

Root cause: PGMappings populates self.pg_mappings[pgid] directly from pginfo["up"] without normalising its length against pool_size. When CRUSH cannot place all shards (host failure, exhausted candidates, etc.), the up set is shorter than pool_size, so len(pg_osds) != len(root_order) and PGMoveChecker raises. The exception propagates up and kills the whole balance run.

Fix: catch RuntimeError around the PGMoveChecker construction in balance() and continue to the next candidate, mirroring the existing skip pattern used for other unmovable candidates a few lines above. Recovering an undersized PG is Ceph's job — moving its remaining shards via upmap is unsafe to plan against, so skipping is the correct behaviour.

Just to be clear, this is one of three AI generated fixes. I collected these three issues over the last few months and wanted to see if claude could find sensible fixes and it looked good to me. If you don't like this, I won't do this again.

Symptom: balance aborts on the first undersized PG it considers as a
move candidate with

    File "placementoptimizer.py", line 2702, in __init__
        raise RuntimeError(f"not as many roots as shards! root_order={root_order} osds={self.pg_osds}")
    RuntimeError: not as many roots as shards! root_order=['default~nvme', 'default~nvme', 'default~nvme'] osds=[32, 4]

raised from PGMoveChecker.__init__ via balance() at line 4809.

Root cause: PGMappings populates `self.pg_mappings[pgid]` directly
from `pginfo["up"]` without normalising its length against
`pool_size`. When CRUSH cannot place all shards (host failure,
exhausted candidates, etc.), the up set is shorter than pool_size,
so `len(pg_osds) != len(root_order)` and PGMoveChecker raises. The
exception propagates up and kills the whole balance run.

Fix: catch RuntimeError around the PGMoveChecker construction in
balance() and `continue` to the next candidate, mirroring the
existing skip pattern used for other unmovable candidates a few
lines above. Recovering an undersized PG is Ceph's job — moving its
remaining shards via upmap is unsafe to plan against, so skipping is
the correct behaviour.
Comment thread placementoptimizer.py
# planned upmap is meaningful anyway.
try:
try_pg_move = PGMoveChecker(pg_mappings, move_pg)
except RuntimeError as exc:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

we should handle this case properly :) we should not catch all runtime errors, instead we should add a code path that deals with this expected cluster state

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.

Makes sense, I will revise this PR

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants