From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 6D0EA8E1F9 for ; Thu, 10 Nov 2022 15:44:36 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4F73629CB5 for ; Thu, 10 Nov 2022 15:44:06 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Thu, 10 Nov 2022 15:44:04 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 7B8A044B40 for ; Thu, 10 Nov 2022 15:38:07 +0100 (CET) From: Fiona Ebner To: pve-devel@lists.proxmox.com Date: Thu, 10 Nov 2022 15:37:53 +0100 Message-Id: <20221110143800.98047-15-f.ebner@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221110143800.98047-1-f.ebner@proxmox.com> References: <20221110143800.98047-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.027 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% 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 Subject: [pve-devel] [PATCH ha-manager 05/11] manager: online node usage: switch to Usage::Basic plugin X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Nov 2022 14:44:36 -0000 no functional change is intended. One test needs adaptation too, because it created its own version of $online_node_usage. Signed-off-by: Fiona Ebner --- src/PVE/HA/Manager.pm | 35 +++++++++++++++++------------------ src/test/test_failover1.pl | 19 ++++++++++--------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/PVE/HA/Manager.pm b/src/PVE/HA/Manager.pm index 63c94af..63e6c8a 100644 --- a/src/PVE/HA/Manager.pm +++ b/src/PVE/HA/Manager.pm @@ -7,6 +7,7 @@ use Digest::MD5 qw(md5_base64); use PVE::Tools; use PVE::HA::Tools ':exit_codes'; use PVE::HA::NodeStatus; +use PVE::HA::Usage::Basic; ## Variable Name & Abbreviations Convention # @@ -77,9 +78,7 @@ sub get_service_group { my $group = {}; # add all online nodes to default group to allow try_next when no group set - foreach my $node (keys %$online_node_usage) { - $group->{nodes}->{$node} = 1; - } + $group->{nodes}->{$_} = 1 for $online_node_usage->list_nodes(); # overwrite default if service is bound to a specific group if (my $group_id = $service_conf->{group}) { @@ -100,7 +99,7 @@ sub get_node_priority_groups { if ($entry =~ m/^(\S+):(\d+)$/) { ($node, $pri) = ($1, $2); } - next if !defined($online_node_usage->{$node}); # offline + next if !$online_node_usage->contains_node($node); # offline $pri_groups->{$pri}->{$node} = 1; $group_members->{$node} = $pri; } @@ -108,7 +107,7 @@ sub get_node_priority_groups { # add non-group members to unrestricted groups (priority -1) if (!$group->{restricted}) { my $pri = -1; - foreach my $node (keys %$online_node_usage) { + for my $node ($online_node_usage->list_nodes()) { next if defined($group_members->{$node}); $pri_groups->{$pri}->{$node} = 1; $group_members->{$node} = -1; @@ -144,8 +143,9 @@ sub select_service_node { } } + my $scores = $online_node_usage->score_nodes_to_start_service($sid, $current_node); my @nodes = sort { - $online_node_usage->{$a} <=> $online_node_usage->{$b} || $a cmp $b + $scores->{$a} <=> $scores->{$b} || $a cmp $b } keys %{$pri_groups->{$top_pri}}; my $found; @@ -201,39 +201,38 @@ my $valid_service_states = { sub recompute_online_node_usage { my ($self) = @_; - my $online_node_usage = {}; + my $online_node_usage = PVE::HA::Usage::Basic->new($self->{haenv}); my $online_nodes = $self->{ns}->list_online_nodes(); - foreach my $node (@$online_nodes) { - $online_node_usage->{$node} = 0; - } + $online_node_usage->add_node($_) for $online_nodes->@*; foreach my $sid (keys %{$self->{ss}}) { my $sd = $self->{ss}->{$sid}; my $state = $sd->{state}; my $target = $sd->{target}; # optional - if (defined($online_node_usage->{$sd->{node}})) { + if ($online_node_usage->contains_node($sd->{node})) { if ( $state eq 'started' || $state eq 'request_stop' || $state eq 'fence' || $state eq 'freeze' || $state eq 'error' || $state eq 'recovery' ) { - $online_node_usage->{$sd->{node}}++; + $online_node_usage->add_service_usage_to_node($sd->{node}, $sid, $sd->{node}); } elsif (($state eq 'migrate') || ($state eq 'relocate')) { + my $source = $sd->{node}; # count it for both, source and target as load is put on both - $online_node_usage->{$sd->{node}}++; - $online_node_usage->{$target}++; + $online_node_usage->add_service_usage_to_node($source, $sid, $source, $target); + $online_node_usage->add_service_usage_to_node($target, $sid, $source, $target); } elsif ($state eq 'stopped') { # do nothing } else { die "should not be reached (sid = '$sid', state = '$state')"; } - } elsif (defined($target) && defined($online_node_usage->{$target})) { + } elsif (defined($target) && $online_node_usage->contains_node($target)) { if ($state eq 'migrate' || $state eq 'relocate') { # to correctly track maintenance modi and also consider the target as used for the # case a node dies, as we cannot really know if the to-be-aborted incoming migration # has already cleaned up all used resources - $online_node_usage->{$target}++; + $online_node_usage->add_service_usage_to_node($target, $sid, $sd->{node}, $target); } } } @@ -775,7 +774,7 @@ sub next_state_started { ); if ($node && ($sd->{node} ne $node)) { - $self->{online_node_usage}->{$node}++; + $self->{online_node_usage}->add_service_usage_to_node($node, $sid, $sd->{node}); if (defined(my $fallback = $sd->{maintenance_node})) { if ($node eq $fallback) { @@ -864,7 +863,7 @@ sub next_state_recovery { $fence_recovery_cleanup->($self, $sid, $fenced_node); $haenv->steal_service($sid, $sd->{node}, $recovery_node); - $self->{online_node_usage}->{$recovery_node}++; + $self->{online_node_usage}->add_service_usage_to_node($recovery_node, $sid, $recovery_node); # NOTE: $sd *is normally read-only*, fencing is the exception $cd->{node} = $sd->{node} = $recovery_node; diff --git a/src/test/test_failover1.pl b/src/test/test_failover1.pl index f11d1a6..308eab3 100755 --- a/src/test/test_failover1.pl +++ b/src/test/test_failover1.pl @@ -6,6 +6,7 @@ use warnings; use lib '..'; use PVE::HA::Groups; use PVE::HA::Manager; +use PVE::HA::Usage::Basic; my $groups = PVE::HA::Groups->parse_config("groups.tmp", < 0, - node2 => 0, - node3 => 0, -}; +# Relies on the fact that the basic plugin doesn't use the haenv. +my $online_node_usage = PVE::HA::Usage::Basic->new(); +$online_node_usage->add_node("node1"); +$online_node_usage->add_node("node2"); +$online_node_usage->add_node("node3"); my $service_conf = { node => 'node1', @@ -43,22 +44,22 @@ sub test { test('node1'); test('node1', 1); -delete $online_node_usage->{node1}; # poweroff +$online_node_usage->remove_node("node1"); # poweroff test('node2'); test('node3', 1); test('node2', 1); -delete $online_node_usage->{node2}; # poweroff +$online_node_usage->remove_node("node2"); # poweroff test('node3'); test('node3', 1); -$online_node_usage->{node1} = 0; # poweron +$online_node_usage->add_node("node1"); # poweron test('node1'); -$online_node_usage->{node2} = 0; # poweron +$online_node_usage->add_node("node2"); # poweron test('node1'); test('node1', 1); -- 2.30.2