From e5a7d9744e163d07e2e4b52ab7fc7670355ace57 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Wed, 2 Dec 2026 19:58:25 +0300 Subject: [PATCH] mon: Put NO_OSD last among vacated EC positions An undersized PG that loses two or more positions in one change got NO_OSD rotated together with the new OSDs, so the empty slot could take a data position (reads of that chunk then reconstruct) while a new OSD took a parity one. Keep rotating the new OSDs and put NO_OSD after them, as the sorted sets did before. --- mon/lp_optimizer/lp_optimizer.js | 7 +++++-- mon/lp_optimizer/test-optimize-simple.js | 9 ++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/mon/lp_optimizer/lp_optimizer.js b/mon/lp_optimizer/lp_optimizer.js index c5bc8d79..73636df6 100644 --- a/mon/lp_optimizer/lp_optimizer.js +++ b/mon/lp_optimizer/lp_optimizer.js @@ -470,18 +470,21 @@ function align_positions(prev_int_pgs, new_pgs, combinator) } } // Place pg's own items: prev read from etcd may hold OSD numbers where pg holds strings - const kept = pg.map(() => null), fresh = []; + const kept = pg.map(() => null), fresh = [], holes = []; for (const osd of pg) { if (old_pos[osd] && old_pos[osd].length) kept[old_pos[osd].shift()] = osd; + else if (osd == NO_OSD) + holes.push(osd); else fresh.push(osd); } const n = fresh.length || 1; const rotated = (r) => { - const f = [ ...fresh.slice(r), ...fresh.slice(0, r) ]; + // NO_OSD last: EC parity chunks come last, so an empty slot does not take a data position + const f = [ ...fresh.slice(r), ...fresh.slice(0, r), ...holes ]; return kept.map(osd => (osd === null ? f.shift() : osd)); }; // A positional placement rule may forbid an order: try every rotation of the new items diff --git a/mon/lp_optimizer/test-optimize-simple.js b/mon/lp_optimizer/test-optimize-simple.js index 2d5dd9c6..b782d862 100644 --- a/mon/lp_optimizer/test-optimize-simple.js +++ b/mon/lp_optimizer/test-optimize-simple.js @@ -85,14 +85,17 @@ async function test_ordered_two_new_items() const prev = res.int_pgs; res = await LPOptimizer.optimize_change(compat({ prev_pgs: prev, osd_tree: host_tree(5), pg_size: 6, ordered: true })); assert(kept_positions(prev, res.int_pgs), 'Two new items per PG: surviving OSDs keep their positions'); - const z_first = new Set(); + let checked = 0; for (let i = 0; i < res.int_pgs.length; i++) { const vacated = [ prev[i].indexOf('6'), prev[i].indexOf('7') ].sort((a, b) => a-b); if (vacated[0] >= 0) - z_first.add(res.int_pgs[i][vacated[0]] == 'Z'); + { + assert(res.int_pgs[i][vacated[1]] == 'Z', 'Two new items per PG: NO_OSD in the last vacated position'); + checked++; + } } - assert(z_first.size == 2, 'Two new items per PG: rotated over the vacated positions'); + assert(checked > 0, 'Some PGs lose two hosts'); } function assert(cond, txt) -- 2.47.3