Keep PG count when optimize_change drops PGs instead of moving them #178

Open
koolkhel wants to merge 3 commits from koolkhel/vitastor:mon-keep-pg-count into master
Contributor

Description

The LP in optimize_change() has no constraint on the total PG count, and make_int_pgs() scales whatever is left back to pg_count. In an EC pool (ordered) a moved PG costs 2 or more, so the LP may prefer to drop PGs from overloaded failure domains rather than move them. The remaining PGs are then scaled back onto the same domains:

  • a host returns to an EC 4+2 pool on 7 hosts (128 PGs, all of them on the other 6 hosts): the LP drops 18.3 PGs, the returned host keeps 0 PGs and the pool stays at 85.7 % (6/7) space efficiency;
  • a host leaves an EC 8+2 pool on 12 hosts (256 PGs): the LP places 232.7 of 256 PGs; after scaling another, healthy host is left with 0 PGs and the other 10 hosts get 256 PGs each instead of 233.

A recheck doesn't fix it, since it sees the same input. Replicated pools are not affected (a moved PG costs 1).

optimize_change() now solves with the PG count fixed (sum(add - del) + sum(new) = pg_count - kept) and solves without it only when that is infeasible (failure domains that can't take pg_count PGs at their shares). The pool's change stats then say that some OSDs get more than their share. Where the LP without the condition already kept the PG count, the objective is the same, but lp_solve may return another solution with the same score.

Found: on a 7-host EC 4+2 cluster a host was out for longer than osd_out_time and came back; it kept 1 PG instead of ~110, and the pool stayed at 85.3 % space efficiency.

Tested: new mon/lp_optimizer/test-optimize-keep-count.js covers both cases above and the fallback (EC 4+2 on 6 hosts, one 3 times bigger). It fails on master (host 1 has 128 PGs, expected 109.7) and passes with the fix (109–110 PGs per host, 99.74 %, 110 PGs moved; 232–233 per host, 99.88 %, 233 moved). Same results through generate_pool_pgs() with folded failure domains. The other mon/lp_optimizer/test-*.js reach the same LP objective as on master; test-nonuniform.js gets another solution with the same score (96.0 % space efficiency instead of 98.1 %), and test-optimize-simple.js fails with "Redistribution failed" on master too.

Contributor Name

Yury Luneff (MIND Software LLC, https://mindsw.io)

CLA

### Description The LP in `optimize_change()` has no constraint on the total PG count, and `make_int_pgs()` scales whatever is left back to `pg_count`. In an EC pool (`ordered`) a moved PG costs 2 or more, so the LP may prefer to drop PGs from overloaded failure domains rather than move them. The remaining PGs are then scaled back onto the same domains: - a host returns to an EC 4+2 pool on 7 hosts (128 PGs, all of them on the other 6 hosts): the LP drops 18.3 PGs, the returned host keeps 0 PGs and the pool stays at 85.7 % (6/7) space efficiency; - a host leaves an EC 8+2 pool on 12 hosts (256 PGs): the LP places 232.7 of 256 PGs; after scaling another, healthy host is left with 0 PGs and the other 10 hosts get 256 PGs each instead of 233. A recheck doesn't fix it, since it sees the same input. Replicated pools are not affected (a moved PG costs 1). `optimize_change()` now solves with the PG count fixed (`sum(add - del) + sum(new) = pg_count - kept`) and solves without it only when that is infeasible (failure domains that can't take `pg_count` PGs at their shares). The pool's change stats then say that some OSDs get more than their share. Where the LP without the condition already kept the PG count, the objective is the same, but lp_solve may return another solution with the same score. Found: on a 7-host EC 4+2 cluster a host was out for longer than `osd_out_time` and came back; it kept 1 PG instead of ~110, and the pool stayed at 85.3 % space efficiency. Tested: new `mon/lp_optimizer/test-optimize-keep-count.js` covers both cases above and the fallback (EC 4+2 on 6 hosts, one 3 times bigger). It fails on master (host 1 has 128 PGs, expected 109.7) and passes with the fix (109–110 PGs per host, 99.74 %, 110 PGs moved; 232–233 per host, 99.88 %, 233 moved). Same results through `generate_pool_pgs()` with folded failure domains. The other `mon/lp_optimizer/test-*.js` reach the same LP objective as on master; `test-nonuniform.js` gets another solution with the same score (96.0 % space efficiency instead of 98.1 %), and `test-optimize-simple.js` fails with "Redistribution failed" on master too. ### Contributor Name Yury Luneff (MIND Software LLC, https://mindsw.io) ### CLA - [x] I accept Vitastor CLA agreement: https://git.yourcmc.ru/vitalif/vitastor/src/branch/master/CLA-en.md
koolkhel added 1 commit 2026-11-24 23:04:52 +03:00
The LP in optimize_change() has no constraint on the total PG count,
and make_int_pgs() scales whatever is left back to pg_count. In an EC
pool (ordered) a moved PG costs 2 or more, so the LP may prefer to drop
PGs from overloaded failure domains rather than move them. The rest are
then scaled back onto the same domains: a host returning to an EC 4+2
pool on 7 hosts keeps 0 PGs and the pool stays at 6/7 efficiency, and a
host leaving an EC 8+2 pool on 12 hosts leaves another host empty.

If the solution loses PGs, solve again with the PG count fixed, and
keep the first solution when that is infeasible.
koolkhel added 1 commit 2026-11-25 02:42:18 +03:00
When the PG count can't be kept within OSD sizes (failure domains too
unequal for pg_count PGs at their shares), the first solution is kept
and some OSDs get more than their share. Say so instead of keeping it
silently.
vitalif requested changes 2026-11-26 00:11:08 +03:00
vitalif left a comment
Owner

Если так, то может сделать наоборот - сначала решать с доп.условием, а уж потом, если не получается - то без?

Если так, то может сделать наоборот - сначала решать с доп.условием, а уж потом, если не получается - то без?
koolkhel added 1 commit 2026-11-26 14:36:43 +03:00
Add the PG count condition to the first solve and solve without it only
when that is infeasible, instead of re-solving after a solution that
lost PGs. Return the fallback as over_share and print it with the pool's
change stats: pools are optimized concurrently, so a separate log line
can't be matched to its pool. Bound the data movement in the test and
add a case where the PG count can't be kept.
Author
Contributor

Если так, то может сделать наоборот - сначала решать с доп.условием, а уж потом, если не получается - то без?

Сделал в 5cf77636: сначала решается с условием на число PG, без него только если решения нет, и тогда в статистике пула пишется, что часть OSD получает больше своей доли; в тест добавлен такой случай.
Где и без условия число PG сохранялось, значение целевой функции то же, но lp_solve может вернуть другое решение с той же оценкой: в test-nonuniform.js эффективность 96,0 % вместо 98,1 %.

> Если так, то может сделать наоборот - сначала решать с доп.условием, а уж потом, если не получается - то без? Сделал в 5cf77636: сначала решается с условием на число PG, без него только если решения нет, и тогда в статистике пула пишется, что часть OSD получает больше своей доли; в тест добавлен такой случай. Где и без условия число PG сохранялось, значение целевой функции то же, но lp_solve может вернуть другое решение с той же оценкой: в test-nonuniform.js эффективность 96,0 % вместо 98,1 %.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u mon-keep-pg-count:koolkhel-mon-keep-pg-count
git checkout koolkhel-mon-keep-pg-count
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vitalif/vitastor#178
No description provided.