storecache

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2020 License: Apache-2.0 Imports: 21 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultInMemoryIndexCacheConfig = InMemoryIndexCacheConfig{
		MaxSize:     250 * 1024 * 1024,
		MaxItemSize: 125 * 1024 * 1024,
	}
)

Functions

This section is empty.

Types

type Bytes added in v0.10.0

type Bytes uint64

Bytes is a data type which supports yaml serialization/deserialization with units.

func (*Bytes) MarshalYAML added in v0.10.0

func (b *Bytes) MarshalYAML() (interface{}, error)

func (*Bytes) UnmarshalYAML added in v0.10.0

func (b *Bytes) UnmarshalYAML(unmarshal func(interface{}) error) error

type InMemoryIndexCache added in v0.10.0

type InMemoryIndexCache struct {
	// contains filtered or unexported fields
}

func NewInMemoryIndexCache added in v0.10.0

func NewInMemoryIndexCache(logger log.Logger, reg prometheus.Registerer, conf []byte) (*InMemoryIndexCache, error)

NewInMemoryIndexCache creates a new thread-safe LRU cache for index entries and ensures the total cache size approximately does not exceed maxBytes.

func NewInMemoryIndexCacheWithConfig added in v0.10.0

func NewInMemoryIndexCacheWithConfig(logger log.Logger, reg prometheus.Registerer, config InMemoryIndexCacheConfig) (*InMemoryIndexCache, error)

NewInMemoryIndexCacheWithConfig creates a new thread-safe LRU cache for index entries and ensures the total cache size approximately does not exceed maxBytes.

func (*InMemoryIndexCache) FetchMultiPostings added in v0.10.0

func (c *InMemoryIndexCache) FetchMultiPostings(_ context.Context, blockID ulid.ULID, keys []labels.Label) (hits map[labels.Label][]byte, misses []labels.Label)

FetchMultiPostings fetches multiple postings - each identified by a label - and returns a map containing cache hits, along with a list of missing keys.

func (*InMemoryIndexCache) FetchMultiSeries added in v0.10.0

func (c *InMemoryIndexCache) FetchMultiSeries(_ context.Context, blockID ulid.ULID, ids []uint64) (hits map[uint64][]byte, misses []uint64)

FetchMultiSeries fetches multiple series - each identified by ID - from the cache and returns a map containing cache hits, along with a list of missing IDs.

func (*InMemoryIndexCache) StorePostings added in v0.10.0

func (c *InMemoryIndexCache) StorePostings(_ context.Context, blockID ulid.ULID, l labels.Label, v []byte)

StorePostings sets the postings identified by the ulid and label to the value v, if the postings already exists in the cache it is not mutated.

func (*InMemoryIndexCache) StoreSeries added in v0.10.0

func (c *InMemoryIndexCache) StoreSeries(_ context.Context, blockID ulid.ULID, id uint64, v []byte)

StoreSeries sets the series identified by the ulid and id to the value v, if the series already exists in the cache it is not mutated.

type InMemoryIndexCacheConfig added in v0.10.0

type InMemoryIndexCacheConfig struct {
	// MaxSize represents overall maximum number of bytes cache can contain.
	MaxSize Bytes `yaml:"max_size"`
	// MaxItemSize represents maximum size of single item.
	MaxItemSize Bytes `yaml:"max_item_size"`
}

InMemoryIndexCacheConfig holds the in-memory index cache config.

type IndexCache

type IndexCache interface {
	// StorePostings stores postings for a single series.
	StorePostings(ctx context.Context, blockID ulid.ULID, l labels.Label, v []byte)

	// FetchMultiPostings fetches multiple postings - each identified by a label -
	// and returns a map containing cache hits, along with a list of missing keys.
	FetchMultiPostings(ctx context.Context, blockID ulid.ULID, keys []labels.Label) (hits map[labels.Label][]byte, misses []labels.Label)

	// StoreSeries stores a single series.
	StoreSeries(ctx context.Context, blockID ulid.ULID, id uint64, v []byte)

	// FetchMultiSeries fetches multiple series - each identified by ID - from the cache
	// and returns a map containing cache hits, along with a list of missing IDs.
	FetchMultiSeries(ctx context.Context, blockID ulid.ULID, ids []uint64) (hits map[uint64][]byte, misses []uint64)
}

IndexCache is the interface exported by index cache backends.

func NewIndexCache

func NewIndexCache(logger log.Logger, confContentYaml []byte, reg prometheus.Registerer) (IndexCache, error)

NewIndexCache initializes and returns new index cache.

type IndexCacheConfig added in v0.10.0

type IndexCacheConfig struct {
	Type   IndexCacheProvider `yaml:"type"`
	Config interface{}        `yaml:"config"`
}

IndexCacheConfig specifies the index cache config.

type IndexCacheProvider added in v0.10.0

type IndexCacheProvider string
const (
	INMEMORY  IndexCacheProvider = "IN-MEMORY"
	MEMCACHED IndexCacheProvider = "MEMCACHED"
)

type MemcachedIndexCache added in v0.10.0

type MemcachedIndexCache struct {
	// contains filtered or unexported fields
}

MemcachedIndexCache is a memcached-based index cache.

func NewMemcachedIndexCache added in v0.10.0

func NewMemcachedIndexCache(logger log.Logger, memcached cacheutil.MemcachedClient, reg prometheus.Registerer) (*MemcachedIndexCache, error)

NewMemcachedIndexCache makes a new MemcachedIndexCache.

func (*MemcachedIndexCache) FetchMultiPostings added in v0.10.0

func (c *MemcachedIndexCache) FetchMultiPostings(ctx context.Context, blockID ulid.ULID, lbls []labels.Label) (hits map[labels.Label][]byte, misses []labels.Label)

FetchMultiPostings fetches multiple postings - each identified by a label - and returns a map containing cache hits, along with a list of missing keys. In case of error, it logs and return an empty cache hits map.

func (*MemcachedIndexCache) FetchMultiSeries added in v0.10.0

func (c *MemcachedIndexCache) FetchMultiSeries(ctx context.Context, blockID ulid.ULID, ids []uint64) (hits map[uint64][]byte, misses []uint64)

FetchMultiSeries fetches multiple series - each identified by ID - from the cache and returns a map containing cache hits, along with a list of missing IDs. In case of error, it logs and return an empty cache hits map.

func (*MemcachedIndexCache) StorePostings added in v0.10.0

func (c *MemcachedIndexCache) StorePostings(ctx context.Context, blockID ulid.ULID, l labels.Label, v []byte)

StorePostings sets the postings identified by the ulid and label to the value v. The function enqueues the request and returns immediately: the entry will be asynchronously stored in the cache.

func (*MemcachedIndexCache) StoreSeries added in v0.10.0

func (c *MemcachedIndexCache) StoreSeries(ctx context.Context, blockID ulid.ULID, id uint64, v []byte)

StoreSeries sets the series identified by the ulid and id to the value v. The function enqueues the request and returns immediately: the entry will be asynchronously stored in the cache.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL