From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id BE2BB1FF165
	for <inbox@lore.proxmox.com>; Thu, 24 Apr 2025 14:29:48 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 1543A7161;
	Thu, 24 Apr 2025 14:29:54 +0200 (CEST)
Message-ID: <d6d55f44-70a1-4da8-b19c-a88667126e14@proxmox.com>
Date: Thu, 24 Apr 2025 14:29:49 +0200
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
 Daniel Kral <d.kral@proxmox.com>
References: <20250325151254.193177-1-d.kral@proxmox.com>
 <20250325151254.193177-5-d.kral@proxmox.com>
Content-Language: en-US
From: Fiona Ebner <f.ebner@proxmox.com>
In-Reply-To: <20250325151254.193177-5-d.kral@proxmox.com>
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.038 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
 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [basic.pm, usage.pm, static.pm]
Subject: Re: [pve-devel] [PATCH ha-manager 03/15] usage: add
 get_service_node and pin_service_node methods
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

Am 25.03.25 um 16:12 schrieb Daniel Kral:
> Add methods get_service_node() and pin_service_node() to the Usage class
> to retrieve and pin the current node of a specific service.

Hmm, not sure about calling it "pin", why not "set"?

> 
> This is used to retrieve the current node of a service for colocation
> rules inside of select_service_node(), where there is currently no
> access to the global services state.
> 
> Signed-off-by: Daniel Kral <d.kral@proxmox.com>
> ---
> For me this is more of a temporary change, since I don't think putting
> this information here is very useful in the future. It was more of a
> workaround for the moment, since `select_service_node()` doesn't have
> access to the global service configuration data, which is needed here.
> 
> I would like to give `select_service_node()` the information from e.g.
> $sc directly post-RFC.

Yes, this sounds cleaner than essentially tracking the same things twice
in different places. Can't we do this as preparation to avoid such
temporary workarounds?

>  src/PVE/HA/Usage.pm        | 12 ++++++++++++
>  src/PVE/HA/Usage/Basic.pm  | 15 +++++++++++++++
>  src/PVE/HA/Usage/Static.pm | 14 ++++++++++++++
>  3 files changed, 41 insertions(+)
> 
> diff --git a/src/PVE/HA/Usage.pm b/src/PVE/HA/Usage.pm
> index 66d9572..e4f86d7 100644
> --- a/src/PVE/HA/Usage.pm
> +++ b/src/PVE/HA/Usage.pm
> @@ -27,6 +27,18 @@ sub list_nodes {
>      die "implement in subclass";
>  }
>  
> +sub get_service_node {
> +    my ($self, $sid) = @_;
> +
> +    die "implement in subclass";
> +}
> +
> +sub pin_service_node {
> +    my ($self, $sid, $node) = @_;
> +
> +    die "implement in subclass";
> +}
> +
>  sub contains_node {
>      my ($self, $nodename) = @_;
>  
> diff --git a/src/PVE/HA/Usage/Basic.pm b/src/PVE/HA/Usage/Basic.pm
> index d6b3d6c..50d687b 100644
> --- a/src/PVE/HA/Usage/Basic.pm
> +++ b/src/PVE/HA/Usage/Basic.pm
> @@ -10,6 +10,7 @@ sub new {
>  
>      return bless {
>  	nodes => {},
> +	services => {},

I feel like it would be more natural to also use 'service-nodes' here
like you do for the 'static' plugin [continued below...]

>  	haenv => $haenv,
>      }, $class;
>  }
> @@ -38,11 +39,25 @@ sub contains_node {
>      return defined($self->{nodes}->{$nodename});
>  }
>  
> +sub get_service_node {
> +    my ($self, $sid) = @_;
> +
> +    return $self->{services}->{$sid};

...because these kinds of expressions don't make it clear that this is a
node.

> +}
> +
> +sub pin_service_node {
> +    my ($self, $sid, $node) = @_;
> +
> +    $self->{services}->{$sid} = $node;
> +}
> +
>  sub add_service_usage_to_node {
>      my ($self, $nodename, $sid, $service_node, $migration_target) = @_;
>  
>      if ($self->contains_node($nodename)) {
> +	$self->{total}++;
>  	$self->{nodes}->{$nodename}++;
> +	$self->{services}->{$sid} = $nodename;
>      } else {
>  	$self->{haenv}->log(
>  	    'warning',
> diff --git a/src/PVE/HA/Usage/Static.pm b/src/PVE/HA/Usage/Static.pm
> index 3d0af3a..8db9202 100644
> --- a/src/PVE/HA/Usage/Static.pm
> +++ b/src/PVE/HA/Usage/Static.pm
> @@ -22,6 +22,7 @@ sub new {
>  	'service-stats' => {},
>  	haenv => $haenv,
>  	scheduler => $scheduler,
> +	'service-nodes' => {},
>  	'service-counts' => {}, # Service count on each node. Fallback if scoring calculation fails.
>      }, $class;
>  }
> @@ -85,9 +86,22 @@ my sub get_service_usage {
>      return $service_stats;
>  }
>  
> +sub get_service_node {
> +    my ($self, $sid) = @_;
> +
> +    return $self->{'service-nodes'}->{$sid};
> +}
> +
> +sub pin_service_node {
> +    my ($self, $sid, $node) = @_;
> +
> +    $self->{'service-nodes'}->{$sid} = $node;
> +}
> +
>  sub add_service_usage_to_node {
>      my ($self, $nodename, $sid, $service_node, $migration_target) = @_;
>  
> +    $self->{'service-nodes'}->{$sid} = $nodename;

This is why "pin" feels wrong to me. It will just get overwritten here
next time a usage calculation is made. Can that be problematic?

>      $self->{'service-counts'}->{$nodename}++;
>  
>      eval {



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel