Skip to content

Commit

Permalink
fix(backup): don't backup views
Browse files Browse the repository at this point in the history
Fixes #3918
  • Loading branch information
Michal-Leszczynski committed Jul 11, 2024
1 parent 71356e8 commit 0b85d9d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/service/backup/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions pkg/service/backup/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()...),
Expand Down

0 comments on commit 0b85d9d

Please sign in to comment.