CreateBlockBoundaries splits the range of blockIDs into queryShards parts
(queryShards int)
| 7 | |
| 8 | // CreateBlockBoundaries splits the range of blockIDs into queryShards parts |
| 9 | func CreateBlockBoundaries(queryShards int) [][]byte { |
| 10 | if queryShards == 0 { |
| 11 | return nil |
| 12 | } |
| 13 | |
| 14 | // create sharded queries |
| 15 | blockBoundaries := make([][]byte, queryShards+1) |
| 16 | for i := 0; i < queryShards+1; i++ { |
| 17 | blockBoundaries[i] = make([]byte, 16) |
| 18 | } |
| 19 | |
| 20 | // bucketSz is the min size for the bucket |
| 21 | bucketSz := (math.MaxUint64 / uint64(queryShards)) |
| 22 | // numLarger is the number of buckets that have to be bumped by 1 |
| 23 | numLarger := (math.MaxUint64 % uint64(queryShards)) |
| 24 | boundary := uint64(0) |
| 25 | for i := 0; i < queryShards; i++ { |
| 26 | binary.BigEndian.PutUint64(blockBoundaries[i][:8], boundary) |
| 27 | binary.BigEndian.PutUint64(blockBoundaries[i][8:], 0) |
| 28 | |
| 29 | boundary += bucketSz |
| 30 | if numLarger != 0 { |
| 31 | numLarger-- |
| 32 | boundary++ |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | binary.BigEndian.PutUint64(blockBoundaries[queryShards][:8], math.MaxUint64) |
| 37 | binary.BigEndian.PutUint64(blockBoundaries[queryShards][8:], math.MaxUint64) |
| 38 | |
| 39 | return blockBoundaries |
| 40 | } |
no outgoing calls