mon: Put NO_OSD last among vacated EC positions #223

Open
koolkhel wants to merge 1 commits from koolkhel/vitastor:mon-ec-hole-last into master
2 changed files with 11 additions and 5 deletions

View File

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

View File

@@ -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)