mon: Add sticky_primaries to keep live primaries and balance new ones #198

Merged
vitalif merged 4 commits from koolkhel/vitastor:mon-primary-spread into master 2026-11-29 14:14:51 +03:00

4 Commits

Author SHA1 Message Date
7b4c0825b4 mon: Restart the primary rebalance wait on takeover and after a pass
A standby monitor sees no changes, so on takeover it could run a pass at
once, and a pass could follow another before the moved PGs reported
their state. Restart the wait when the monitor becomes master and when a
pass runs. Re-arm the timer when the pass lands on a re-optimize round
instead of dropping it, and treat a negative value as 0.
2026-11-28 03:13:17 +03:00
39b20040ac mon: Check calm again when the primary rebalance runs
A monitor that took over a clean cluster never armed the rebalance
timer, an OSD could go down between the timer and the pass, and setting
primary_rebalance_time to 0 did not cancel an armed pass. Check calm in
one place, when the timer fires and again when the pass runs, and run
save_last_clean() on start.
2026-11-28 01:32:02 +03:00
5680fc61fe mon: Even out sticky primaries once the cluster is calm
With sticky_primaries a returned OSD got primaries again only when other
PGs needed a new one. Once all PGs stay clean and no OSD goes up or down
for primary_rebalance_time (300 s by default, 0 disables), move a live
primary to the least loaded candidate of its PG when it has at least 2
primaries more. One pass gives each OSD at most one new primary, so no
OSD re-peers a batch of PGs at once; the next pass waits until the
cluster is calm again.
2026-11-28 01:13:40 +03:00
06a5f98734 mon: Add sticky_primaries to keep live primaries and balance new ones
The monitor picks the primary OSD of a PG by PG number among the alive
candidates and re-picks it on every OSD up/down. So when an OSD fails,
live primaries of PGs that lost a member move too, and they all move
back when it returns; every move restarts the PG on both OSDs. The
rotation is also uneven: some OSDs become primary for several times
more PGs than the average and peer them one after another.

With sticky_primaries, a live primary stays while it is one of the PG's
candidates, and a PG that needs a new primary gets the candidate which
is primary for the fewest PGs of all pools, ties by PG number. The
counts are shared by all pools of one change. Off by default.
2026-11-28 00:45:58 +03:00