all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Daniel Kral <d.kral@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH ha-manager 6/7] make get_node_affinity return all priority classes sorted in descending order
Date: Wed, 22 Apr 2026 12:00:24 +0200	[thread overview]
Message-ID: <20260422100035.232716-7-d.kral@proxmox.com> (raw)
In-Reply-To: <20260422100035.232716-1-d.kral@proxmox.com>

This is in preparation of the next patch, which needs to iterate through
the priority classes from the highest to the lowest priority class.

Signed-off-by: Daniel Kral <d.kral@proxmox.com>
---
 src/PVE/HA/Manager.pm            |  7 +++++--
 src/PVE/HA/Rules/NodeAffinity.pm | 24 ++++++++++++++----------
 2 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/src/PVE/HA/Manager.pm b/src/PVE/HA/Manager.pm
index ce5d69a4..0d7a2f59 100644
--- a/src/PVE/HA/Manager.pm
+++ b/src/PVE/HA/Manager.pm
@@ -194,7 +194,9 @@ sub get_resource_migration_candidates {
         my $current_leader_node = $ss->{$leader_sid}->{node};
         my $online_nodes = { map { $_ => 1 } $online_node_usage->list_nodes() };
 
-        my (undef, $target_nodes) = get_node_affinity($node_affinity, $leader_sid, $online_nodes);
+        my (undef, $priority_classes) =
+            get_node_affinity($node_affinity, $leader_sid, $online_nodes);
+        my $target_nodes = shift @$priority_classes // {};
         my ($together, $separate) =
             get_resource_affinity($resource_affinity, $leader_sid, $ss, $online_nodes);
         apply_negative_resource_affinity($separate, $target_nodes);
@@ -325,7 +327,8 @@ sub select_service_node {
         $compiled_rules->@{qw(node-affinity resource-affinity)};
 
     my $online_nodes = { map { $_ => 1 } $online_node_usage->list_nodes() };
-    my ($allowed_nodes, $pri_nodes) = get_node_affinity($node_affinity, $sid, $online_nodes);
+    my ($allowed_nodes, $priority_classes) = get_node_affinity($node_affinity, $sid, $online_nodes);
+    my $pri_nodes = shift @$priority_classes // {};
 
     return undef if !%$pri_nodes;
 
diff --git a/src/PVE/HA/Rules/NodeAffinity.pm b/src/PVE/HA/Rules/NodeAffinity.pm
index 3fa1fdb4..9b4edbfd 100644
--- a/src/PVE/HA/Rules/NodeAffinity.pm
+++ b/src/PVE/HA/Rules/NodeAffinity.pm
@@ -253,22 +253,26 @@ __PACKAGE__->register_check(
 
 =head3 get_node_affinity($node_affinity, $sid, $online_nodes)
 
-Returns a list of two hashes representing the node affinity of C<$sid>
-according to the node affinity C<$node_affinity> and the available nodes in
-the C<$online_nodes> hash.
+Returns a list of a hash and a list representing the available nodes and the
+priority classes of the node affinity of C<$sid> according to the node affinity
+C<$node_affinity> and the online nodes in the C<$online_nodes> hash.
 
 The first hash is a hash set of available nodes, i.e. nodes where the
-resource C<$sid> is allowed to be assigned to, and the second hash is a hash set
-of preferred nodes, i.e. nodes where the resource C<$sid> should be assigned to.
+resource C<$sid> is allowed to be assigned to.
 
-If there are no available nodes at all, returns C<undef>.
+The second item is a list of hash sets of priority classes sorted from highest
+to lowest priority, where each priority class contains the nodes where the
+resource C<$sid> can be assigned to. This list does not contain effectively
+empty priority classes.
+
+If there are no available nodes at all, returns C<({}, [])>.
 
 =cut
 
 sub get_node_affinity {
     my ($node_affinity, $sid, $online_nodes) = @_;
 
-    return ($online_nodes, $online_nodes) if !defined($node_affinity->{$sid});
+    return ($online_nodes, [$online_nodes]) if !defined($node_affinity->{$sid});
 
     my $allowed_nodes = {};
     my $prioritized_nodes = {};
@@ -283,10 +287,10 @@ sub get_node_affinity {
     }
 
     my $preferred_nodes = {};
-    my $highest_priority = (sort { $b <=> $a } keys %$prioritized_nodes)[0];
-    $preferred_nodes = $prioritized_nodes->{$highest_priority} if defined($highest_priority);
+    my @priority_class_numbers = sort { $b <=> $a } keys %$prioritized_nodes;
+    my $priority_classes = [map { $prioritized_nodes->{$_} } @priority_class_numbers];
 
-    return ($allowed_nodes, $preferred_nodes);
+    return ($allowed_nodes, $priority_classes);
 }
 
 1;
-- 
2.47.3





  parent reply	other threads:[~2026-04-22 10:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-22 10:00 [PATCH-SERIES ha-manager 0/7] improve handling of maintenance nodes Daniel Kral
2026-04-22 10:00 ` [PATCH ha-manager 1/7] manager: warn if HA resources cannot be moved away from maintenance node Daniel Kral
2026-04-22 10:00 ` [PATCH ha-manager 2/7] test: add test casses for node affinity rules with maintenance mode Daniel Kral
2026-04-22 10:00 ` [PATCH ha-manager 3/7] test: add test cases for resource " Daniel Kral
2026-04-22 10:00 ` [PATCH ha-manager 4/7] manager: make HA resources without failback move back to maintenance node Daniel Kral
2026-04-22 10:00 ` [PATCH ha-manager 5/7] manager: make HA resource bundles " Daniel Kral
2026-04-22 10:00 ` Daniel Kral [this message]
2026-04-22 10:00 ` [PATCH ha-manager 7/7] manager: try multiple priority classes when applying negative resource affinity Daniel Kral

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=20260422100035.232716-7-d.kral@proxmox.com \
    --to=d.kral@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal