[pve-devel] [PATCH ha-manager 10/18] compile ha rules to a more compact representation
Daniel Kral
d.kral at proxmox.com
Wed Aug 27 17:19:03 CEST 2025
On Thu Aug 21, 2025 at 4:35 PM CEST, Daniel Kral wrote:
> diff --git a/src/PVE/HA/Rules/NodeAffinity.pm b/src/PVE/HA/Rules/NodeAffinity.pm
> index b7abf9a4..1af442ec 100644
> --- a/src/PVE/HA/Rules/NodeAffinity.pm
> +++ b/src/PVE/HA/Rules/NodeAffinity.pm
> @@ -251,31 +265,15 @@ If there are no available nodes at all, returns C<undef>.
>
> =cut
>
> -sub get_node_affinity : prototype($$$) {
> - my ($rules, $sid, $online_nodes) = @_;
> +sub get_node_affinity {
> + my ($node_affinity, $sid, $online_nodes) = @_;
>
> - my $node_affinity_rule = $get_resource_node_affinity_rule->($rules, $sid);
> -
> - # default to a node affinity rule with all available nodes
> - if (!$node_affinity_rule) {
> - for my $node (keys %$online_nodes) {
> - $node_affinity_rule->{nodes}->{$node} = { priority => 0 };
> - }
> - }
> -
> - # add remaining nodes with low priority for non-strict node affinity rules
> - if (!$node_affinity_rule->{strict}) {
> - for my $node (keys %$online_nodes) {
> - next if defined($node_affinity_rule->{nodes}->{$node});
> -
> - $node_affinity_rule->{nodes}->{$node} = { priority => -1 };
> - }
> - }
> + return ($online_nodes, $online_nodes) if !defined($node_affinity->{$sid}->{nodes});
Just noticed that the `$node_affinity->{$sid}->{nodes}` could cause
auto-vivification in the $node_affinity hash, so it should be something
like
return ($online_nodes, $online_nodes) if !defined($node_affinity->{$sid});
as the key $sid should only exist if there does actually exist a
rule for that HA resource $sid and `nodes` cannot be empty as it's a
required field in the section config, but a more auto-vivification-proof
solution should be used here.
I'll change that in a v2.
>
> my $allowed_nodes = {};
> my $prioritized_nodes = {};
>
> - while (my ($node, $props) = each %{ $node_affinity_rule->{nodes} }) {
> + while (my ($node, $props) = each $node_affinity->{$sid}->{nodes}->%*) {
> next if !defined($online_nodes->{$node}); # node is offline
>
> $allowed_nodes->{$node} = 1;
More information about the pve-devel
mailing list