Skip to content

Commit

Permalink
Change expectedBytes to be int64 to be able to run on 64-bit systems
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitar Dimitrov <[email protected]>
  • Loading branch information
dimitarvdimitrov committed Nov 15, 2024
1 parent dcc1397 commit 70fa210
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/storage/ingest/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ func (w fetchWant) UpdateBytesPerRecord(lastFetchBytes int, lastFetchNumberOfRec

// expectedBytes returns how many bytes we'd need to accommodate the range of offsets using estimatedBytesPerRecord.
// They may be more than the kafka protocol supports (> MaxInt32). Use MaxBytes.
func (w fetchWant) expectedBytes() int {
func (w fetchWant) expectedBytes() int64 {
// We over-fetch bytes to reduce the likelihood of under-fetching and having to run another request.
// Based on some testing 65% of under-estimations are by less than 5%. So we account for that.
const overFetchBytesFactor = 1.05
return int(overFetchBytesFactor * float64(int64(w.estimatedBytesPerRecord)*(w.endOffset-w.startOffset)))
return int64(overFetchBytesFactor * float64(int64(w.estimatedBytesPerRecord)*(w.endOffset-w.startOffset)))
}

type fetchResult struct {
Expand Down
3 changes: 1 addition & 2 deletions pkg/storage/ingest/fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1307,8 +1307,7 @@ func TestFetchWant_UpdateBytesPerRecord(t *testing.T) {
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
result := baseWant.UpdateBytesPerRecord(tc.lastFetchBytes, tc.lastFetchRecords)
//1844674407370955961
// endOffset should never change

assert.Equal(t, baseWant.startOffset, result.startOffset, "startOffset should not change")
assert.Equal(t, baseWant.endOffset, result.endOffset, "endOffset should not change")

Expand Down

0 comments on commit 70fa210

Please sign in to comment.