public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Rusovac <d.rusovac@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH proxmox 02/15] resource-scheduling: scheduler: abstract post-migration stats logic
Date: Wed, 21 Oct 2026 10:59:19 +0200	[thread overview]
Message-ID: <20261021085932.1196302-3-d.rusovac@proxmox.com> (raw)
In-Reply-To: <20261021085932.1196302-1-d.rusovac@proxmox.com>

DRY and hide repeatedly used closure inside reuasble function.

Signed-off-by: Dominik Rusovac <d.rusovac@proxmox.com>
---
 proxmox-resource-scheduling/src/scheduler.rs | 41 ++++++++------------
 1 file changed, 16 insertions(+), 25 deletions(-)

diff --git a/proxmox-resource-scheduling/src/scheduler.rs b/proxmox-resource-scheduling/src/scheduler.rs
index 9078fa72..a12cd519 100644
--- a/proxmox-resource-scheduling/src/scheduler.rs
+++ b/proxmox-resource-scheduling/src/scheduler.rs
@@ -56,6 +56,19 @@ fn calculate_node_imbalance(nodes: &[NodeUsage], to_load: impl Fn(&NodeUsage) ->
     cv / max_cv
 }
 
+/// Returns the hypothetical [`NodeStats`] of `node` with respect to the migration `candidate`.
+fn node_stats_after_migration(candidate: &MigrationCandidate, node: &NodeUsage) -> NodeStats {
+    let mut new_stats = node.stats;
+
+    if node.name == candidate.migration.source_node {
+        new_stats.remove_running_resource(&candidate.stats);
+    } else if node.name == candidate.migration.target_node {
+        new_stats.add_running_resource(&candidate.stats);
+    }
+
+    new_stats
+}
+
 criteria_struct! {
     /// A given alternative.
     struct PveTopsisAlternative {
@@ -216,15 +229,7 @@ impl Scheduler {
     /// See [`calculate_node_imbalance`] for more information.
     fn node_imbalance_with_migration_candidate(&self, candidate: &MigrationCandidate) -> f64 {
         calculate_node_imbalance(&self.nodes, |node| {
-            let mut new_stats = node.stats;
-
-            if node.name == candidate.migration.source_node {
-                new_stats.remove_running_resource(&candidate.stats);
-            } else if node.name == candidate.migration.target_node {
-                new_stats.add_running_resource(&candidate.stats);
-            }
-
-            new_stats.load()
+            node_stats_after_migration(candidate, node).load()
         })
     }
 
@@ -288,22 +293,8 @@ impl Scheduler {
         let matrix = candidates
             .iter()
             .map(|candidate| {
-                let resource_stats = &candidate.stats;
-                let source_node = &candidate.migration.source_node;
-                let target_node = &candidate.migration.target_node;
-
-                self.topsis_alternative_with(|node| {
-                    let mut new_stats = node.stats;
-
-                    if &node.name == source_node {
-                        new_stats.remove_running_resource(resource_stats);
-                    } else if &node.name == target_node {
-                        new_stats.add_running_resource(resource_stats);
-                    }
-
-                    new_stats
-                })
-                .into()
+                self.topsis_alternative_with(|node| node_stats_after_migration(candidate, node))
+                    .into()
             })
             .collect::<Vec<_>>();
 
-- 
2.47.3





  parent reply	other threads:[~2026-10-21  8:59 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-21  8:59 [RFC PATCH-SERIES cluster/ha-manager/manager/proxmox{,-perl-rs} 00/15] fix #7993: implement weighted auto rebalancing Dominik Rusovac
2026-10-21  8:59 ` [PATCH proxmox 01/15] resource-scheduling: scheduler: fix typos Dominik Rusovac
2026-10-21  8:59 ` Dominik Rusovac [this message]
2026-10-21 12:49   ` [PATCH proxmox 02/15] resource-scheduling: scheduler: abstract post-migration stats logic Daniel Kral
2026-10-21  8:59 ` [PATCH proxmox 03/15] fix #7993: resource-scheduling: lift to weighted load balancing Dominik Rusovac
2026-10-21  8:59 ` [PATCH proxmox 04/15] workspace,resource-scheduling: add proptest crate Dominik Rusovac
2026-10-21  8:59 ` [PATCH proxmox 05/15] resource-scheduling: scheduler: proptest weights Dominik Rusovac
2026-10-21  8:59 ` [PATCH proxmox-perl-rs 06/15] fix #7993: pve-rs: resource-scheduling: add weights to pve bindings Dominik Rusovac
2026-10-21  8:59 ` [PATCH pve-manager 07/15] fix #7993: ui: form: crs options: add weights Dominik Rusovac
2026-10-21  8:59 ` [PATCH pve-manager 08/15] ui: form: crs options: make options advanced Dominik Rusovac
2026-10-21  8:59 ` [PATCH pve-ha-manager 09/15] manager: remove obsolete argument Dominik Rusovac
2026-10-21  8:59 ` [PATCH pve-ha-manager 10/15] fix #7993: manager,usage: implement weighted auto rebalancing Dominik Rusovac
2026-10-21  8:59 ` [PATCH pve-ha-manager 11/15] sim: hardware: enable datacenter config changes at runtime Dominik Rusovac
2026-10-21  8:59 ` [PATCH pve-ha-manager 12/15] manager: log changes to crs settings Dominik Rusovac
2026-10-21  8:59 ` [PATCH pve-ha-manager 13/15] test: add auto rebalance with weights test cases Dominik Rusovac
2026-10-21  8:59 ` [PATCH pve-ha-manager 14/15] manager: rename update_crs_scheduler_mode Dominik Rusovac
2026-10-21  8:59 ` [PATCH pve-cluster 15/15] fix #7993: datacenter config: add ha-auto-rebalance-{cpu,mem}-weight Dominik Rusovac

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261021085932.1196302-3-d.rusovac@proxmox.com \
    --to=d.rusovac@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal