From ed87d32ab9968250189aebfa9ed255a8f6a939ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= <2000michal@wp.pl> Date: Tue, 10 Sep 2024 16:34:49 +0200 Subject: [PATCH] fix(cluster): don't assume that --host is set E.g. clusters created before SM 3.2.6 can have empty --host SM DB column. --- pkg/service/cluster/service.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/service/cluster/service.go b/pkg/service/cluster/service.go index f86c2bd61..df0770ca3 100644 --- a/pkg/service/cluster/service.go +++ b/pkg/service/cluster/service.go @@ -173,10 +173,19 @@ func (s *Service) discoverAndSetClusterHosts(ctx context.Context, c *Cluster) er func (s *Service) discoverClusterHosts(ctx context.Context, c *Cluster) ([]string, error) { var contactPoints []string - contactPoints = append(contactPoints, c.Host) // Go with the designated contact point first + if c.Host != "" { + contactPoints = append(contactPoints, c.Host) // Go with the designated contact point first + } else { + s.logger.Error(ctx, "Missing --host flag. Using only previously discovered hosts instead", "cluster ID", c.ID) + } contactPoints = append(contactPoints, c.KnownHosts...) // In case it failed, try to contact previously discovered hosts for _, cp := range contactPoints { + if cp == "" { + s.logger.Error(ctx, "Empty contact point", "cluster ID", c.ID, "contact points", contactPoints) + continue + } + config := scyllaclient.DefaultConfigWithTimeout(s.timeoutConfig) if c.Port != 0 { config.Port = fmt.Sprint(c.Port)