Skip to content

Commit

Permalink
refactor(repair): remove idx dependency from TableDiskSizeReport
Browse files Browse the repository at this point in the history
This change increases readability.
  • Loading branch information
Michal-Leszczynski committed Mar 13, 2024
1 parent f48e64b commit 15f4226
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
15 changes: 12 additions & 3 deletions pkg/scyllaclient/client_scylla.go
Original file line number Diff line number Diff line change
Expand Up @@ -875,8 +875,14 @@ func (t HostKeyspaceTables) Hosts() []string {
return s.List()
}

// SizeReport extends HostKeyspaceTable with Size information.
type SizeReport struct {
HostKeyspaceTable
Size int64
}

// TableDiskSizeReport returns total on disk size of tables in bytes.
func (c *Client) TableDiskSizeReport(ctx context.Context, hostKeyspaceTables HostKeyspaceTables) ([]int64, error) {
func (c *Client) TableDiskSizeReport(ctx context.Context, hostKeyspaceTables HostKeyspaceTables) ([]SizeReport, error) {
// Get shard count of a first node to estimate parallelism limit
shards, err := c.ShardCount(ctx, "")
if err != nil {
Expand All @@ -885,7 +891,7 @@ func (c *Client) TableDiskSizeReport(ctx context.Context, hostKeyspaceTables Hos

var (
limit = len(hostKeyspaceTables.Hosts()) * int(shards)
report = make([]int64, len(hostKeyspaceTables))
report = make([]SizeReport, len(hostKeyspaceTables))
)

f := func(i int) error {
Expand All @@ -902,7 +908,10 @@ func (c *Client) TableDiskSizeReport(ctx context.Context, hostKeyspaceTables Hos
"size", size,
)

report[i] = size
report[i] = SizeReport{
HostKeyspaceTable: v,
Size: size,
}
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/service/backup/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ func (s *Service) GetTargetSize(ctx context.Context, clusterID uuid.UUID, target
}

var total int64
for _, size := range report {
total += size
for _, sr := range report {
total += sr.Size
}

return total, err
Expand Down
14 changes: 7 additions & 7 deletions pkg/service/repair/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,14 @@ func (p *plan) FillSize(ctx context.Context, client *scyllaclient.Client, smallT
ksSize := make(map[string]int64)
tableSize := make(map[string]int64)
p.HostTableSize = make(map[scyllaclient.HostKeyspaceTable]int64, len(hkts))
for i, size := range report {
ksSize[hkts[i].Keyspace] += size
tableSize[hkts[i].Keyspace+"."+hkts[i].Table] += size
for _, sr := range report {
ksSize[sr.Keyspace] += sr.Size
tableSize[sr.Keyspace+"."+sr.Table] += sr.Size
p.HostTableSize[scyllaclient.HostKeyspaceTable{
Host: hkts[i].Host,
Keyspace: hkts[i].Keyspace,
Table: hkts[i].Table,
}] = size
Host: sr.Host,
Keyspace: sr.Keyspace,
Table: sr.Table,
}] = sr.Size
}

for i, kp := range p.Keyspaces {
Expand Down

0 comments on commit 15f4226

Please sign in to comment.