indexcache

package
v0.0.0-...-7fa48db Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Overview

SPDX-License-Identifier: AGPL-3.0-only Provenance-includes-location: https://github.com/thanos-io/thanos/blob/main/pkg/store/cache/inmemory.go Provenance-includes-license: Apache-2.0 Provenance-includes-copyright: The Thanos Authors.

Index

Constants

This section is empty.

Variables

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

Functions

func BlockTTL

func BlockTTL(meta *block.Meta) time.Duration

BlockTTL determines an appropriate TTL for cache entries related to a particular block based on metadata about the block. Use a shorter TTL for temporary blocks that will be compacted and deleted soon and a longer TTL for larger blocks that won't be deleted.

Types

type BytesResult

type BytesResult interface {
	// Next should return a byte slice if there was a cache hit for the current key; otherwise Next should return nil.
	// Next should return false when there are no more keys in the result.
	Next() ([]byte, bool)

	// Remaining should return the number of keys left in the result.
	// There may or may not be an item for each key.
	Remaining() int

	// Size should return the size in bytes of the result.
	Size() int
}

type InMemoryIndexCache

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

func NewInMemoryIndexCache

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

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) FetchExpandedPostings

func (c *InMemoryIndexCache) FetchExpandedPostings(_ context.Context, userID string, blockID ulid.ULID, key LabelMatchersKey, postingsSelectionStrategy string) ([]byte, bool)

FetchExpandedPostings fetches the encoded result of ExpandedPostings for specified matchers identified by the provided LabelMatchersKey.

func (*InMemoryIndexCache) FetchLabelNames

func (c *InMemoryIndexCache) FetchLabelNames(_ context.Context, userID string, blockID ulid.ULID, matchersKey LabelMatchersKey) ([]byte, bool)

FetchLabelNames fetches the result of a LabelNames() call.

func (*InMemoryIndexCache) FetchLabelValues

func (c *InMemoryIndexCache) FetchLabelValues(_ context.Context, userID string, blockID ulid.ULID, labelName string, matchersKey LabelMatchersKey) ([]byte, bool)

FetchLabelValues fetches the result of a LabelValues() call.

func (*InMemoryIndexCache) FetchMultiPostings

func (c *InMemoryIndexCache) FetchMultiPostings(_ context.Context, userID string, blockID ulid.ULID, keys []labels.Label) BytesResult

FetchMultiPostings fetches multiple postings - each identified by a label.

func (*InMemoryIndexCache) FetchMultiSeriesForRefs

func (c *InMemoryIndexCache) FetchMultiSeriesForRefs(_ context.Context, userID string, blockID ulid.ULID, ids []storage.SeriesRef) (hits map[storage.SeriesRef][]byte, misses []storage.SeriesRef)

FetchMultiSeriesForRefs 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) FetchSeriesForPostings

func (c *InMemoryIndexCache) FetchSeriesForPostings(_ context.Context, userID string, blockID ulid.ULID, shard *sharding.ShardSelector, postingsKey PostingsKey) ([]byte, bool)

FetchSeriesForPostings fetches a series set for the provided postings.

func (*InMemoryIndexCache) StoreExpandedPostings

func (c *InMemoryIndexCache) StoreExpandedPostings(userID string, blockID ulid.ULID, key LabelMatchersKey, postingsSelectionStrategy string, v []byte)

StoreExpandedPostings stores the encoded result of ExpandedPostings for specified matchers identified by the provided LabelMatchersKey.

func (*InMemoryIndexCache) StoreLabelNames

func (c *InMemoryIndexCache) StoreLabelNames(userID string, blockID ulid.ULID, matchersKey LabelMatchersKey, v []byte)

StoreLabelNames stores the result of a LabelNames() call.

func (*InMemoryIndexCache) StoreLabelValues

func (c *InMemoryIndexCache) StoreLabelValues(userID string, blockID ulid.ULID, labelName string, matchersKey LabelMatchersKey, v []byte)

StoreLabelValues stores the result of a LabelValues() call.

func (*InMemoryIndexCache) StorePostings

func (c *InMemoryIndexCache) StorePostings(userID string, blockID ulid.ULID, l labels.Label, v []byte, _ time.Duration)

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) StoreSeriesForPostings

func (c *InMemoryIndexCache) StoreSeriesForPostings(userID string, blockID ulid.ULID, shard *sharding.ShardSelector, postingsKey PostingsKey, v []byte)

StoreSeriesForPostings stores a series set for the provided postings.

func (*InMemoryIndexCache) StoreSeriesForRef

func (c *InMemoryIndexCache) StoreSeriesForRef(userID string, blockID ulid.ULID, id storage.SeriesRef, v []byte, _ time.Duration)

StoreSeriesForRef 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

type InMemoryIndexCacheConfig struct {
	// MaxSize represents overall maximum number of bytes cache can contain.
	MaxSize flagext.Bytes `yaml:"max_size"`
	// MaxItemSize represents maximum size of single item.
	MaxItemSize flagext.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(userID string, blockID ulid.ULID, l labels.Label, v []byte, ttl time.Duration)

	// FetchMultiPostings fetches multiple postings - each identified by a label.
	// The returned result should contain one item for each requested key.
	FetchMultiPostings(ctx context.Context, userID string, blockID ulid.ULID, keys []labels.Label) (result BytesResult)

	// StoreSeriesForRef stores a single series.
	StoreSeriesForRef(userID string, blockID ulid.ULID, id storage.SeriesRef, v []byte, ttl time.Duration)

	// FetchMultiSeriesForRefs fetches multiple series - each identified by ID - from the cache
	// and returns a map containing cache hits, along with a list of missing IDs.
	// The order of the returned misses should be the same as their relative order in the provided ids.
	FetchMultiSeriesForRefs(ctx context.Context, userID string, blockID ulid.ULID, ids []storage.SeriesRef) (hits map[storage.SeriesRef][]byte, misses []storage.SeriesRef)

	// StoreExpandedPostings stores the result of ExpandedPostings, encoded with an unspecified codec.
	StoreExpandedPostings(userID string, blockID ulid.ULID, key LabelMatchersKey, postingsSelectionStrategy string, v []byte)

	// FetchExpandedPostings fetches the result of ExpandedPostings, encoded with an unspecified codec.
	FetchExpandedPostings(ctx context.Context, userID string, blockID ulid.ULID, key LabelMatchersKey, postingsSelectionStrategy string) ([]byte, bool)

	// StoreSeriesForPostings stores a series set for the provided postings.
	StoreSeriesForPostings(userID string, blockID ulid.ULID, shard *sharding.ShardSelector, postingsKey PostingsKey, v []byte)
	// FetchSeriesForPostings fetches a series set for the provided postings.
	FetchSeriesForPostings(ctx context.Context, userID string, blockID ulid.ULID, shard *sharding.ShardSelector, postingsKey PostingsKey) ([]byte, bool)

	// StoreLabelNames stores the result of a LabelNames() call.
	StoreLabelNames(userID string, blockID ulid.ULID, matchersKey LabelMatchersKey, v []byte)
	// FetchLabelNames fetches the result of a LabelNames() call.
	FetchLabelNames(ctx context.Context, userID string, blockID ulid.ULID, matchersKey LabelMatchersKey) ([]byte, bool)

	// StoreLabelValues stores the result of a LabelValues() call.
	StoreLabelValues(userID string, blockID ulid.ULID, labelName string, matchersKey LabelMatchersKey, v []byte)
	// FetchLabelValues fetches the result of a LabelValues() call.
	FetchLabelValues(ctx context.Context, userID string, blockID ulid.ULID, labelName string, matchersKey LabelMatchersKey) ([]byte, bool)
}

IndexCache is the interface exported by index cache backends.

func NewTracingIndexCache

func NewTracingIndexCache(cache IndexCache, logger log.Logger) IndexCache

type LabelMatchersKey

type LabelMatchersKey string

LabelMatchersKey represents a canonical key for a []*matchers.Matchers slice

func CanonicalLabelMatchersKey

func CanonicalLabelMatchersKey(ms []*labels.Matcher) LabelMatchersKey

CanonicalLabelMatchersKey creates a canonical version of LabelMatchersKey

type MapIterator

type MapIterator[T comparable] struct {
	M    map[T][]byte
	Keys []T
}

func (*MapIterator[T]) Next

func (l *MapIterator[T]) Next() ([]byte, bool)

func (*MapIterator[T]) Remaining

func (l *MapIterator[T]) Remaining() int

func (*MapIterator[T]) Size

func (l *MapIterator[T]) Size() int

type PostingsKey

type PostingsKey string

PostingsKey represents a canonical key for a []storage.SeriesRef slice

func CanonicalPostingsKey

func CanonicalPostingsKey(postings []storage.SeriesRef) PostingsKey

CanonicalPostingsKey creates a canonical version of PostingsKey

type RemoteIndexCache

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

RemoteIndexCache is a memcached or redis based index cache.

func NewRemoteIndexCache

func NewRemoteIndexCache(logger log.Logger, remote cache.Cache, reg prometheus.Registerer) (*RemoteIndexCache, error)

NewRemoteIndexCache makes a new RemoteIndexCache.

func (*RemoteIndexCache) FetchExpandedPostings

func (c *RemoteIndexCache) FetchExpandedPostings(ctx context.Context, userID string, blockID ulid.ULID, lmKey LabelMatchersKey, postingsSelectionStrategy string) ([]byte, bool)

FetchExpandedPostings fetches the encoded result of ExpandedPostings for specified matchers identified by the provided LabelMatchersKey.

func (*RemoteIndexCache) FetchLabelNames

func (c *RemoteIndexCache) FetchLabelNames(ctx context.Context, userID string, blockID ulid.ULID, matchersKey LabelMatchersKey) ([]byte, bool)

FetchLabelNames fetches the result of a LabelNames() call.

func (*RemoteIndexCache) FetchLabelValues

func (c *RemoteIndexCache) FetchLabelValues(ctx context.Context, userID string, blockID ulid.ULID, labelName string, matchersKey LabelMatchersKey) ([]byte, bool)

FetchLabelValues fetches the result of a LabelValues() call.

func (*RemoteIndexCache) FetchMultiPostings

func (c *RemoteIndexCache) FetchMultiPostings(ctx context.Context, userID string, blockID ulid.ULID, lbls []labels.Label) BytesResult

FetchMultiPostings fetches multiple postings - each identified by a label. In case of error, it logs and return an empty result.

func (*RemoteIndexCache) FetchMultiSeriesForRefs

func (c *RemoteIndexCache) FetchMultiSeriesForRefs(ctx context.Context, userID string, blockID ulid.ULID, ids []storage.SeriesRef) (hits map[storage.SeriesRef][]byte, misses []storage.SeriesRef)

FetchMultiSeriesForRefs 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 (*RemoteIndexCache) FetchSeriesForPostings

func (c *RemoteIndexCache) FetchSeriesForPostings(ctx context.Context, userID string, blockID ulid.ULID, shard *sharding.ShardSelector, postingsKey PostingsKey) ([]byte, bool)

FetchSeriesForPostings fetches a series set for the provided postings.

func (*RemoteIndexCache) StoreExpandedPostings

func (c *RemoteIndexCache) StoreExpandedPostings(userID string, blockID ulid.ULID, lmKey LabelMatchersKey, postingsSelectionStrategy string, v []byte)

StoreExpandedPostings stores the encoded result of ExpandedPostings for specified matchers identified by the provided LabelMatchersKey.

func (*RemoteIndexCache) StoreLabelNames

func (c *RemoteIndexCache) StoreLabelNames(userID string, blockID ulid.ULID, matchersKey LabelMatchersKey, v []byte)

StoreLabelNames stores the result of a LabelNames() call.

func (*RemoteIndexCache) StoreLabelValues

func (c *RemoteIndexCache) StoreLabelValues(userID string, blockID ulid.ULID, labelName string, matchersKey LabelMatchersKey, v []byte)

StoreLabelValues stores the result of a LabelValues() call.

func (*RemoteIndexCache) StorePostings

func (c *RemoteIndexCache) StorePostings(userID string, blockID ulid.ULID, l labels.Label, v []byte, ttl time.Duration)

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 (*RemoteIndexCache) StoreSeriesForPostings

func (c *RemoteIndexCache) StoreSeriesForPostings(userID string, blockID ulid.ULID, shard *sharding.ShardSelector, postingsKey PostingsKey, v []byte)

StoreSeriesForPostings stores a series set for the provided postings.

func (*RemoteIndexCache) StoreSeriesForRef

func (c *RemoteIndexCache) StoreSeriesForRef(userID string, blockID ulid.ULID, id storage.SeriesRef, v []byte, ttl time.Duration)

StoreSeriesForRef 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.

type TracingIndexCache

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

func (*TracingIndexCache) FetchExpandedPostings

func (t *TracingIndexCache) FetchExpandedPostings(ctx context.Context, userID string, blockID ulid.ULID, key LabelMatchersKey, postingsSelectionStrategy string) ([]byte, bool)

func (*TracingIndexCache) FetchLabelNames

func (t *TracingIndexCache) FetchLabelNames(ctx context.Context, userID string, blockID ulid.ULID, matchersKey LabelMatchersKey) ([]byte, bool)

func (*TracingIndexCache) FetchLabelValues

func (t *TracingIndexCache) FetchLabelValues(ctx context.Context, userID string, blockID ulid.ULID, labelName string, matchersKey LabelMatchersKey) ([]byte, bool)

func (*TracingIndexCache) FetchMultiPostings

func (t *TracingIndexCache) FetchMultiPostings(ctx context.Context, userID string, blockID ulid.ULID, keys []labels.Label) (hits BytesResult)

func (*TracingIndexCache) FetchMultiSeriesForRefs

func (t *TracingIndexCache) FetchMultiSeriesForRefs(ctx context.Context, userID string, blockID ulid.ULID, ids []storage.SeriesRef) (hits map[storage.SeriesRef][]byte, misses []storage.SeriesRef)

func (*TracingIndexCache) FetchSeriesForPostings

func (t *TracingIndexCache) FetchSeriesForPostings(ctx context.Context, userID string, blockID ulid.ULID, shard *sharding.ShardSelector, postingsKey PostingsKey) ([]byte, bool)

func (*TracingIndexCache) StoreExpandedPostings

func (t *TracingIndexCache) StoreExpandedPostings(userID string, blockID ulid.ULID, key LabelMatchersKey, postingsSelectionStrategy string, v []byte)

func (*TracingIndexCache) StoreLabelNames

func (t *TracingIndexCache) StoreLabelNames(userID string, blockID ulid.ULID, matchersKey LabelMatchersKey, v []byte)

func (*TracingIndexCache) StoreLabelValues

func (t *TracingIndexCache) StoreLabelValues(userID string, blockID ulid.ULID, labelName string, matchersKey LabelMatchersKey, v []byte)

func (*TracingIndexCache) StorePostings

func (t *TracingIndexCache) StorePostings(userID string, blockID ulid.ULID, l labels.Label, v []byte, ttl time.Duration)

func (*TracingIndexCache) StoreSeriesForPostings

func (t *TracingIndexCache) StoreSeriesForPostings(userID string, blockID ulid.ULID, shard *sharding.ShardSelector, postingsKey PostingsKey, v []byte)

func (*TracingIndexCache) StoreSeriesForRef

func (t *TracingIndexCache) StoreSeriesForRef(userID string, blockID ulid.ULID, id storage.SeriesRef, v []byte, ttl time.Duration)

Jump to

Keyboard shortcuts

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