2021-02-25 23:21:14 +03:00
|
|
|
// Copyright (c) Vitaliy Filippov, 2019+
|
|
|
|
// License: VNPL-1.1 (see README.md for details)
|
|
|
|
|
|
|
|
const LPOptimizer = require('./lp-optimizer.js');
|
|
|
|
|
|
|
|
async function run()
|
|
|
|
{
|
2022-01-03 20:37:07 +03:00
|
|
|
const osd_tree = {
|
|
|
|
100: { 1: 1 },
|
|
|
|
200: { 2: 1 },
|
|
|
|
300: { 3: 1 },
|
|
|
|
};
|
|
|
|
|
2021-02-25 23:21:14 +03:00
|
|
|
let res;
|
|
|
|
|
|
|
|
console.log('16 PGs, size=3');
|
2022-01-03 20:37:07 +03:00
|
|
|
res = await LPOptimizer.optimize_initial({ osd_tree, pg_size: 3, pg_count: 16, ordered: false });
|
2021-02-25 23:21:14 +03:00
|
|
|
LPOptimizer.print_change_stats(res, false);
|
2022-01-03 20:37:07 +03:00
|
|
|
assert(res.space == 3, 'Initial distribution');
|
|
|
|
console.log('\nChange size to 2');
|
|
|
|
res = await LPOptimizer.optimize_change({ prev_pgs: res.int_pgs, osd_tree, pg_size: 2, ordered: false });
|
2021-02-25 23:21:14 +03:00
|
|
|
LPOptimizer.print_change_stats(res, false);
|
2022-01-03 20:37:07 +03:00
|
|
|
assert(res.space >= 3*14/16 && res.osd_differs == 0, 'Redistribution');
|
2021-02-25 23:21:14 +03:00
|
|
|
console.log('\nRemove OSD 3');
|
2022-01-03 20:37:07 +03:00
|
|
|
const no3_tree = { ...osd_tree };
|
|
|
|
delete no3_tree['300'];
|
|
|
|
res = await LPOptimizer.optimize_change({ prev_pgs: res.int_pgs, osd_tree: no3_tree, pg_size: 2, ordered: false });
|
|
|
|
LPOptimizer.print_change_stats(res, false);
|
|
|
|
assert(res.space == 2, 'Redistribution after OSD removal');
|
|
|
|
|
|
|
|
console.log('\n16 PGs, size=3, ordered');
|
|
|
|
res = await LPOptimizer.optimize_initial({ osd_tree, pg_size: 3, pg_count: 16, ordered: true });
|
2021-02-25 23:21:14 +03:00
|
|
|
LPOptimizer.print_change_stats(res, false);
|
2022-01-03 20:37:07 +03:00
|
|
|
assert(res.space == 3, 'Initial distribution');
|
|
|
|
console.log('\nChange size to 2, ordered');
|
|
|
|
res = await LPOptimizer.optimize_change({ prev_pgs: res.int_pgs, osd_tree, pg_size: 2, ordered: true });
|
|
|
|
LPOptimizer.print_change_stats(res, false);
|
|
|
|
assert(res.space >= 3*14/16 && res.osd_differs < 8, 'Redistribution');
|
|
|
|
}
|
|
|
|
|
|
|
|
function assert(cond, txt)
|
|
|
|
{
|
|
|
|
if (!cond)
|
|
|
|
{
|
|
|
|
throw new Error((txt||'test')+' failed');
|
|
|
|
}
|
2021-02-25 23:21:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
run().catch(console.error);
|