Skip to content

Commit 63e556f

Browse files
committed
fix bug on the reuse
Signed-off-by: Alan Protasio <[email protected]>
1 parent 02729b1 commit 63e556f

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

pkg/cortexpb/slicesPool.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,9 @@ func (sp *byteSlicePools) getSlice(size int) *[]byte {
5252
func (sp *byteSlicePools) reuseSlice(s *[]byte) {
5353
index := int(math.Floor(math.Log2(float64(cap(*s))))) - minPoolSizePower
5454

55-
if index >= len(sp.pools) {
55+
if index >= len(sp.pools) || index < 0 {
5656
return
5757
}
5858

59-
if index < 0 {
60-
index = 0
61-
}
62-
6359
sp.pools[index].Put(s)
6460
}

pkg/cortexpb/slicesPool_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,12 @@ func TestFuzzyByteSlicePools(t *testing.T) {
1919
sut.reuseSlice(s)
2020
}
2121
}
22+
23+
func TestReturnSliceSmallerThanMin(t *testing.T) {
24+
sut := newSlicePool(20)
25+
size := 3
26+
buff := make([]byte, 0, size)
27+
sut.reuseSlice(&buff)
28+
buff2 := sut.getSlice(size * 2)
29+
assert.Equal(t, len(*buff2), size*2)
30+
}

pkg/cortexpb/timeseries.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ func ReuseWriteRequest(req *PreallocWriteRequest) {
9898
bytePool.reuseSlice(req.data)
9999
req.data = nil
100100
}
101-
101+
req.Source = 0
102+
req.Metadata = nil
103+
req.Timeseries = nil
102104
writeRequestPool.Put(req)
103105
}
104106

0 commit comments

Comments
 (0)