Skip to content

Commit

Permalink
feat(repair): 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 7ed1e3d commit 5ea2a5a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 40 deletions.
15 changes: 6 additions & 9 deletions pkg/service/repair/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,18 @@ func (g *generator) Run(ctx context.Context) error {
g.logger.Info(ctx, "Start generator")
var genErr error

ringDescriber := scyllaclient.NewRingDescriber(ctx, g.client)
for _, ksp := range g.plan.Keyspaces {
if !g.shouldGenerate() {
break
}

ring, err := g.client.DescribeVnodeRing(ctx, ksp.Keyspace)
if err != nil {
return errors.Wrap(err, "describe ring")
}

for _, tp := range ksp.Tables {
if !g.shouldGenerate() {
break
}

ring, err := ringDescriber.DescribeRing(ctx, ksp.Keyspace, tp.Table)
if err != nil {
return errors.Wrap(err, "describe ring")
}

tg := g.newTableGenerator(ksp.Keyspace, tp, ring)
// All errors are logged, so in order to reduce clutter,
// return only the first one.
Expand Down
62 changes: 31 additions & 31 deletions pkg/service/repair/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,53 +63,53 @@ func newPlan(ctx context.Context, target Target, client *scyllaclient.Client) (*
maxP int
)

ringDescriber := scyllaclient.NewRingDescriber(ctx, client)
for _, u := range target.Units {
ring, err := client.DescribeVnodeRing(ctx, u.Keyspace)
if err != nil {
return nil, errors.Wrapf(err, "keyspace %s: get ring description", u.Keyspace)
}
// Allow repairing single node cluster for better UX.
if len(status) > 1 && !ShouldRepairRing(ring, target.DC, target.Host) {
continue
}

// Update max parallel
maxP = max(maxP, MaxRingParallel(ring, target.DC))

// Update ranges and hosts
rangesCnt := 0
replicaSetCnt := 0
for _, rep := range ring.ReplicaTokens {
filtered := filterReplicaSet(rep.ReplicaSet, ring.HostDC, target)
if len(filtered) == 0 {
var tables []tablePlan
for _, t := range u.Tables {
ring, err := ringDescriber.DescribeRing(ctx, u.Keyspace, t)
if err != nil {
return nil, errors.Wrapf(err, "keyspace %s.%s: get ring description", u.Keyspace, t)
}
// Allow repairing single node cluster for better UX.
if len(status) > 1 && !ShouldRepairRing(ring, target.DC, target.Host) {
continue
}

replicaSetCnt++
allHosts.Add(filtered...)
// Update max parallel
maxP = max(maxP, MaxRingParallel(ring, target.DC))

// Update ranges and hosts
rangesCnt := 0
replicaSetCnt := 0
for _, rep := range ring.ReplicaTokens {
filtered := filterReplicaSet(rep.ReplicaSet, ring.HostDC, target)
if len(filtered) == 0 {
continue
}

replicaSetCnt++
allHosts.Add(filtered...)

for _, h := range filtered {
for _, t := range u.Tables {
for _, h := range filtered {
ranges[newHostKsTable(h, u.Keyspace, t)] += len(rep.Ranges)
}
rangesCnt += len(rep.Ranges)
}
rangesCnt += len(rep.Ranges)
}

// Update table plan
var tables []tablePlan
for _, t := range u.Tables {
tables = append(tables, tablePlan{
Table: t,
ReplicaSetCnt: replicaSetCnt,
RangesCnt: rangesCnt,
})
}

ks = append(ks, keyspacePlan{
Keyspace: u.Keyspace,
Tables: tables,
})
if len(tables) > 0 {
ks = append(ks, keyspacePlan{
Keyspace: u.Keyspace,
Tables: tables,
})
}
}

if len(ks) == 0 {
Expand Down

0 comments on commit 5ea2a5a

Please sign in to comment.