From 0b85d9d4caeb1b1a2d6dc15442c313bf46cb8b88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= <2000michal@wp.pl> Date: Thu, 11 Jul 2024 14:38:49 +0200 Subject: [PATCH] fix(backup): don't backup views Fixes #3918 --- pkg/service/backup/model.go | 10 ++++++++++ pkg/service/backup/service.go | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/pkg/service/backup/model.go b/pkg/service/backup/model.go index 42f540ab9..6b95fb04b 100644 --- a/pkg/service/backup/model.go +++ b/pkg/service/backup/model.go @@ -497,6 +497,16 @@ func (f localDataFilter) filter(_, _ string, ring scyllaclient.Ring) bool { return ring.Replication != scyllaclient.LocalStrategy } +// Filters out views as they are restored by re-creating them on restored base table. +// There is no use in backing up their sstables. +type viewFilter struct { + views *strset.Set +} + +func (f viewFilter) filter(ks, tab string, _ scyllaclient.Ring) bool { + return !f.views.Has(ks + "." + tab) +} + // tableValidator checks if it's safe to back up table. type tabValidator interface { validate(ks, tab string, ring scyllaclient.Ring) error diff --git a/pkg/service/backup/service.go b/pkg/service/backup/service.go index 1583f35f3..910736e7e 100644 --- a/pkg/service/backup/service.go +++ b/pkg/service/backup/service.go @@ -28,6 +28,7 @@ import ( "github.com/scylladb/scylla-manager/v3/pkg/util/inexlist/ksfilter" "github.com/scylladb/scylla-manager/v3/pkg/util/jsonutil" "github.com/scylladb/scylla-manager/v3/pkg/util/parallel" + "github.com/scylladb/scylla-manager/v3/pkg/util/query" "github.com/scylladb/scylla-manager/v3/pkg/util/timeutc" "github.com/scylladb/scylla-manager/v3/pkg/util/uuid" "go.uber.org/atomic" @@ -161,6 +162,22 @@ func (s *Service) GetTarget(ctx context.Context, clusterID uuid.UUID, properties localDataFilter{}, } + // Try to add view filter - possible only when credentials are set + session, err := s.clusterSession(ctx, clusterID) + switch { + case err == nil: + defer session.Close() + views, err := query.GetAllViews(session) + if err != nil { + return Target{}, errors.Wrap(err, "get cluster views") + } + filters = append(filters, viewFilter{views: views}) + case errors.Is(err, cluster.ErrNoCQLCredentials): + s.logger.Error(ctx, "No CQL cluster credentials, backup of views won't be skipped", "error", err) + default: + return Target{}, errors.Wrap(err, "create cluster session") + } + validators := []tabValidator{ tokenRangesValidator{ liveNodes: strset.New(liveNodes.Hosts()...),