Keep PG count when optimize_change drops PGs instead of moving them #178
@@ -326,12 +326,18 @@ async function optimize_change({ prev_pgs: prev_int_pgs, osd_weights, combinator
|
||||
lp += `${pg_name} >= 0;\n`;
|
||||
}
|
||||
}
|
||||
lp += 'sec '+pg_vars.join(', ')+';\n';
|
||||
// Solve it
|
||||
const lp_result = await lp_solve(lp);
|
||||
const sec = 'sec '+pg_vars.join(', ')+';\n';
|
||||
// make_int_pgs() scales dropped PGs back onto the same OSDs, so keep the PG count if possible
|
||||
const kept_count = all_pg_names.reduce((a, pg_name) => a + (prev_weights[pg_name]||0), 0);
|
||||
const keep_count = all_pg_names.map(pg_name => prev_weights[pg_name] ? `add_${pg_name} - del_${pg_name}` : pg_name)
|
||||
.join(' + ')+' = '+(pg_count-kept_count)+';\n';
|
||||
let lp_result = await lp_solve(lp+keep_count+sec);
|
||||
const over_share = !lp_result;
|
||||
if (over_share)
|
||||
lp_result = await lp_solve(lp+sec);
|
||||
if (!lp_result)
|
||||
{
|
||||
console.log(lp);
|
||||
console.log(lp+sec);
|
||||
throw new Error('Problem is infeasible or unbounded - is it a bug?');
|
||||
}
|
||||
// Generate the new distribution
|
||||
@@ -414,6 +420,7 @@ async function optimize_change({ prev_pgs: prev_int_pgs, osd_weights, combinator
|
||||
int_pgs: new_pgs,
|
||||
differs,
|
||||
osd_differs,
|
||||
over_share,
|
||||
pg_effsize,
|
||||
space: pg_effsize * pg_list_space_efficiency(new_pgs, osd_weights, pg_minsize, parity_space),
|
||||
total_space: total_weight,
|
||||
@@ -440,6 +447,8 @@ function print_change_stats(retval, detailed)
|
||||
"Data movement: "+retval.differs+" pgs, "+
|
||||
retval.osd_differs+" pg*osds = "+Math.round(retval.osd_differs / prev_int_pgs.length / 3 * 10000)/100+" %"
|
||||
);
|
||||
if (retval.over_share)
|
||||
console.log("Can't place all "+new_pgs.length+" PGs within OSD sizes, some OSDs get more than their share");
|
||||
}
|
||||
console.log(
|
||||
"Total space (raw): "+Math.round(retval.space*100)/100+" TB, space efficiency: "+
|
||||
|
||||
84
mon/lp_optimizer/test-optimize-keep-count.js
Normal file
84
mon/lp_optimizer/test-optimize-keep-count.js
Normal file
@@ -0,0 +1,84 @@
|
||||
// Copyright (c) Vitaliy Filippov, 2019+
|
||||
// License: VNPL-1.1 (see README.md for details)
|
||||
|
||||
// optimize_change() must not lose PGs and leave failure domains empty or overloaded
|
||||
// when a host leaves or returns to an EC pool
|
||||
|
||||
const assert = require('assert');
|
||||
const LPOptimizer = require('./lp_optimizer.js');
|
||||
|
||||
// Hosts folded into one item each, all their combinations
|
||||
function host_cfg(hosts, pg_size, pg_minsize)
|
||||
{
|
||||
const all_sets = {};
|
||||
const add_sets = (start, cur) =>
|
||||
{
|
||||
if (cur.length == pg_size)
|
||||
all_sets['pg_'+cur.join('_')] = cur;
|
||||
else
|
||||
for (let i = start; i < hosts.length; i++)
|
||||
add_sets(i+1, [ ...cur, hosts[i] ]);
|
||||
};
|
||||
add_sets(0, []);
|
||||
return {
|
||||
osd_weights: hosts.reduce((a, h) => { a[h] = 1; return a; }, {}),
|
||||
combinator: {
|
||||
random_combinations: () => ({ ...all_sets }),
|
||||
check_combinations: pgs => pgs.filter(pg => pg.every(h => hosts.includes(h))),
|
||||
},
|
||||
pg_size,
|
||||
pg_minsize,
|
||||
ordered: true,
|
||||
};
|
||||
}
|
||||
|
||||
function check_balance(res, hosts, pg_count, pg_size)
|
||||
{
|
||||
LPOptimizer.print_change_stats(res);
|
||||
const per_host = {};
|
||||
for (const pg of res.int_pgs)
|
||||
for (const h of pg)
|
||||
per_host[h] = (per_host[h]||0) + 1;
|
||||
console.log('PGs per host:', per_host);
|
||||
assert(res.int_pgs.length == pg_count);
|
||||
const fair = pg_count*pg_size/hosts.length;
|
||||
for (const h of hosts)
|
||||
assert(Math.abs(per_host[h] - fair) <= 0.05*fair, 'host '+h+' has '+per_host[h]+' PGs, expected '+fair);
|
||||
}
|
||||
|
||||
async function run()
|
||||
{
|
||||
// EC 4+2 on 7 hosts, host 3 returns after all 128 PGs moved to the other 6
|
||||
let hosts = [ '1', '2', '3', '4', '5', '6', '7' ];
|
||||
const prev_pgs = [];
|
||||
for (let i = 0; i < 128; i++)
|
||||
{
|
||||
const pg = [ '1', '2', '4', '5', '6', '7' ];
|
||||
prev_pgs.push([ ...pg.slice(i % 6), ...pg.slice(0, i % 6) ]);
|
||||
}
|
||||
let res = await LPOptimizer.optimize_change({ prev_pgs, ...host_cfg(hosts, 6, 4) });
|
||||
check_balance(res, hosts, 128, 6);
|
||||
// Host 3 needs ~110 PGs, one per moved PG
|
||||
assert(res.differs <= 120, res.differs+' PGs moved');
|
||||
// EC 8+2 on 12 hosts, host 9 leaves
|
||||
hosts = [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12' ];
|
||||
res = await LPOptimizer.optimize_initial({ pg_count: 256, ...host_cfg(hosts, 10, 9) });
|
||||
check_balance(res, hosts, 256, 10);
|
||||
hosts = hosts.filter(h => h != '9');
|
||||
res = await LPOptimizer.optimize_change({ prev_pgs: res.int_pgs, ...host_cfg(hosts, 10, 9) });
|
||||
check_balance(res, hosts, 256, 10);
|
||||
// ~213 PGs lose host 9, plus some rebalancing, but not all 256
|
||||
assert(res.differs <= 245, res.differs+' PGs moved');
|
||||
// EC 4+2 on 6 hosts, host 1 is 3 times bigger: the others can't take 128 PGs at their share
|
||||
hosts = [ '1', '2', '3', '4', '5', '6' ];
|
||||
res = await LPOptimizer.optimize_change({
|
||||
prev_pgs: [ ...Array(128) ].map(() => [ ...hosts ]),
|
||||
...host_cfg(hosts, 6, 4),
|
||||
osd_weights: { '1': 3, '2': 1, '3': 1, '4': 1, '5': 1, '6': 1 },
|
||||
});
|
||||
LPOptimizer.print_change_stats(res);
|
||||
assert(res.over_share && res.int_pgs.length == 128);
|
||||
console.log('OK');
|
||||
}
|
||||
|
||||
run().catch(e => { console.error(e); process.exit(1); });
|
||||
Reference in New Issue
Block a user