From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id C6A101FF065 for ; Mon, 23 Nov 2026 13:10:43 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 76617201EE; Mon, 23 Nov 2026 13:10:42 +0100 (CET) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Mon, 23 Nov 2026 13:10:34 +0100 Message-Id: Subject: Re: [PATCH ha-manager v2 2/2] manager: avoid nodes where moving a service failed From: "Daniel Kral" To: "Thomas Lamprecht" , X-Mailer: aerc 0.22.0-45-gc30c872fde7b-dirty References: <20261123072228.1506031-1-t.lamprecht@proxmox.com> <20261123072228.1506031-3-t.lamprecht@proxmox.com> In-Reply-To: <20261123072228.1506031-3-t.lamprecht@proxmox.com> X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795435834762 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.368 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) PROLO_LEO1 0.1 Meta Catches all Leo drug variations so far RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust 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: GMOTQ3YJQL4OFJHYIIOJJWHGCSJOINOA X-Message-ID-Hash: GMOTQ3YJQL4OFJHYIIOJJWHGCSJOINOA 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 Mon Nov 23, 2026 at 7:53 AM CET, Thomas Lamprecht wrote: > When moving a service failed, for example because the LRM refused a > target that would drop the guest identity, the next automatic move of > the service selected the same node again. Maintenance mode and shutdown > with the 'migrate' policy then retried that node every round and never > finished, even if other nodes would have worked, and rebalancing kept > trying to move the service there. > > Remember for five minutes where moving a service failed, and only > select such a node if no other node is left. Other nodes include nodes > with a lower priority and the current node, so a failed failback leaves > the service where it is. If only such nodes are left, try the one where > moving failed longest ago first. Rebalancing does not select them, as > it can always leave the service where it is. Explicit migration > requests are not affected. > > Signed-off-by: Thomas Lamprecht > --- > > new in v2 > > src/PVE/HA/Manager.pm | 78 +++++++++++++-- > .../test-crm-maintenance-request5/log.expect | 10 +- > src/test/test-migrate-old-target2/README | 5 +- > src/test/test-migrate-old-target2/log.expect | 77 +++++++-------- > src/test/test-migrate-old-target5/README | 7 ++ > src/test/test-migrate-old-target5/cmdlist | 3 + > .../test-migrate-old-target5/datacenter.cfg | 6 ++ > .../test-migrate-old-target5/hardware_status | 5 + > src/test/test-migrate-old-target5/log.expect | 98 +++++++++++++++++++ > .../test-migrate-old-target5/manager_status | 1 + > .../test-migrate-old-target5/service_config | 6 ++ > .../static_service_stats | 6 ++ > src/test/test-migrate-old-target6/README | 14 +++ > src/test/test-migrate-old-target6/cmdlist | 5 + > .../test-migrate-old-target6/hardware_status | 5 + > src/test/test-migrate-old-target6/log.expect | 74 ++++++++++++++ > .../test-migrate-old-target6/manager_status | 1 + > .../test-migrate-old-target6/rules_config | 7 ++ > .../test-migrate-old-target6/service_config | 4 + > .../log.expect | 36 +++---- > 20 files changed, 374 insertions(+), 74 deletions(-) > create mode 100644 src/test/test-migrate-old-target5/README > create mode 100644 src/test/test-migrate-old-target5/cmdlist > create mode 100644 src/test/test-migrate-old-target5/datacenter.cfg > create mode 100644 src/test/test-migrate-old-target5/hardware_status > create mode 100644 src/test/test-migrate-old-target5/log.expect > create mode 100644 src/test/test-migrate-old-target5/manager_status > create mode 100644 src/test/test-migrate-old-target5/service_config > create mode 100644 src/test/test-migrate-old-target5/static_service_stat= s > create mode 100644 src/test/test-migrate-old-target6/README > create mode 100644 src/test/test-migrate-old-target6/cmdlist > create mode 100644 src/test/test-migrate-old-target6/hardware_status > create mode 100644 src/test/test-migrate-old-target6/log.expect > create mode 100644 src/test/test-migrate-old-target6/manager_status > create mode 100644 src/test/test-migrate-old-target6/rules_config > create mode 100644 src/test/test-migrate-old-target6/service_config > > diff --git a/src/PVE/HA/Manager.pm b/src/PVE/HA/Manager.pm > index b719f23..bb3938f 100644 > --- a/src/PVE/HA/Manager.pm > +++ b/src/PVE/HA/Manager.pm > @@ -31,6 +31,9 @@ eval { > $have_dynamic_scheduling =3D 1; > }; > =20 > +# How long a node where moving a service failed is avoided for that serv= ice, in seconds. > +my $FAILED_TARGET_EXPIRY =3D 5 * 60; Can be a static time window for now, contemplating whether using exponential backoff with a upper time bound as in Michael Ryom's patch series [0] here could be useful. However, the main issue with exponential backoff is that the time window can grow too large and users cannot control or look into how much the HA Manager waits, so that could end up making the HA Manager wait a long time even though the issue we're waiting on has already been resolved in the mean time. So probably better to stay at a static, predictable time window. [0] https://lore.proxmox.com/pve-devel/20261018124559.24305-5-Michael@RyomH= erold.dk/ > + > ## Variable Name & Abbreviations Convention > # > # The HA stack has some variables it uses frequently and thus abbreviate= s it such that it may be > @@ -215,6 +218,13 @@ sub get_resource_migration_candidates { > =20 > delete $target_nodes->{$current_leader_node}; > =20 > + # rebalancing can always leave the resources where they are, so = it does not retry a node > + # where moving one of them failed > + for my $sid ($resource_bundles->{$leader_sid}->@*) { > + my $failed_targets =3D $ss->{$sid}->{failed_targets} // {}; > + delete $target_nodes->@{ keys %$failed_targets }; > + } > + > next if !%$target_nodes; > =20 > push @compact_migration_candidates, > @@ -339,6 +349,9 @@ The C<$node_preference> can be set to: > =20 > =3Dback > =20 > +Nodes in C<< $sd->{failed_targets} >>, where moving the service failed r= ecently, are only selected > +if no other node is left, also considering nodes with a lower priority a= nd the current node. > + > =3Dcut > =20 > sub select_service_node { > @@ -372,15 +385,45 @@ sub select_service_node { > return $current_node; > } > =20 > - # try to avoid nodes where the service failed already if we want to = relocate > - if ($node_preference eq 'try-next') { > - foreach my $node (@$tried_nodes) { > - delete $pri_nodes->{$node}; > + my $narrow_down =3D sub { > + my ($nodes) =3D @_; > + > + # try to avoid nodes where the service failed already if we want= to relocate > + if ($node_preference eq 'try-next') { > + foreach my $node (@$tried_nodes) { > + delete $nodes->{$node}; > + } > } > - } > =20 > - apply_negative_resource_affinity($separate, $pri_nodes); > - apply_positive_resource_affinity($together, $pri_nodes); > + apply_negative_resource_affinity($separate, $nodes); > + apply_positive_resource_affinity({ $together->%* }, $nodes); > + }; > + > + # Nodes where moving the service failed are only used if no other no= de is left, which may also > + # be a node with a lower priority or the current node, so leave them= out before the priorities. > + my $failed_targets =3D $sd->{failed_targets} // {}; > + my @avoided_nodes =3D grep { $_ ne $current_node && $online_nodes->{= $_} } keys %$failed_targets; > + if (@avoided_nodes) { > + my $other_nodes =3D { $online_nodes->%* }; > + delete $other_nodes->@{@avoided_nodes}; > + my (undef, $other_pri_nodes) =3D get_node_affinity($node_affinit= y, $sid, $other_nodes); > + $narrow_down->($other_pri_nodes); > + > + if (%$other_pri_nodes) { > + $pri_nodes =3D $other_pri_nodes; > + } else { > + $narrow_down->($pri_nodes); > + # retry the node where moving the service failed longest ago= first > + if (!grep { !$failed_targets->{$_} } keys %$pri_nodes) { > + my ($oldest) =3D sort { > + $failed_targets->{$a} <=3D> $failed_targets->{$b} ||= $a cmp $b > + } keys %$pri_nodes; > + $pri_nodes =3D { $oldest =3D> 1 } if defined($oldest); > + } > + } > + } else { > + $narrow_down->($pri_nodes); > + } select_service_node() is quite a stateful subroutine already and I'm currently working on fixing cases, where affinity rules and/or the maintenance fallback node aren't resolved correctly/efficiently here. This needs some care to get right and should come with a v3 for the maintenance node edge case series [1]. Unfortunately, this patch collides with this series quite much and would make untangling the existing errors in select_service_node() harder, so I'd prefer to wait for this functionality after select_service_node() has settled again. In general, it would be nice to make the special use cases from select_service_node() ('try-next', maintenance node fallback, avoid random migrations) be moved out, because most of them are for next_state_started() anyway, rather than adding more complexity in here, so it's easier to fix issues and review changes done here. Additionally, I think it would also be nice to make this remember failed starts for longer as well, because then the 'try-next' behavior could probably be made more stable in some scenarios as well... maybe even streamlined with remembering failed migrations, because it has the same incentive: to not issue migrations there as we suspect that an HA resource cannot be moved and/or started there. Then these might be able to share the same code path here as well, reducing the overall complexity. [1] https://lore.proxmox.com/pve-devel/20261106095650.72865-1-d.kral@proxmo= x.com/ > =20 > return $maintenance_fallback > if defined($maintenance_fallback) && $pri_nodes->{$maintenance_f= allback}; > @@ -518,6 +561,7 @@ my $change_service_state =3D sub { > my $old_state =3D $sd->{state}; > my $old_node =3D $sd->{node}; > my $old_failed_nodes =3D $sd->{failed_nodes}; > + my $old_failed_targets =3D $sd->{failed_targets}; > my $old_maintenance_node =3D $sd->{maintenance_node}; > =20 > die "no state change" if $old_state eq $new_state; # just to be sure > @@ -529,6 +573,7 @@ my $change_service_state =3D sub { > $sd->{state} =3D $new_state; > $sd->{node} =3D $old_node; > $sd->{failed_nodes} =3D $old_failed_nodes if defined($old_failed_nod= es); > + $sd->{failed_targets} =3D $old_failed_targets if defined($old_failed= _targets); > $sd->{maintenance_node} =3D $old_maintenance_node if defined($old_ma= intenance_node); > =20 > my $text_state =3D ''; > @@ -1170,6 +1215,8 @@ sub manage { > $self->{last_services_digest} =3D $services_digest; > } > =20 > + $self->forget_expired_failed_targets(); > + > $self->update_crm_commands(); > =20 > my $deferred_sids; > @@ -1353,6 +1400,7 @@ sub next_state_migrate_relocate { > $change_service_state->($self, $sid, $req_state, node =3D> $= sd->{node}); > } else { > $haenv->log('err', "service '$sid' - migration failed (exit = code $exit_code)"); > + $sd->{failed_targets}->{ $sd->{target} } =3D $haenv->get_tim= e(); nit: $sd->{target} coulde be factored out as $target_node before to avoid dereferencing a hash value to dereference another hash value It should be noted that now any HA resource migration marks failed targets. Also, should we log that the HA resource will not be automatically moved to the node again for $FAILED_TARGET_EXPIRY, so that users are aware for that behavior when looking at the logs? > &$change_service_state($self, $sid, $req_state, node =3D> $s= d->{node}); > return; > } > @@ -1483,6 +1531,20 @@ sub next_state_request_start { > $change_service_state->($self, $sid, 'started', node =3D> $current_n= ode); > } > =20 > +sub forget_expired_failed_targets { > + my ($self) =3D @_; > + > + my $now =3D $self->{haenv}->get_time(); > + for my $sd (values $self->{ss}->%*) { > + my $failed_targets =3D $sd->{failed_targets} or next; > + for my $node (keys %$failed_targets) { > + delete $failed_targets->{$node} > + if $now - $failed_targets->{$node} >=3D $FAILED_TARGET_E= XPIRY; > + } > + delete $sd->{failed_targets} if !%$failed_targets; > + } > +} > + > sub record_service_failed_on_node { > my ($self, $sid, $node) =3D @_; > =20 > @@ -1702,6 +1764,7 @@ sub next_state_error { > if ($cd->{state} eq 'disabled') { > # clean up on error recovery > delete $sd->{failed_nodes}; > + delete $sd->{failed_targets}; > =20 > &$change_service_state($self, $sid, 'stopped'); > return; > @@ -1760,6 +1823,7 @@ sub next_state_recovery { > if ($cd->{state} eq 'disabled') { > # allow getting a service out of recovery manually if an adm= in disables it. > delete $sd->{failed_nodes}; # clean up on recovery to stoppe= d > + delete $sd->{failed_targets}; > $change_service_state->($self, $sid, 'stopped'); # must NOT = go through request_stop > return; > }