From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 11EB11FF16F for ; Tue, 30 Sep 2025 16:21:03 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 55B219906; Tue, 30 Sep 2025 16:20:34 +0200 (CEST) From: Daniel Kral To: pve-devel@lists.proxmox.com Date: Tue, 30 Sep 2025 16:19:17 +0200 Message-ID: <20250930142021.366529-11-d.kral@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250930142021.366529-1-d.kral@proxmox.com> References: <20250930142021.366529-1-d.kral@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1759242004130 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.015 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 Subject: [pve-devel] [PATCH ha-manager 7/9] usage: allow granular changes to Usage implementations 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: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" This makes use of the new signature for add_service_usage_to_node(...) from the Proxmox::RS::ResourceScheduling::Static package, which allows tracking of which HA resources have been assigned to which nodes. Signed-off-by: Daniel Kral --- src/PVE/HA/Usage.pm | 6 ++++++ src/PVE/HA/Usage/Basic.pm | 14 +++++++++++--- src/PVE/HA/Usage/Static.pm | 26 ++++++++++++++++++++------ 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/PVE/HA/Usage.pm b/src/PVE/HA/Usage.pm index 66d9572e..f19fae76 100644 --- a/src/PVE/HA/Usage.pm +++ b/src/PVE/HA/Usage.pm @@ -40,6 +40,12 @@ sub add_service_usage_to_node { die "implement in subclass"; } +sub remove_service_usage { + my ($self, $sid) = @_; + + die "implement in subclass"; +} + # Returns a hash with $nodename => $score pairs. A lower $score is better. sub score_nodes_to_start_service { my ($self, $sid, $service_node) = @_; diff --git a/src/PVE/HA/Usage/Basic.pm b/src/PVE/HA/Usage/Basic.pm index ead08c54..9b80661a 100644 --- a/src/PVE/HA/Usage/Basic.pm +++ b/src/PVE/HA/Usage/Basic.pm @@ -17,7 +17,7 @@ sub new { sub add_node { my ($self, $nodename) = @_; - $self->{nodes}->{$nodename} = 0; + $self->{nodes}->{$nodename} = {}; } sub remove_node { @@ -42,7 +42,7 @@ sub add_service_usage_to_node { my ($self, $nodename, $sid, $service_node, $migration_target) = @_; if ($self->contains_node($nodename)) { - $self->{nodes}->{$nodename}++; + $self->{nodes}->{$nodename}->{$sid} = 1; } else { $self->{haenv}->log( 'warning', @@ -51,10 +51,18 @@ sub add_service_usage_to_node { } } +sub remove_service_usage { + my ($self, $sid) = @_; + + for my $node ($self->list_nodes()) { + delete $self->{nodes}->{$node}->{$sid}; + } +} + sub score_nodes_to_start_service { my ($self, $sid, $service_node) = @_; - return $self->{nodes}; + return { map { $_ => scalar keys $self->{nodes}->{$_}->%* } keys $self->{nodes}->%* }; } 1; diff --git a/src/PVE/HA/Usage/Static.pm b/src/PVE/HA/Usage/Static.pm index 061e74a2..2867d4ff 100644 --- a/src/PVE/HA/Usage/Static.pm +++ b/src/PVE/HA/Usage/Static.pm @@ -22,14 +22,14 @@ sub new { 'service-stats' => {}, haenv => $haenv, scheduler => $scheduler, - 'service-counts' => {}, # Service count on each node. Fallback if scoring calculation fails. + 'node-services' => {}, # Services on each node. Fallback if scoring calculation fails. }, $class; } sub add_node { my ($self, $nodename) = @_; - $self->{'service-counts'}->{$nodename} = 0; + $self->{'node-services'}->{$nodename} = {}; my $stats = $self->{'node-stats'}->{$nodename} or die "did not get static node usage information for '$nodename'\n"; @@ -43,7 +43,7 @@ sub add_node { sub remove_node { my ($self, $nodename) = @_; - delete $self->{'service-counts'}->{$nodename}; + delete $self->{'node-services'}->{$nodename}; $self->{scheduler}->remove_node($nodename); } @@ -89,16 +89,27 @@ my sub get_service_usage { sub add_service_usage_to_node { my ($self, $nodename, $sid, $service_node, $migration_target) = @_; - $self->{'service-counts'}->{$nodename}++; + $self->{'node-services'}->{$nodename}->{$sid} = 1; eval { my $service_usage = get_service_usage($self, $sid, $service_node, $migration_target); - $self->{scheduler}->add_service_usage_to_node($nodename, $service_usage); + $self->{scheduler}->add_service_usage_to_node($nodename, $sid, $service_usage); }; $self->{haenv}->log('warning', "unable to add service '$sid' usage to node '$nodename' - $@") if $@; } +sub remove_service_usage { + my ($self, $sid) = @_; + + delete $self->{'node-services'}->{$_}->{$sid} for $self->list_nodes(); + + eval { $self->{scheduler}->remove_service_usage($sid) }; + $self->{haenv}->log('warning', "unable to remove service '$sid' usage - $@") if $@; + + delete $self->{'service-stats'}->{$sid}; # Invalidate old service stats +} + sub score_nodes_to_start_service { my ($self, $sid, $service_node) = @_; @@ -111,7 +122,10 @@ sub score_nodes_to_start_service { 'err', "unable to score nodes according to static usage for service '$sid' - $err", ); - return $self->{'service-counts'}; + return { + map { $_ => scalar keys $self->{'node-services'}->{$_}->%* } + keys $self->{'node-services'}->%* + }; } # Take minus the value, so that a lower score is better, which our caller(s) expect(s). -- 2.47.3 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel