From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id C26F91FF137 for ; Tue, 31 Mar 2026 11:42:39 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1ECDE166FC; Tue, 31 Mar 2026 11:43:07 +0200 (CEST) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Tue, 31 Mar 2026 11:42:32 +0200 Message-Id: Subject: Re: [PATCH ha-manager v3 35/40] implement automatic rebalancing From: "Daniel Kral" To: =?utf-8?q?Michael_K=C3=B6ppl?= , X-Mailer: aerc 0.21.0-38-g7088c3642f2c-dirty References: <20260330144101.668747-1-d.kral@proxmox.com> <20260330144101.668747-36-d.kral@proxmox.com> In-Reply-To: X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1774950097557 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.070 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 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: FXZFPELDEMBSBTYZTVU4TDNQRPKYUJJE X-Message-ID-Hash: FXZFPELDEMBSBTYZTVU4TDNQRPKYUJJE X-MailFrom: d.kral@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: On Tue Mar 31, 2026 at 11:07 AM CEST, Michael K=C3=B6ppl wrote: > On Mon Mar 30, 2026 at 4:30 PM CEST, Daniel Kral wrote: >> diff --git a/src/PVE/HA/Usage.pm b/src/PVE/HA/Usage.pm >> index 43feb041..659ab30a 100644 >> --- a/src/PVE/HA/Usage.pm >> +++ b/src/PVE/HA/Usage.pm >> @@ -60,6 +60,40 @@ sub remove_service_usage { >> die "implement in subclass"; >> } >> =20 >> +sub calculate_node_imbalance { >> + my ($self) =3D @_; >> + >> + die "implement in subclass"; >> +} >> + >> +sub score_best_balancing_migrations { >> + my ($self, $migration_candidates, $limit) =3D @_; >> + >> + die "implement in subclass"; >> +} >> + >> +sub select_best_balancing_migration { >> + my ($self, $migration_candidates) =3D @_; >> + >> + my $migrations =3D $self->score_best_balancing_migrations($migratio= n_candidates, 1); >> + >> + return $migrations->[0]; > > If an error occurs in the following call in > score_best_balancing_migrations > > my $migrations =3D eval { > $self->{scheduler} > ->score_best_balancing_migration_candidates_topsis($migration= _candidates, $limit); > }; > > you'd return an undefined $migrations, which would result in a > dereference error here. > Hm, I can't seem to reproduce it even if I just `return undef` in score_best_balancing_migrations{,_topsis}() and before writing this line I tested it with: # cat perl-array-empty.pl #!/usr/bin/perl =20 use v5.36; use Data::Dumper; =20 my $array1 =3D undef; my $array2 =3D []; my $array3 =3D [{}]; my $array4 =3D [{something =3D> 'a'}, {else =3D> 'b'}]; =20 my $i =3D 1; for my $var (($array1, $array2, $array3, $array4)) { print "array$i value: " . Dumper($var); print "array$i first: " . Dumper($var->[0]); =20 $i++; } # ./perl-array-empty.pl array1 value: $VAR1 =3D undef; array1 first: $VAR1 =3D undef; array2 value: $VAR1 =3D []; array2 first: $VAR1 =3D undef; array3 value: $VAR1 =3D [ {} ]; array3 first: $VAR1 =3D {}; array4 value: $VAR1 =3D [ { 'something' =3D> 'a' }, { 'else' =3D> 'b' } ]; array4 first: $VAR1 =3D { 'something' =3D> 'a' }; Or do you have another reproducer for this? >> +} >> + >> +sub score_best_balancing_migrations_topsis { >> + my ($self, $migration_candidates, $limit) =3D @_; >> + >> + die "implement in subclass"; >> +} >> + >> +sub select_best_balancing_migration_topsis { >> + my ($self, $migration_candidates) =3D @_; >> + >> + my $migrations =3D $self->score_best_balancing_migrations_topsis($m= igration_candidates, 1); >> + >> + return $migrations->[0]; >> +} >> + >> # Returns a hash with $nodename =3D> $score pairs. A lower $score is be= tter. >> sub score_nodes_to_start_service { >> my ($self, $sid) =3D @_; >> diff --git a/src/PVE/HA/Usage/Dynamic.pm b/src/PVE/HA/Usage/Dynamic.pm >> index 24c85a41..76d0feaa 100644 >> --- a/src/PVE/HA/Usage/Dynamic.pm >> +++ b/src/PVE/HA/Usage/Dynamic.pm >> @@ -104,6 +104,39 @@ sub remove_service_usage { >> $self->{haenv}->log('warning', "unable to remove service '$sid' usa= ge - $@") if $@; >> } >> =20 > > [snip]