metrictank: github.com/grafana/metrictank/mdata/cache Index | Files | Directories

package cache

import "github.com/grafana/metrictank/mdata/cache"

Index

Package Files

cache_mock.go ccache.go ccache_chunk.go ccache_metric.go if.go resulttype_string.go

Variables

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

type CCSearchResult Uses

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 Uses

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

func NewCCache Uses

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 Uses

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

func (*CCache) AddIfHot Uses

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 Uses

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

func (*CCache) DelMetric Uses

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 Uses

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

func (*CCache) Search Uses

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 Uses

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

func (*CCache) Stop Uses

func (c *CCache) Stop()

type CCacheChunk Uses

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 Uses

type CCacheMetric struct {
    sync.RWMutex

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

CCacheMetric caches data chunks

func NewCCacheMetric Uses

func NewCCacheMetric(mkey schema.MKey) *CCacheMetric

NewCCacheMetric creates a CCacheMetric

func (*CCacheMetric) Add Uses

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

Add adds a chunk to the cache

func (*CCacheMetric) AddRange Uses

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 Uses

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

Del deletes chunks for the given timestamp

func (*CCacheMetric) Search Uses

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 Uses

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 Uses

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

type MockCache Uses

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 Uses

func NewMockCache() *MockCache

func (*MockCache) Add Uses

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

func (*MockCache) AddIfHot Uses

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

func (*MockCache) AddRange Uses

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

func (*MockCache) DelMetric Uses

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

func (*MockCache) Reset Uses

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

func (*MockCache) Search Uses

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

func (*MockCache) Stop Uses

func (mc *MockCache) Stop()

type ResultType Uses

type ResultType uint8

go:generate stringer -type=ResultType

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 Uses

func (i ResultType) String() string

Directories

PathSynopsis
accnt

Package cache imports 14 packages (graph) and is imported by 9 packages. Updated 2019-11-07. Refresh now. Tools for package owners.