mon: Keep positions of surviving OSDs in EC PGs on re-layout #214
@@ -368,6 +368,10 @@ async function optimize_change({ prev_pgs: prev_int_pgs, osd_weights, combinator
|
||||
const int_pgs = make_int_pgs(weights, pg_count);
|
||||
// Align them with most similar previous PGs
|
||||
const new_pgs = align_pgs(prev_int_pgs, int_pgs);
|
||||
if (ordered)
|
||||
{
|
||||
align_positions(prev_int_pgs, new_pgs, combinator);
|
||||
}
|
||||
let differs = 0, osd_differs = 0;
|
||||
for (let i = 0; i < pg_count; i++)
|
||||
{
|
||||
@@ -447,6 +451,54 @@ function print_change_stats(retval, detailed)
|
||||
);
|
||||
}
|
||||
|
||||
// EC chunk number = position: items of the previous set keep their positions, new items fill
|
||||
// the vacated ones, rotated by PG number. Items may repeat (folded failure domains)
|
||||
function align_positions(prev_int_pgs, new_pgs, combinator)
|
||||
{
|
||||
for (let i = 0; i < new_pgs.length; i++)
|
||||
{
|
||||
const prev = prev_int_pgs[i], pg = new_pgs[i];
|
||||
if (prev.length != pg.length)
|
||||
continue;
|
||||
const old_pos = {};
|
||||
for (let j = 0; j < prev.length; j++)
|
||||
{
|
||||
if (prev[j] != NO_OSD)
|
||||
{
|
||||
old_pos[prev[j]] = old_pos[prev[j]] || [];
|
||||
old_pos[prev[j]].push(j);
|
||||
}
|
||||
}
|
||||
// Place pg's own items: prev read from etcd may hold OSD numbers where pg holds strings
|
||||
const kept = pg.map(() => null), fresh = [];
|
||||
for (const osd of pg)
|
||||
{
|
||||
if (old_pos[osd] && old_pos[osd].length)
|
||||
kept[old_pos[osd].shift()] = osd;
|
||||
else
|
||||
fresh.push(osd);
|
||||
}
|
||||
const n = fresh.length || 1;
|
||||
const rotated = (r) =>
|
||||
{
|
||||
const f = [ ...fresh.slice(r), ...fresh.slice(0, r) ];
|
||||
return kept.map(osd => (osd === null ? f.shift() : osd));
|
||||
};
|
||||
// A positional placement rule may forbid an order: try every rotation of the new items
|
||||
let found = null;
|
||||
for (let r = 0; r < n && !found; r++)
|
||||
{
|
||||
const cand = rotated((i+r) % n);
|
||||
if (combinator.check_combinations([ cand ]).length)
|
||||
found = cand;
|
||||
}
|
||||
// Sets with NO_OSD never pass the check: then any order is as good as the optimizer's.
|
||||
// Otherwise keep the optimizer's order if no rotation fits
|
||||
if (found || !combinator.check_combinations([ pg ]).length)
|
||||
new_pgs[i] = found || rotated(i % n);
|
||||
}
|
||||
}
|
||||
|
||||
function align_pgs(prev_int_pgs, int_pgs)
|
||||
{
|
||||
const aligned_pgs = [];
|
||||
|
||||
@@ -103,6 +103,56 @@ async function run()
|
||||
unfolded_res.space = unfolded_res.pg_effsize * LPOptimizer.pg_list_space_efficiency(unfolded_res.int_pgs, osd_weights, 0, 1);
|
||||
LPOptimizer.print_change_stats(unfolded_res, false);
|
||||
assert.equal(res.space, 100, 'Initial distribution');
|
||||
|
||||
await test_ordered_repeated_hosts();
|
||||
await test_ordered_dc_rule();
|
||||
}
|
||||
|
||||
function kept_positions(prev, pgs)
|
||||
{
|
||||
return pgs.every((pg, i) => prev[i].every((osd, j) => !pg.includes(osd) || pg[j] == osd));
|
||||
}
|
||||
|
||||
async function test_ordered_repeated_hosts()
|
||||
{
|
||||
console.log('\n32 PGs, 2 OSDs per host (host=112233), ordered: remove hosts 5 and 6');
|
||||
const nodes = [];
|
||||
for (let i = 1; i <= 12; i++)
|
||||
nodes.push({ id: i, level: 'osd', size: 1, parent: 'host'+(1+(0|((i-1)/2))) });
|
||||
for (let i = 1; i <= 6; i++)
|
||||
nodes.push({ id: 'host'+i, level: 'host' });
|
||||
const rules = DSL.parse_level_indexes({ host: '112233' }, [ 'host', 'osd' ]);
|
||||
const folded = fold_failure_domains(nodes, rules).nodes;
|
||||
const weights = folded.reduce((a, c) => { if (Number(c.id)) { a[c.id] = c.size; } return a; }, {});
|
||||
let res = await LPOptimizer.optimize_initial({ osd_weights: weights,
|
||||
combinator: new DSL.RuleCombinator(folded, rules, 10000, false), pg_size: 6, pg_count: 32, ordered: false });
|
||||
const prev = res.int_pgs;
|
||||
const left = folded.filter(n => n.name != 'host5' && n.name != 'host6');
|
||||
const combinator = new DSL.RuleCombinator(left, rules, 10000, false);
|
||||
res = await LPOptimizer.optimize_change({ prev_pgs: prev, combinator: combinator, pg_size: 6, ordered: true,
|
||||
osd_weights: left.reduce((a, c) => { if (Number(c.id)) { a[c.id] = c.size; } return a; }, {}) });
|
||||
LPOptimizer.print_change_stats(res, false);
|
||||
assert.equal(combinator.check_combinations(res.int_pgs).length, 32, 'New sets follow the placement rule');
|
||||
assert(kept_positions(prev, res.int_pgs), 'Surviving hosts keep their positions');
|
||||
}
|
||||
|
||||
async function test_ordered_dc_rule()
|
||||
{
|
||||
console.log('\n32 PGs, 2 DCs x 3 hosts, dc=1122: remove one host in each DC');
|
||||
const nodes = [ { id: 'dc1', level: 'dc' }, { id: 'dc2', level: 'dc' } ];
|
||||
for (let h = 1; h <= 6; h++)
|
||||
nodes.push({ id: 'host'+h, level: 'host', parent: h <= 3 ? 'dc1' : 'dc2' }, { id: h, level: 'osd', size: 1, parent: 'host'+h });
|
||||
const rules = DSL.parse_level_indexes({ dc: '1122', host: '1234' }, [ 'dc', 'host', 'osd' ]);
|
||||
let res = await LPOptimizer.optimize_initial({ osd_weights: { 1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1 },
|
||||
combinator: new DSL.RuleCombinator(nodes, rules, 10000, false), pg_size: 4, pg_count: 32, ordered: false });
|
||||
const prev = res.int_pgs;
|
||||
const left = nodes.filter(n => ![ 1, 6, 'host1', 'host6' ].includes(n.id));
|
||||
const combinator = new DSL.RuleCombinator(left, rules, 10000, false);
|
||||
res = await LPOptimizer.optimize_change({ prev_pgs: prev, combinator: combinator, pg_size: 4, ordered: true,
|
||||
osd_weights: { 2: 1, 3: 1, 4: 1, 5: 1 } });
|
||||
LPOptimizer.print_change_stats(res, false);
|
||||
assert.equal(combinator.check_combinations(res.int_pgs).length, 32, 'New sets follow the DC rule');
|
||||
assert(kept_positions(prev, res.int_pgs), 'Surviving OSDs keep their positions under a positional rule');
|
||||
}
|
||||
|
||||
run().catch(console.error);
|
||||
|
||||
@@ -29,6 +29,10 @@ async function run()
|
||||
LPOptimizer.print_change_stats(res, false);
|
||||
assert(res.space == 2, 'Redistribution after OSD removal');
|
||||
|
||||
await test_ordered_remove_hosts();
|
||||
await test_ordered_undersized();
|
||||
await test_ordered_two_new_items();
|
||||
|
||||
console.log('\n16 PGs, size=3, ordered');
|
||||
res = await LPOptimizer.optimize_initial(compat({ osd_tree, pg_size: 3, pg_count: 16, ordered: true }));
|
||||
LPOptimizer.print_change_stats(res, false);
|
||||
@@ -39,6 +43,58 @@ async function run()
|
||||
assert(res.space >= 3*14/16 && res.osd_differs < 8, 'Redistribution');
|
||||
}
|
||||
|
||||
function host_tree(hosts)
|
||||
{
|
||||
const tree = {};
|
||||
for (let h = 1; h <= hosts; h++)
|
||||
tree[h*100] = { [h]: 1 };
|
||||
return tree;
|
||||
}
|
||||
|
||||
function kept_positions(prev, pgs)
|
||||
{
|
||||
return pgs.every((pg, i) => prev[i].every((osd, j) => !pg.includes(osd) || pg[j] == osd));
|
||||
}
|
||||
|
||||
async function test_ordered_remove_hosts()
|
||||
{
|
||||
console.log('\n32 PGs, 6 hosts, size=4, ordered: remove hosts 5 and 6');
|
||||
let res = await LPOptimizer.optimize_initial(compat({ osd_tree: host_tree(6), pg_size: 4, pg_count: 32, ordered: true }));
|
||||
const prev = res.int_pgs;
|
||||
// OSD numbers as in etcd after an osd_set rewrite: the result keeps the optimizer's own items
|
||||
res = await LPOptimizer.optimize_change(compat({ prev_pgs: prev.map(pg => pg.map(Number)), osd_tree: host_tree(4), pg_size: 4, ordered: true }));
|
||||
LPOptimizer.print_change_stats(res, false);
|
||||
assert(kept_positions(prev, res.int_pgs), 'Surviving OSDs keep their positions');
|
||||
assert(res.int_pgs.every(pg => pg.every(osd => typeof osd == 'string')), 'Items are the optimizer\'s strings');
|
||||
assert(res.int_pgs.every(pg => pg.slice().sort().join() == '1,2,3,4'), 'Every PG has all 4 hosts left');
|
||||
}
|
||||
|
||||
async function test_ordered_undersized()
|
||||
{
|
||||
console.log('\n32 PGs, 6 hosts, size=6, ordered: remove host 6 (undersized)');
|
||||
let res = await LPOptimizer.optimize_initial(compat({ osd_tree: host_tree(6), pg_size: 6, pg_count: 32, ordered: true }));
|
||||
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), 'Undersized PGs: surviving OSDs keep their positions');
|
||||
}
|
||||
|
||||
async function test_ordered_two_new_items()
|
||||
{
|
||||
console.log('\n32 PGs, 7 hosts, size=6, ordered: remove hosts 6 and 7 (a new host and NO_OSD per PG)');
|
||||
let res = await LPOptimizer.optimize_initial(compat({ osd_tree: host_tree(7), pg_size: 6, pg_count: 32, ordered: true }));
|
||||
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();
|
||||
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(z_first.size == 2, 'Two new items per PG: rotated over the vacated positions');
|
||||
}
|
||||
|
||||
function assert(cond, txt)
|
||||
{
|
||||
if (!cond)
|
||||
|
||||
Reference in New Issue
Block a user