2020-09-17 23:02:40 +03:00
|
|
|
// Copyright (c) Vitaliy Filippov, 2019+
|
2021-02-06 01:26:07 +03:00
|
|
|
// License: VNPL-1.1 (see README.md for details)
|
2020-09-17 23:02:40 +03:00
|
|
|
|
2020-09-01 02:22:50 +03:00
|
|
|
module.exports = {
|
|
|
|
scale_pg_count,
|
|
|
|
};
|
|
|
|
|
2021-03-08 23:13:08 +03:00
|
|
|
function add_pg_history(new_pg_history, new_pg, prev_pgs, prev_pg_history, old_pg)
|
|
|
|
{
|
|
|
|
if (!new_pg_history[new_pg])
|
|
|
|
{
|
|
|
|
new_pg_history[new_pg] = {
|
|
|
|
osd_sets: {},
|
|
|
|
all_peers: {},
|
|
|
|
epoch: 0,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
const nh = new_pg_history[new_pg], oh = prev_pg_history[old_pg];
|
|
|
|
nh.osd_sets[prev_pgs[old_pg].join(' ')] = prev_pgs[old_pg];
|
|
|
|
if (oh && oh.osd_sets && oh.osd_sets.length)
|
|
|
|
{
|
|
|
|
for (const pg of oh.osd_sets)
|
|
|
|
{
|
|
|
|
nh.osd_sets[pg.join(' ')] = pg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (oh && oh.all_peers && oh.all_peers.length)
|
|
|
|
{
|
|
|
|
for (const osd_num of oh.all_peers)
|
|
|
|
{
|
|
|
|
nh.all_peers[osd_num] = Number(osd_num);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (oh && oh.epoch)
|
|
|
|
{
|
|
|
|
nh.epoch = nh.epoch < oh.epoch ? oh.epoch : nh.epoch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function finish_pg_history(merged_history)
|
|
|
|
{
|
|
|
|
merged_history.osd_sets = Object.values(merged_history.osd_sets);
|
|
|
|
merged_history.all_peers = Object.values(merged_history.all_peers);
|
|
|
|
}
|
|
|
|
|
2020-09-01 02:22:50 +03:00
|
|
|
function scale_pg_count(prev_pgs, prev_pg_history, new_pg_history, new_pg_count)
|
|
|
|
{
|
|
|
|
const old_pg_count = prev_pgs.length;
|
2021-02-25 20:36:37 +03:00
|
|
|
// Add all possibly intersecting PGs to the history of new PGs
|
2020-09-01 02:22:50 +03:00
|
|
|
if (!(new_pg_count % old_pg_count))
|
|
|
|
{
|
2021-03-08 23:13:08 +03:00
|
|
|
// New PG count is a multiple of old PG count
|
2020-09-01 02:22:50 +03:00
|
|
|
for (let i = 0; i < new_pg_count; i++)
|
|
|
|
{
|
2021-03-08 23:13:08 +03:00
|
|
|
add_pg_history(new_pg_history, i, prev_pgs, prev_pg_history, i % old_pg_count);
|
|
|
|
finish_pg_history(new_pg_history[i]);
|
2020-09-01 02:22:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!(old_pg_count % new_pg_count))
|
|
|
|
{
|
|
|
|
// Old PG count is a multiple of the new PG count
|
|
|
|
const mul = (old_pg_count / new_pg_count);
|
|
|
|
for (let i = 0; i < new_pg_count; i++)
|
|
|
|
{
|
|
|
|
for (let j = 0; j < mul; j++)
|
|
|
|
{
|
2021-03-08 23:13:08 +03:00
|
|
|
add_pg_history(new_pg_history, i, prev_pgs, prev_pg_history, i+j*new_pg_count);
|
2020-09-01 02:22:50 +03:00
|
|
|
}
|
2021-03-08 23:13:08 +03:00
|
|
|
finish_pg_history(new_pg_history[i]);
|
2020-09-01 02:22:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Any PG may intersect with any PG after non-multiple PG count change
|
|
|
|
// So, merge ALL PGs history
|
2021-03-08 23:13:08 +03:00
|
|
|
let merged_history = {};
|
|
|
|
for (let i = 0; i < old_pg_count; i++)
|
2020-09-01 02:22:50 +03:00
|
|
|
{
|
2021-03-08 23:13:08 +03:00
|
|
|
add_pg_history(merged_history, 1, prev_pgs, prev_pg_history, i);
|
2020-09-01 02:22:50 +03:00
|
|
|
}
|
2021-03-08 23:13:08 +03:00
|
|
|
finish_pg_history(merged_history[1]);
|
2020-09-01 02:22:50 +03:00
|
|
|
for (let i = 0; i < new_pg_count; i++)
|
|
|
|
{
|
2021-03-08 23:13:08 +03:00
|
|
|
new_pg_history[i] = { ...merged_history[1] };
|
2020-09-01 02:22:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Mark history keys for removed PGs as removed
|
|
|
|
for (let i = new_pg_count; i < old_pg_count; i++)
|
|
|
|
{
|
|
|
|
new_pg_history[i] = null;
|
|
|
|
}
|
2021-03-08 23:13:08 +03:00
|
|
|
// Just for the lp_solve optimizer - pick a "previous" PG for each "new" one
|
2020-09-01 02:22:50 +03:00
|
|
|
if (old_pg_count < new_pg_count)
|
|
|
|
{
|
2021-03-08 23:13:08 +03:00
|
|
|
for (let i = old_pg_count; i < new_pg_count; i++)
|
2020-09-01 02:22:50 +03:00
|
|
|
{
|
2021-03-08 23:13:08 +03:00
|
|
|
prev_pgs[i] = prev_pgs[i % old_pg_count];
|
2020-09-01 02:22:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (old_pg_count > new_pg_count)
|
|
|
|
{
|
|
|
|
prev_pgs.splice(new_pg_count, old_pg_count-new_pg_count);
|
|
|
|
}
|
|
|
|
}
|