mon: add idempotent shortcut to optimize_change #225

Open
pan.guihua wants to merge 1 commits from pan.guihua/vitastor:mon-lp-optimizer-idempotency into master
First-time contributor

Description

In optimize_change, add prepare_optimize_change to short-circuit with 0 movement when all old PG combinations remain valid (check_combinations), all existing OSDs have positive weight, and every live OSD's load is within max(1.5, target * 1.5%) tolerance (e.g., when a downed OSD comes back up before migration finishes and prev_pgs is last_clean_pgs). When the shortcut is bypassed, still_valid is reused for LP candidate merging.

Also add mon/lp_optimizer/test-optimize-idempotency.js covering EC 4+2 and Rep3 idempotent shortcut and shortcut bypass (zero-weight / weight-change) cases.

Contributor Name

Guihua Pan

CLA

### Description In optimize_change, add prepare_optimize_change to short-circuit with 0 movement when all old PG combinations remain valid (check_combinations), all existing OSDs have positive weight, and every live OSD's load is within max(1.5, target * 1.5%) tolerance (e.g., when a downed OSD comes back up before migration finishes and prev_pgs is last_clean_pgs). When the shortcut is bypassed, still_valid is reused for LP candidate merging. Also add mon/lp_optimizer/test-optimize-idempotency.js covering EC 4+2 and Rep3 idempotent shortcut and shortcut bypass (zero-weight / weight-change) cases. ### Contributor Name Guihua Pan ### CLA - [x] I accept Vitastor CLA agreement: https://git.yourcmc.ru/vitalif/vitastor/src/branch/master/CLA-en.md
pan.guihua added 2 commits 2026-12-03 11:14:53 +03:00
In `fold_prev_pgs`, when trailing OSDs go down, newly assigned folded host IDs (max online OSD + 1) can collide with the downed OSD IDs. Fallback unmapped OSDs to `0` instead of keeping `osd` so they are not mistaken for folded host IDs, and add a unit test in `test-optimize-fold.js`.
In `optimize_change`, add `prepare_optimize_change` and `trim_prev_pgs` to:
1. Trim old PGs when `pg_size` shrinks (keep the first `pg_size` positions for ordered/EC pools, and prefer live and lower-load OSDs for unordered/replicated pools).
2. Deduplicate and validate old PG combinations once via `check_combinations`, reusing `still_valid` for both the shortcut check and candidate merging.
3. Short-circuit with 0 movement when all old combinations remain valid, all existing OSDs have positive weight, and every live OSD's load is within `max(1.5, target * 1.5%)` tolerance (e.g., when a downed OSD comes back up before migration finishes and `prev_pgs` is `last_clean_pgs`).

Also add `mon/lp_optimizer/test-optimize-change.js` covering EC 4+2 and 3-replica idempotent shortcut, `pg_size` shrink, and shortcut bypass (zero-weight / weight-change) cases.
pan.guihua changed title from mon-lp-optimizer-idempotency to mon: add idempotent shortcut and pg_size shrink trimming to optimize_change 2026-12-03 11:17:40 +03:00
pan.guihua force-pushed mon-lp-optimizer-idempotency from 60334087d9 to ad4b2fba51 2026-12-04 11:34:23 +03:00 Compare
pan.guihua force-pushed mon-lp-optimizer-idempotency from ad4b2fba51 to 6eea942f12 2026-12-04 12:57:41 +03:00 Compare
pan.guihua changed title from mon: add idempotent shortcut and pg_size shrink trimming to optimize_change to mon: add idempotent shortcut to optimize_change 2026-12-04 12:59:00 +03:00
pan.guihua requested review from vitalif 2026-12-04 13:00:58 +03:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u mon-lp-optimizer-idempotency:pan.guihua-mon-lp-optimizer-idempotency
git checkout pan.guihua-mon-lp-optimizer-idempotency
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vitalif/vitastor#225
No description provided.