cache

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2020 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidRange = errors.New("CCache: invalid range: from must be less than to")
)

Functions

This section is empty.

Types

type CCSearchResult

type CCSearchResult struct {
	Type ResultType

	// if Type is not Hit, then the following store query
	// will need to use this from value to fill in the missing data
	From uint32

	// if Type is not Hit, then the following store query
	// will need to use this until value to fill in the missing data
	Until uint32

	// if the cache contained the chunk containing the original "from" ts then
	// this slice will hold it as the first element, plus all the subsequent
	// cached chunks. If Type is Hit then all chunks are in this slice.
	Start []chunk.IterGen

	// if type is not Hit and the original "until" ts is in a cached chunk
	// then this slice will hold it as the first element, plus all the previous
	// ones in reverse order (because the search is seeking in reverse)
	End []chunk.IterGen
}

type CCache

type CCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewCCache

func NewCCache() *CCache

NewCCache creates a new chunk cache. When cache is disabled, this will return nil but the caller doesn't have to worry about this and can call methods as usual on a nil cache

func (*CCache) Add

func (c *CCache) Add(metric schema.AMKey, prev uint32, itergen chunk.IterGen)

func (*CCache) AddIfHot

func (c *CCache) AddIfHot(metric schema.AMKey, prev uint32, itergen chunk.IterGen)

adds the given chunk to the cache, but only if the metric is sufficiently hot

func (*CCache) AddRange

func (c *CCache) AddRange(metric schema.AMKey, prev uint32, itergens []chunk.IterGen)

func (*CCache) DelMetric

func (c *CCache) DelMetric(rawMetric schema.MKey) (int, int)

takes a raw key and deletes all archives associated with it from cache

func (*CCache) Reset

func (cc *CCache) Reset() (int, int)

func (*CCache) Search

func (c *CCache) Search(ctx context.Context, metric schema.AMKey, from, until uint32) (*CCSearchResult, error)

Search looks for the requested metric and returns a complete-as-possible CCSearchResult from is inclusive, until is exclusive

func (*CCache) SetTracer

func (c *CCache) SetTracer(t opentracing.Tracer)

func (*CCache) Stop

func (c *CCache) Stop()

type CCacheChunk

type CCacheChunk struct {
	// the timestamp of this cache chunk
	Ts uint32

	// the previous chunk. if the previous chunk isn't cached this is 0
	Prev uint32

	// the next chunk. if the next chunk isn't cached this is 0
	Next uint32

	// an iterator generator to iterate over the chunk's data
	Itgen chunk.IterGen
}

type CCacheMetric

type CCacheMetric struct {
	sync.RWMutex

	MKey schema.MKey
	// contains filtered or unexported fields
}

CCacheMetric caches data chunks

func NewCCacheMetric

func NewCCacheMetric(mkey schema.MKey) *CCacheMetric

NewCCacheMetric creates a CCacheMetric

func (*CCacheMetric) Add

func (mc *CCacheMetric) Add(prev uint32, itergen chunk.IterGen)

Add adds a chunk to the cache

func (*CCacheMetric) AddRange

func (mc *CCacheMetric) AddRange(prev uint32, itergens []chunk.IterGen)

AddRange adds a range (sequence) of chunks. Note the following requirements: the sequence should be in ascending timestamp order the sequence should be complete (no gaps)

func (*CCacheMetric) Del

func (mc *CCacheMetric) Del(ts uint32) int

Del deletes chunks for the given timestamp

func (*CCacheMetric) Search

func (mc *CCacheMetric) Search(ctx context.Context, metric schema.AMKey, res *CCSearchResult, from, until uint32)

Search searches the CCacheMetric's data and returns a complete-as-possible CCSearchResult

we first look for the chunks where the "from" and "until" ts are in. then we seek from the "from" towards "until" and add as many cunks as possible to the result, if this did not result in all chunks necessary to serve the request we do the same in the reverse order from "until" to "from" if the first seek in chronological direction already ends up with all the chunks we need to serve the request, the second one can be skipped.

EXAMPLE: from ts: | until ts: | cache: |---|---|---| | | | | |---|---|---|---|---|---| chunks returned: |---| |---|---|---|

type Cache

type Cache interface {
	Add(metric schema.AMKey, prev uint32, itergen chunk.IterGen)
	AddIfHot(metric schema.AMKey, prev uint32, itergen chunk.IterGen)
	AddRange(metric schema.AMKey, prev uint32, itergens []chunk.IterGen)
	Stop()
	Search(ctx context.Context, metric schema.AMKey, from, until uint32) (*CCSearchResult, error)
	DelMetric(rawMetric schema.MKey) (int, int)
	Reset() (int, int)
}

type CachePusher

type CachePusher interface {
	AddIfHot(metric schema.AMKey, prev uint32, itergen chunk.IterGen)
}

type MockCache

type MockCache struct {
	sync.Mutex
	AddCount          int
	AddIfHotCount     int
	AddIfHotCb        func()
	StopCount         int
	SearchCount       int
	DelMetricArchives int
	DelMetricSeries   int
	DelMetricKeys     []schema.MKey
	ResetCalls        int
}

func NewMockCache

func NewMockCache() *MockCache

func (*MockCache) Add

func (mc *MockCache) Add(metric schema.AMKey, prev uint32, itergen chunk.IterGen)

func (*MockCache) AddIfHot

func (mc *MockCache) AddIfHot(metric schema.AMKey, prev uint32, itergen chunk.IterGen)

func (*MockCache) AddRange

func (mc *MockCache) AddRange(metric schema.AMKey, prev uint32, itergens []chunk.IterGen)

func (*MockCache) DelMetric

func (mc *MockCache) DelMetric(rawMetric schema.MKey) (int, int)

func (*MockCache) Reset

func (mc *MockCache) Reset() (int, int)

func (*MockCache) Search

func (mc *MockCache) Search(ctx context.Context, metric schema.AMKey, from uint32, until uint32) (*CCSearchResult, error)

func (*MockCache) Stop

func (mc *MockCache) Stop()

type ResultType added in v0.13.0

type ResultType uint8
const (
	Miss       ResultType = iota // no data for this request in cache
	HitPartial                   // request partially served from cache
	Hit                          // whole request served from cache
)

func (ResultType) String added in v0.13.0

func (i ResultType) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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