github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/pkg/storage/stores/tsdb/pool.go (about)

     1  package tsdb
     2  
     3  import (
     4  	"sync"
     5  
     6  	"github.com/grafana/loki/pkg/storage/stores/tsdb/index"
     7  )
     8  
     9  var (
    10  	ChunkMetasPool = &index.ChunkMetasPool // re-exporting
    11  	SeriesPool     PoolSeries
    12  	ChunkRefsPool  PoolChunkRefs
    13  )
    14  
    15  type PoolSeries struct {
    16  	pool sync.Pool
    17  }
    18  
    19  func (p *PoolSeries) Get() []Series {
    20  	if xs := p.pool.Get(); xs != nil {
    21  		return xs.([]Series)
    22  	}
    23  	return make([]Series, 0, 1<<10)
    24  }
    25  
    26  func (p *PoolSeries) Put(xs []Series) {
    27  	xs = xs[:0]
    28  	//nolint:staticcheck
    29  	p.pool.Put(xs)
    30  }
    31  
    32  type PoolChunkRefs struct {
    33  	pool sync.Pool
    34  }
    35  
    36  func (p *PoolChunkRefs) Get() []ChunkRef {
    37  	if xs := p.pool.Get(); xs != nil {
    38  		return xs.([]ChunkRef)
    39  	}
    40  	return make([]ChunkRef, 0, 1<<10)
    41  }
    42  
    43  func (p *PoolChunkRefs) Put(xs []ChunkRef) {
    44  	xs = xs[:0]
    45  	//nolint:staticcheck
    46  	p.pool.Put(xs)
    47  }