Skip to content

Commit

Permalink
fix chunksize computation (#1376)
Browse files Browse the repository at this point in the history
  • Loading branch information
iskakaushik authored Feb 25, 2024
1 parent 91bc2e9 commit ad5c137
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 7 additions & 0 deletions flow/shared/math.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package shared

import "golang.org/x/exp/constraints"

func DivCeil[T constraints.Integer](x, y T) T {
return (x + y - 1) / y
}
8 changes: 2 additions & 6 deletions flow/workflows/qrep_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (q *QRepFlowExecution) GetPartitions(
return nil, fmt.Errorf("failed to fetch partitions to replicate: %w", err)
}

q.logger.Info("partitions to replicate - ", len(partitions.Partitions))
q.logger.Info("partitions to replicate - ", slog.Int("num_partitions", len(partitions.Partitions)))
return partitions, nil
}

Expand Down Expand Up @@ -242,11 +242,7 @@ func (q *QRepFlowExecution) processPartitions(
maxParallelWorkers int,
partitions []*protos.QRepPartition,
) error {
chunkSize := len(partitions) / maxParallelWorkers
if chunkSize == 0 {
chunkSize = 1
}

chunkSize := shared.DivCeil(len(partitions), maxParallelWorkers)
batches := make([][]*protos.QRepPartition, 0, len(partitions)/chunkSize+1)
for i := 0; i < len(partitions); i += chunkSize {
end := min(i+chunkSize, len(partitions))
Expand Down

0 comments on commit ad5c137

Please sign in to comment.