[pve-devel] [PATCH v2 ha-manager 13/15] usage: static: use service count on nodes as a fallback
Fiona Ebner
f.ebner at proxmox.com
Thu Nov 17 15:00:14 CET 2022
if something goes wrong with the TOPSIS scoring. Not expected to
happen, but it's rather cheap to be on the safe side.
Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
---
New in v2.
src/PVE/HA/Usage/Static.pm | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/PVE/HA/Usage/Static.pm b/src/PVE/HA/Usage/Static.pm
index ce705eb..73ce836 100644
--- a/src/PVE/HA/Usage/Static.pm
+++ b/src/PVE/HA/Usage/Static.pm
@@ -22,12 +22,15 @@ sub new {
'service-stats' => {},
haenv => $haenv,
scheduler => $scheduler,
+ 'service-counts' => {}, # Service count on each node. Fallback if scoring calculation fails.
}, $class;
}
sub add_node {
my ($self, $nodename) = @_;
+ $self->{'service-counts'}->{$nodename} = 0;
+
my $stats = $self->{'node-stats'}->{$nodename}
or die "did not get static node usage information for '$nodename'\n";
die "static node usage information for '$nodename' missing cpu count\n" if !$stats->{cpus};
@@ -40,6 +43,8 @@ sub add_node {
sub remove_node {
my ($self, $nodename) = @_;
+ delete $self->{'service-counts'}->{$nodename};
+
$self->{scheduler}->remove_node($nodename);
}
@@ -83,6 +88,8 @@ my sub get_service_usage {
sub add_service_usage_to_node {
my ($self, $nodename, $sid, $service_node, $migration_target) = @_;
+ $self->{'service-counts'}->{$nodename}++;
+
eval {
my $service_usage = get_service_usage($self, $sid, $service_node, $migration_target);
$self->{scheduler}->add_service_usage_to_node($nodename, $service_usage);
@@ -103,8 +110,7 @@ sub score_nodes_to_start_service {
'err',
"unable to score nodes according to static usage for service '$sid' - $err",
);
- # TODO maybe use service count as fallback?
- return { map { $_ => 1 } $self->list_nodes() };
+ return $self->{'service-counts'};
}
# Take minus the value, so that a lower score is better, which our caller(s) expect(s).
--
2.30.2
More information about the pve-devel
mailing list