mon: Keep positions of surviving OSDs in EC PGs on re-layout #214

Merged
vitalif merged 7 commits from koolkhel/vitastor:mon-keep-ec-positions into master 2026-12-02 19:51:58 +03:00
Contributor

Description

In EC pools the position of an OSD in a PG is the number of the chunk it holds. optimize_change() takes changed sets from sorted combinations (the combinator sorts them, only optimize_initial() rotates them in make_int_pgs), so every changed PG came back sorted: OSDs that stayed in the PG changed positions and their chunks moved too, and after a few re-layouts the last hosts held only parity chunks (so they never become primary). This keeps the positions of the OSDs that stay and puts new ones into the vacated positions, rotated by PG number as optimize_initial() does. Replicated pools (ordered false) and pg_size changes are not touched. The previous set's members are mapped to their positions once per PG and placed once, and only the new items are tried over rotations; a member may hold several positions, since folded failure domains can repeat in a set (previous sets of a host-out re-layout do contain repeated hosts). The new order is used only if it passes the pool's placement rules, so positional rules like host=112233 keep their order. This is the round robin after the LP discussed in Telegram.

Model with the monitor code, 12 hosts x 48 OSDs, EC 8+2, 2048 PGs (chunk moves, before -> after):

event before after
host out 11592 3306
same host back 14535 3424
host added 14372 3104
one host reweighted to half 8662 1508

On the real (fully host-ordered) PG map of such a cluster: one host out 5830 -> 2875 chunk moves, back 7192 -> 3096, reweight to 0.5 5414 -> 2104, host added 9447 -> 4105. Moves are still 1.6-2.4x the chunks that really have to move, because of which sets the LP chooses (calc_intersect_weights costs positions against sorted combinations, align_pgs looks at 3 positions); that is a separate change. Note: folded host ids start above the highest in-tree OSD id (fold.js), while out OSDs stay as raw ids in prev sets, so the two can coincide; the position map instead of includes() keeps that from duplicating a host.

Sets in host order after these events: 83-100 % before, 1-7 % after.

Found: seen on a cluster: every PG of a 12-host EC 8+2 pool was in host order and the last two hosts held only parity chunks; the cause was then found in the code and reproduced with the monitor code.

Tested: node mon/lp_optimizer/test-optimize-simple.js, new cases "remove host 6" (fails without the change: "Surviving OSDs keep their positions failed"), previous sets given as numbers, and 7 hosts losing two (a new host and NO_OSD per PG, rotated over the vacated positions). Note: the existing case "Change size to 2, ordered" of that file already fails on master (11 moved, expected < 8), and run().catch(console.error) hides it; the new case is placed before it so it runs. node mon/lp_optimizer/test-optimize-fold.js: a host=112233 pool losing two hosts (repeated folded hosts; fails without the rule check). Other mon/lp_optimizer/test-*.js unchanged.

Contributor Name

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

CLA

### Description In EC pools the position of an OSD in a PG is the number of the chunk it holds. `optimize_change()` takes changed sets from sorted combinations (the combinator sorts them, only `optimize_initial()` rotates them in `make_int_pgs`), so every changed PG came back sorted: OSDs that stayed in the PG changed positions and their chunks moved too, and after a few re-layouts the last hosts held only parity chunks (so they never become primary). This keeps the positions of the OSDs that stay and puts new ones into the vacated positions, rotated by PG number as `optimize_initial()` does. Replicated pools (`ordered` false) and pg_size changes are not touched. The previous set's members are mapped to their positions once per PG and placed once, and only the new items are tried over rotations; a member may hold several positions, since folded failure domains can repeat in a set (previous sets of a host-out re-layout do contain repeated hosts). The new order is used only if it passes the pool's placement rules, so positional rules like `host=112233` keep their order. This is the round robin after the LP discussed in Telegram. Model with the monitor code, 12 hosts x 48 OSDs, EC 8+2, 2048 PGs (chunk moves, before -> after): | event | before | after | |---|---|---| | host out | 11592 | 3306 | | same host back | 14535 | 3424 | | host added | 14372 | 3104 | | one host reweighted to half | 8662 | 1508 | On the real (fully host-ordered) PG map of such a cluster: one host out 5830 -> 2875 chunk moves, back 7192 -> 3096, reweight to 0.5 5414 -> 2104, host added 9447 -> 4105. Moves are still 1.6-2.4x the chunks that really have to move, because of which sets the LP chooses (`calc_intersect_weights` costs positions against sorted combinations, `align_pgs` looks at 3 positions); that is a separate change. Note: folded host ids start above the highest in-tree OSD id (`fold.js`), while out OSDs stay as raw ids in prev sets, so the two can coincide; the position map instead of `includes()` keeps that from duplicating a host. Sets in host order after these events: 83-100 % before, 1-7 % after. Found: seen on a cluster: every PG of a 12-host EC 8+2 pool was in host order and the last two hosts held only parity chunks; the cause was then found in the code and reproduced with the monitor code. Tested: `node mon/lp_optimizer/test-optimize-simple.js`, new cases "remove host 6" (fails without the change: "Surviving OSDs keep their positions failed"), previous sets given as numbers, and 7 hosts losing two (a new host and NO_OSD per PG, rotated over the vacated positions). Note: the existing case "Change size to 2, ordered" of that file already fails on master (11 moved, expected < 8), and `run().catch(console.error)` hides it; the new case is placed before it so it runs. `node mon/lp_optimizer/test-optimize-fold.js`: a `host=112233` pool losing two hosts (repeated folded hosts; fails without the rule check). Other `mon/lp_optimizer/test-*.js` unchanged. ### 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-12-01 17:54:53 +03:00
In EC pools the position of an OSD in a PG is the number of the chunk
it holds. optimize_change() takes changed sets from sorted combinations,
so every changed PG came back sorted: OSDs that stayed in the PG changed
positions and their chunks moved too, and after a few re-layouts the
last hosts held only parity chunks. Keep the positions of the OSDs that
stay and put new ones into the vacated positions, rotated by PG number
as optimize_initial() does.
koolkhel added 1 commit 2026-12-01 18:03:55 +03:00
Folded failure domains may repeat in a set, so match the previous set by
counts, not by presence: otherwise a repeated item could be kept twice
and another one dropped. Keep the new order only if it still passes the
pool's placement rules, else use the optimizer's order, so positional
rules like host=112233 are not broken by the rotation.
koolkhel added 1 commit 2026-12-01 18:15:14 +03:00
Remove two hosts in the ordered keep-positions test, so that some PGs
get two new OSDs and the rotation of new items runs, and check that
every new set is complete.
koolkhel added 1 commit 2026-12-01 20:48:07 +03:00
Sets with NO_OSD never pass check_combinations, so surviving OSDs of
undersized PGs did not keep their positions at all; accept the kept
order when the optimizer's own set fails the check too. A rotation of
the new items may break a positional rule: try the other rotations
before falling back to the optimizer's order.
koolkhel added 1 commit 2026-12-02 14:31:33 +03:00
Previous sets read from etcd may hold OSD numbers as JSON numbers, for
example after vitastor-cli rm-osd rewrote them, while the optimizer
returns strings. keep_positions() returned the previous set's items, so
new sets mixed both types and strict comparisons with the stored primary
(includes() in pick_primary) failed for surviving OSDs. Return the new
set's own items instead.
koolkhel force-pushed mon-keep-ec-positions from ba582e83df to d6a153abad 2026-12-02 19:11:04 +03:00 Compare
koolkhel added 1 commit 2026-12-02 19:37:34 +03:00
Make the ordered pass of optimize_change() a function next to
align_pgs(), collect the previous positions with a plain for loop, and
move the new test cases into their own functions.
vitalif merged commit 027ef85d5d into master 2026-12-02 19:51:58 +03:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vitalif/vitastor#214
No description provided.