Skip to content

Commit

Permalink
Use int division instead of float
Browse files Browse the repository at this point in the history
Signed-off-by: 🌲 Harry 🌊 John 🏔 <[email protected]>
  • Loading branch information
harry671003 committed Sep 22, 2023
1 parent 8731f16 commit 586a6a8
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions pkg/block/indexheader/binary_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ const (
MagicIndex = 0xBAAAD792

postingLengthFieldSize = 4
partitionSize = 64 * 1024 * 1024 // 64 MB

// partitionSize is used for splitting range reads for index-header.
partitionSize = 64 * 1024 * 1024 // 64 MiB
)

var NotFoundRange = index.Range{Start: -1, End: -1}
Expand Down Expand Up @@ -246,16 +248,18 @@ func (r *chunkedIndexReader) CopyPostingsOffsets(w io.Writer, buf []byte) (err e
func (r *chunkedIndexReader) getRangePartitioned(ctx context.Context, name string, off int64, length int64) (io.ReadCloser, error) {
g, qctx := errgroup.WithContext(ctx)

numParts := int64(math.Ceil(float64(length) / float64(r.partSize)))
numParts := length / r.partSize
if length%r.partSize > 0 {
// A partial partition is remaining
numParts += 1
}

parts := make([]io.ReadCloser, numParts)

i := 0
for o := off; o < off+length; o += r.partSize {
l := r.partSize
if o+l > off+length {
// l = 1024
//
// expected = (i * partSize )
l = length - (int64(i) * r.partSize)
}

Expand Down

0 comments on commit 586a6a8

Please sign in to comment.