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.k...@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