Skip to content

Commit

Permalink
feat(backup): use RingDescriber per table basis
Browse files Browse the repository at this point in the history
This is required for tablet tables which have per table ring description.
  • Loading branch information
Michal-Leszczynski committed Mar 20, 2024
1 parent 5ea2a5a commit a019436
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 30 deletions.
11 changes: 7 additions & 4 deletions pkg/service/backup/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ func (s *Service) InitTarget(ctx context.Context, clusterID uuid.UUID, target *T
}

// Collect ring information
ringDescriber := scyllaclient.NewRingDescriber(ctx, client)
rings := make(map[string]scyllaclient.Ring, len(target.Units))
for _, u := range target.Units {
ring, err := client.DescribeVnodeRing(ctx, u.Keyspace)
if err != nil {
return errors.Wrap(err, "initialize: describe keyspace ring")
for _, tab := range u.Tables {
ring, err := ringDescriber.DescribeRing(ctx, u.Keyspace, tab)
if err != nil {
return errors.Wrap(err, "initialize: describe keyspace ring")
}
rings[u.Keyspace+"."+tab] = ring
}
rings[u.Keyspace] = ring
}

// Get live nodes
Expand Down
62 changes: 36 additions & 26 deletions pkg/service/backup/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,36 +220,44 @@ func (s *Service) GetTarget(ctx context.Context, clusterID uuid.UUID, properties
AllTables: true,
}

ringDescriber := scyllaclient.NewRingDescriber(ctx, client)
for _, keyspace := range keyspaces {
tables, err := client.Tables(ctx, keyspace)
if err != nil {
return t, errors.Wrapf(err, "keyspace %s: get tables", keyspace)
}

// Get the ring description and skip local data
ring, err := client.DescribeVnodeRing(ctx, keyspace)
if err != nil {
return t, errors.Wrapf(err, "keyspace %s: get ring description", keyspace)
}
if ring.Replication == scyllaclient.LocalStrategy {
if strings.HasPrefix(keyspace, "system") && keyspace != "system_schema" {
continue
var filteredTables []string
for _, tab := range tables {
// Get the ring description and skip local data
ring, err := ringDescriber.DescribeRing(ctx, keyspace, tab)
if err != nil {
return t, errors.Wrapf(err, "%s.%s: get ring description", keyspace, tab)
}
} else {
// Check if keyspace has replica in any DC
if !targetDCs.HasAny(ring.Datacenters()...) {
continue
if ring.Replication == scyllaclient.LocalStrategy {
if strings.HasPrefix(keyspace, "system") && keyspace != "system_schema" {
continue
}
} else {
// Check if keyspace has replica in any DC
if !targetDCs.HasAny(ring.Datacenters()...) {
continue
}
}
}

// Collect ring information
rings[keyspace] = ring
// Collect ring information
rings[keyspace+"."+tab] = ring

// Do not filter system_schema
if keyspace == systemSchema {
systemSchemaUnit.Tables = tables
} else {
f.Add(keyspace, tables)
// Do not filter system_schema
if keyspace == systemSchema {
systemSchemaUnit.Tables = append(systemSchemaUnit.Tables, tab)
} else {
filteredTables = append(filteredTables, tab)
}
}

if len(filteredTables) > 0 {
f.Add(keyspace, filteredTables)
}
}

Expand Down Expand Up @@ -305,12 +313,14 @@ func (s *Service) getLiveNodes(ctx context.Context, client *scyllaclient.Client,
// Validate that there are enough live nodes to back up all tokens
if len(liveNodes) < len(nodes) {
hosts := strset.New(liveNodes.Hosts()...)
for i := range target.Units {
r := rings[target.Units[i].Keyspace]
if r.Replication != scyllaclient.LocalStrategy {
for _, rt := range r.ReplicaTokens {
if !hosts.HasAny(rt.ReplicaSet...) {
return nil, errors.Errorf("not enough live nodes to backup keyspace %s", target.Units[i].Keyspace)
for _, ks := range target.Units {
for _, tab := range ks.Tables {
r := rings[ks.Keyspace+"."+tab]
if r.Replication != scyllaclient.LocalStrategy {
for _, rt := range r.ReplicaTokens {
if !hosts.HasAny(rt.ReplicaSet...) {
return nil, errors.Errorf("not enough live nodes to backup keyspace %s", ks.Keyspace)
}
}
}
}
Expand Down

0 comments on commit a019436

Please sign in to comment.