From: "Daniel Kral" <d.kral@proxmox.com>
To: "David Riley" <d.riley@proxmox.com>, <pve-devel@lists.proxmox.com>
Subject: Re: [PATCH ha-manager v2 03/12] rules: node affinity: implement negative node affinity rules
Date: Tue, 14 Jul 2026 09:36:57 +0200 [thread overview]
Message-ID: <DJY4EH2MPX2O.2EZ3S3YPGMV9F@proxmox.com> (raw)
In-Reply-To: <03abfed5-06ee-441d-be5b-ca3fefcf0056@proxmox.com>
On Mon Jul 13, 2026 at 2:43 PM CEST, David Riley wrote:
> Thanks for the patch series.
> comments inline.
>
Thanks for taking the time to review this series!
> On 6/2/26 12:04 PM, Daniel Kral wrote:
[ snip ]
>> @@ -29,6 +30,25 @@ more verbose implementation.
>>
>> =cut
>>
>> +=head3 set_difference($hash1, $hash2)
>> +
>> +Returns a hash set of the set difference between the hash sets C<$hash1> and
>> +C<$hash2>, i.e. the elements that are in C<$hash1> without the elements that
>> +are in C<$hash2>.
>> +
>> +The hashes C<$hash1> and C<$hash2> are expected to be hash sets, i.e.
>> +key-value pairs are always set to C<1> or another truthy value.
>> +
>> +=cut
>> +
>> +sub set_difference : prototype($$) {
>
>
> Why did you opt for prototype($$) here?
> `set_intersect` and `set_union` don't seem to make use of this.
>
Good catch, that seems like a remnant of when I introduced this helper
for the HA rules series back then, but the helper went unused in the
end. Will remove that prototype for a newer revision!
>> + my ($hash1, $hash2) = @_;
>> +
>> + my $result = { map { $hash2->{$_} ? () : ($_ => 1) } keys %$hash1 };
>> +
>> + return $result;
>> +}
>> +
>> =head3 set_intersect($hash1, $hash2)
>>
>> Returns a hash set of the intersection of the hash sets C<$hash1> and
[ snip ]
>> @@ -256,6 +274,146 @@ __PACKAGE__->register_check(
>> },
>> );
>>
>> +=head3 check_nonempty_negative_nodes_complement($node_affinity_rules, $cluster_nodes)
>> +
>> +Returns a list of negative node affinity rule ids in C<$node_affinity_rules>,
>> +where the complement of the negative node set is an empty node set according to
>> +the currently configured cluster node list C<$cluster_nodes>, i.e., the
>> +negative node set specifies all cluster nodes.
>> +
>> +Even though this is only relevant for strict negative node affinity rules, this
>> +check also includes non-strict negative node affinity rules as their effective
>> +node set would be equivalent to setting no rule at all.
>> +
>> +If there are none, the returned list is empty.
>> +
>> +=cut
>> +
>> +sub check_nonempty_negative_nodes_complement {
>> + my ($node_affinity_rules, $cluster_nodes) = @_;
>> +
>> + my @conflicts = ();
>> +
>> + my $total_node_count = @$cluster_nodes;
>> +
>> + while (my ($ruleid, $rule) = each %$node_affinity_rules) {
>
>
> I'm not a perl expert by any means, but couldn't this be considered problematic.
>
> Consider this scenario:
> You have some kind of function that runs before this is being called which,
> iterates over the elements exactly like you do:
>
> while (my ($ruleid, $rule) = each %$node_affinity_rules) {
> if ($rule->{affinity} eq 'negative') {
> return $ruleid;
> }
> }
>
> but it has this early return statement. So if you have for example rule_a, rule_b
> and rule_c and it returns early on rule_a here, the internal iterator could
> still point at rule_a and never actually reset.
>
> It might not be the case at the moment, but further down the line this could
> be a wild bug to hunt down or am I misinterpreting the perldocs [0].
>
> Might be safer to just use a regular for loop here instead, but after looking
> at other parts of the code this seems to be used a lot in this file.
> And I also get why it was used here, as it makes it easier to grab the key-value
> pairs directly instead of looking them up manually.
> Nothing to worry about right away just something to look out for.
>
> [0] https://perldoc.perl.org/functions/each
>
Yeah, good catch! If I remember correctly I decided on this syntax usage
here for the HA rules in a code review.
As these checkers are meant to iterate through all rules as these should
check all rules. Otherwise, one should use the mentioned for loop which
dereferences the hash entries. So this becomes only troublesome if
someone doesn't know these each-subroutine caveats and the test cases
would quite likely immediately fail if not all items are evaluated.
FWIW as we EOL PVE 8, we might be able to make this use Perl v5.40,
where for loops with multiple iterations variables [0], which AFAIK do
not have these caveats with a hash-global iterator. Then we don't have
to deal with these kind of faults anymore.
[0] https://perldoc.perl.org/perlexperiment#for-loop-with-multiple-iteration-variables
>> + next if $rule->{affinity} ne 'negative';
>> +
>> + push @conflicts, $ruleid if keys $rule->{nodes}->%* >= $total_node_count;
>> + }
>> +
>> + @conflicts = sort @conflicts;
>> + return \@conflicts;
>> +}
[ snip ]
next prev parent reply other threads:[~2026-07-14 7:37 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-02 10:01 [PATCH-SERIES docs/ha-manager/manager v2 00/12] Negative Node Affinity Rules Daniel Kral
2026-06-02 10:01 ` [PATCH ha-manager v2 01/12] rules: node affinity: add affinity property to node affinity rules Daniel Kral
2026-06-02 10:01 ` [PATCH ha-manager v2 02/12] rules: rename ambiguous argument nodes to cluster nodes Daniel Kral
2026-07-13 12:41 ` David Riley
2026-06-02 10:01 ` [PATCH ha-manager v2 03/12] rules: node affinity: implement negative node affinity rules Daniel Kral
2026-07-13 12:43 ` David Riley
2026-07-14 7:36 ` Daniel Kral [this message]
2026-06-02 10:01 ` [PATCH manager v2 04/12] ui: ha: node affinity: handle non-existent nodes Daniel Kral
2026-06-02 10:01 ` [PATCH manager v2 05/12] ui: ha: node affinity: do update node selection all at once Daniel Kral
2026-06-02 10:01 ` [PATCH manager v2 06/12] ui: ha: node affinity: move node priority selector into separate component Daniel Kral
2026-07-13 12:43 ` David Riley
2026-07-14 7:57 ` Daniel Kral
2026-07-14 8:51 ` David Riley
2026-06-02 10:01 ` [PATCH manager v2 07/12] ui: ha: node affinity: allow setting affinity for node affinity rules Daniel Kral
2026-07-13 12:43 ` David Riley
2026-07-14 8:39 ` Daniel Kral
2026-06-02 10:01 ` [PATCH manager v2 08/12] ui: ha: node affinity: do not send default node affinity rule values Daniel Kral
2026-07-13 12:43 ` David Riley
2026-06-02 10:01 ` [PATCH docs v2 09/12] ha-manager: rules: use the correct article for terms starting with HA Daniel Kral
2026-07-13 12:43 ` David Riley
2026-06-02 10:01 ` [PATCH docs v2 10/12] ha-manager: rules: improve resource affinity rule short description Daniel Kral
2026-07-13 12:44 ` David Riley
2026-06-02 10:01 ` [PATCH docs v2 11/12] ha-manager: rules: adapt rule configuration examples Daniel Kral
2026-07-13 12:44 ` David Riley
2026-06-02 10:01 ` [PATCH docs v2 12/12] ha-manager: rules: add negative node affinity rule descriptions Daniel Kral
2026-07-13 12:44 ` David Riley
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=DJY4EH2MPX2O.2EZ3S3YPGMV9F@proxmox.com \
--to=d.kral@proxmox.com \
--cc=d.riley@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.