Skip to content

Commit

Permalink
objstorage: fix readaheadState initialization
Browse files Browse the repository at this point in the history
When I extracted out the readahead logic from the sstable Reader, I
accidentally omitted some initialization code - setting
`readaheadState.size` to `initialReadaheadSize`. Fixing.
  • Loading branch information
RaduBerinde committed May 16, 2023
1 parent 06d0888 commit 8143ffb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
6 changes: 6 additions & 0 deletions objstorage/objstorageprovider/readahead.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ type readaheadState struct {
limit int64
}

func makeReadaheadState() readaheadState {
return readaheadState{
size: initialReadaheadSize,
}
}

func (rs *readaheadState) recordCacheHit(offset, blockLength int64) {
currentReadEnd := offset + blockLength
if rs.numReads >= minFileReadsForReadahead {
Expand Down
2 changes: 1 addition & 1 deletion objstorage/objstorageprovider/readahead_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

func TestMaybeReadahead(t *testing.T) {
var rs readaheadState
rs := makeReadaheadState()
datadriven.RunTest(t, "testdata/readahead", func(t *testing.T, d *datadriven.TestData) string {
cacheHit := false
switch d.Cmd {
Expand Down
3 changes: 0 additions & 3 deletions objstorage/objstorageprovider/testdata/readahead
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
reset
----

read
2048, 16
----
Expand Down
1 change: 1 addition & 0 deletions objstorage/objstorageprovider/vfs_readable.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func (r *fileReadable) Size() int64 {
func (r *fileReadable) NewReadHandle(_ context.Context) objstorage.ReadHandle {
rh := readHandlePool.Get().(*vfsReadHandle)
rh.r = r
rh.rs = makeReadaheadState()
return rh
}

Expand Down

0 comments on commit 8143ffb

Please sign in to comment.