Skip to content

Commit

Permalink
Remove global variable of HeapAllocator
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Haudum <[email protected]>
  • Loading branch information
chaudum committed May 30, 2024
1 parent a95eac2 commit a2cbf40
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions pkg/bloomcompactor/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func dummyBloomGen(t *testing.T, opts v1.BlockOptions, store v1.Iterator[*v1.Ser
for i, b := range blocks {
bqs = append(bqs, &bloomshipper.CloseableBlockQuerier{
BlockRef: refs[i],
BlockQuerier: v1.NewBlockQuerier(b, v1.HeapAllocator, v1.DefaultMaxPageSize),
BlockQuerier: v1.NewBlockQuerier(b, &v1.SimpleHeapAllocator{}, v1.DefaultMaxPageSize),
})
}

Expand Down Expand Up @@ -152,7 +152,7 @@ func TestSimpleBloomGenerator(t *testing.T) {
expectedRefs := v1.PointerSlice(data)
outputRefs := make([]*v1.SeriesWithBloom, 0, len(data))
for _, block := range outputBlocks {
bq := v1.NewBlockQuerier(block, v1.HeapAllocator, v1.DefaultMaxPageSize)
bq := v1.NewBlockQuerier(block, &v1.SimpleHeapAllocator{}, v1.DefaultMaxPageSize)
for bq.Next() {
outputRefs = append(outputRefs, bq.At())
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/bloomgateway/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func createBlocks(t *testing.T, tenant string, n int, from, through model.Time,
// }
// }
querier := &bloomshipper.CloseableBlockQuerier{
BlockQuerier: v1.NewBlockQuerier(block, v1.HeapAllocator, v1.DefaultMaxPageSize),
BlockQuerier: v1.NewBlockQuerier(block, &v1.SimpleHeapAllocator{}, v1.DefaultMaxPageSize),
BlockRef: blockRef,
}
queriers = append(queriers, querier)
Expand Down
2 changes: 1 addition & 1 deletion pkg/loki/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ func (t *Loki) initBloomStore() (services.Service, error) {
// Set global BloomPageAllocator variable
switch bsCfg.MemoryManagement.BloomPageAllocationType {
case "simple":
bloomshipper.BloomPageAllocator = v1.HeapAllocator
bloomshipper.BloomPageAllocator = &v1.SimpleHeapAllocator{}
case "dynamic":
bloomshipper.BloomPageAllocator = v1.BloomPagePool
case "fixed":
Expand Down
10 changes: 4 additions & 6 deletions pkg/storage/bloom/v1/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ var (
return make([]byte, size)
}),
}

HeapAllocator = &simpleHeapAllocator{}
)

// Allocator handles byte slices for bloom queriers.
Expand All @@ -62,14 +60,14 @@ type Allocator interface {
Put([]byte) bool
}

// simpleHeapAllocator allocates a new byte slice every time and does not re-cycle buffers.
type simpleHeapAllocator struct{}
// SimpleHeapAllocator allocates a new byte slice every time and does not re-cycle buffers.
type SimpleHeapAllocator struct{}

func (a *simpleHeapAllocator) Get(size int) ([]byte, error) {
func (a *SimpleHeapAllocator) Get(size int) ([]byte, error) {
return make([]byte, size), nil
}

func (a *simpleHeapAllocator) Put([]byte) bool {
func (a *SimpleHeapAllocator) Put([]byte) bool {
return true
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/stores/shipper/bloomshipper/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (b BlockDirectory) BlockQuerier(
if usePool && BloomPageAllocator != nil {
alloc = BloomPageAllocator
} else {
alloc = v1.HeapAllocator
alloc = &v1.SimpleHeapAllocator{}
}

bq := v1.NewBlockQuerier(b.Block(metrics), alloc, maxPageSize)
Expand Down

0 comments on commit a2cbf40

Please sign in to comment.