Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

break up requests for block refs #334

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions carstore/bs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,29 @@ func (cs *CarStore) GetCompactionTargets(ctx context.Context) ([]CompactionTarge
return targets, nil
}

func (cs *CarStore) getBlockRefsForShards(ctx context.Context, shardIds []uint) ([]blockRef, error) {
ctx, span := otel.Tracer("carstore").Start(ctx, "getBlockRefsForShards")
defer span.End()

chunkSize := 10000
out := make([]blockRef, 0, len(shardIds))
for i := 0; i < len(shardIds); i += chunkSize {
sl := shardIds[i:]
if len(sl) > chunkSize {
sl = sl[:chunkSize]
}

var brefs []blockRef
if err := cs.meta.Raw(`select * from block_refs where shard in (?)`, sl).Scan(&brefs).Error; err != nil {
return nil, err
}

out = append(out, brefs...)
}

return out, nil
}

type CompactionStats struct {
StartShards int `json:"startShards"`
NewShards int `json:"newShards"`
Expand Down Expand Up @@ -1178,9 +1201,9 @@ func (cs *CarStore) CompactUserShards(ctx context.Context, user models.Uid) (*Co
shardsById[s.ID] = s
}

var brefs []blockRef
if err := cs.meta.WithContext(ctx).Raw(`select shard, cid from block_refs where shard in (?)`, shardIds).Scan(&brefs).Error; err != nil {
return nil, err
brefs, err := cs.getBlockRefsForShards(ctx, shardIds)
if err != nil {
return nil, fmt.Errorf("getting block refs failed: %w", err)
}

var staleRefs []staleRef
Expand Down
Loading