Skip to content

Commit

Permalink
fix(backup): use keyspace ownership/locality information returned by …
Browse files Browse the repository at this point in the history
…Scylla

Validated manually as we don't have a single node test setup.

Fixes #3989
  • Loading branch information
Michal-Leszczynski authored and karol-kokoszka committed Sep 3, 2024
1 parent 0eeb8b4 commit 370c0d6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
8 changes: 5 additions & 3 deletions pkg/scyllaclient/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,11 @@ const (
type Ring struct {
ReplicaTokens []ReplicaTokenRanges
HostDC map[string]string
Replication ReplicationStrategy
RF int
DCrf map[string]int // initialized only for NetworkTopologyStrategy
// Replication is not returned by Scylla, but assumed by SM.
// Don't use it for correctness.
Replication ReplicationStrategy
RF int
DCrf map[string]int // initialized only for NetworkTopologyStrategy
}

// Datacenters returns a list of datacenters the keyspace is replicated in.
Expand Down
14 changes: 11 additions & 3 deletions pkg/service/backup/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,18 @@ func (f dcFilter) filter(_, _ string, ring scyllaclient.Ring) bool {
}

// Filters out tables containing local data, as they shouldn't be restored.
type localDataFilter struct{}
type localDataFilter struct {
keyspaces map[scyllaclient.KeyspaceType][]string
}

func (f localDataFilter) filter(_, _ string, ring scyllaclient.Ring) bool {
return ring.Replication != scyllaclient.LocalStrategy
func (f localDataFilter) filter(ks, _ string, _ scyllaclient.Ring) bool {
user, okU := f.keyspaces[scyllaclient.KeyspaceTypeUser]
nonLocal, okNL := f.keyspaces[scyllaclient.KeyspaceTypeNonLocal]
if !okU || !okNL {
panic(fmt.Sprintf("keyspace map %v does not contain expected entries %s and %s",
f.keyspaces, scyllaclient.KeyspaceTypeUser, scyllaclient.KeyspaceTypeNonLocal))
}
return slices.Contains(user, ks) || slices.Contains(nonLocal, ks)
}

// Filters out views as they are restored by re-creating them on restored base table.
Expand Down
7 changes: 6 additions & 1 deletion pkg/service/backup/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,15 @@ func (s *Service) targetFromProperties(ctx context.Context, clusterID uuid.UUID,
return Target{}, err
}

ks, err := client.KeyspacesByType(ctx)
if err != nil {
return Target{}, errors.Wrap(err, "get keyspaces by type")
}

filters := []tabFilter{
patternFilter{pattern: f},
dcFilter{dcs: strset.New(dcs...)},
localDataFilter{},
localDataFilter{keyspaces: ks},
}

// Try to add view filter - possible only when credentials are set
Expand Down

0 comments on commit 370c0d6

Please sign in to comment.