From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 311DE1FF140 for ; Fri, 27 Mar 2026 15:15:51 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 76777C903; Fri, 27 Mar 2026 15:16:14 +0100 (CET) Content-Type: text/plain; charset=UTF-8 Date: Fri, 27 Mar 2026 15:16:11 +0100 Message-Id: Subject: Re: [PATCH perl-rs v2 16/40] pve-rs: resource-scheduling: expose auto rebalancing methods From: "Dominik Rusovac" To: "Daniel Kral" , Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: aerc 0.20.0 References: <20260324183029.1274972-1-d.kral@proxmox.com> <20260324183029.1274972-17-d.kral@proxmox.com> In-Reply-To: <20260324183029.1274972-17-d.kral@proxmox.com> X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1774620921370 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.136 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment POISEN_SPAM_PILL 0.1 Meta: its spam POISEN_SPAM_PILL_1 0.1 random spam to be learned in bayes POISEN_SPAM_PILL_3 0.1 random spam to be learned in bayes SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: UURABDLL26WAEYQ3DZMAVRCPNSY3RCDN X-Message-ID-Hash: UURABDLL26WAEYQ3DZMAVRCPNSY3RCDN X-MailFrom: d.rusovac@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: lgtm On Tue Mar 24, 2026 at 7:30 PM CET, Daniel Kral wrote: > These methods expose the auto rebalancing methods of both the static and > dynamic scheduler. > > As Scheduler::score_best_balancing_migration_candidates{,_topsis}() > takes a possible very large list of migration candidates, the binding > takes a more compact representation, which reduces the size that needs > to be generated on the caller's side and therefore the runtime of the > serialization from Perl to Rust. > > Additionally, while decomposing the compact representation the input > data is validated since the underlying scoring methods do not further > validate whether their input is consistent with the cluster usage. > > The method names score_best_balancing_migration_candidates{,_topsis}() > are chosen deliberately, so that future extensions can implement > score_best_balancing_migrations{,_topsis}(), which might allow to score > migrations without providing the candidates. > > Signed-off-by: Daniel Kral > --- > changes v1 -> v2: > - improve patch message and documentation > - move to the end of the perl-rs changes, which makes it more consistent > with the change order in pve-ha-manager as well > - uses `UsageAggregator` now to discern how usages are accumulated > - s/generate_migration_candidates_from > /decompose_compact_migration_candidates > - make the decomposition of compact migration candidates more robust and > do not use any unwraps or other causes of panic but the Mutex guard > unwrap > [snip] > +/// Transforms a `Vec` to a `Vec` with the cluster > +/// usage from `usage`. > +/// > +/// This function fails for any of the following conditions for a [`Comp= actMigrationCandidate`]: > +/// > +/// - the `leader` is not present in the cluster usage > +/// - the `leader` is non-stationary > +/// - any resource in `resources` is not present in the cluster usage > +/// - any resource in `resources` is non-stationary > +/// - any resource in `resources` is on another node than the `leader` nice idea, to use Vec::with_capacity in here > +pub(crate) fn decompose_compact_migration_candidates( > + usage: &Usage, > + compact_candidates: Vec, > +) -> Result, Error> { > + // The length of `compact_candidates` is at least a lower bound > + let mut candidates =3D Vec::with_capacity(compact_candidates.len()); [snip] Reviewed-by: Dominik Rusovac