query_cache

package
v5.2.0-rc.6 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2023 License: Apache-2.0 Imports: 19 Imported by: 7

Documentation

Overview

Package query_cache is a cache used to store query results.

Each plugin process has a single QueryCache instance which stores the data for all connections

Index

Constants

View Source
const (
	// Key column CacheMatch values
	CacheMatchSubset = "subset"
	CacheMatchExact  = "exact"
)

Variables

This section is empty.

Functions

func IsCacheMiss

func IsCacheMiss(err error) bool

func NewPendingIndexItem

func NewPendingIndexItem(req *CacheRequest) *pendingIndexItem

Types

type CacheData

type CacheData interface {
	proto.Message
	*sdkproto.QueryResult | *sdkproto.IndexBucket
}

type CacheMissError

type CacheMissError struct{}

func (CacheMissError) Error

func (CacheMissError) Error() string

type CacheRequest

type CacheRequest struct {
	CallId         string
	Table          string
	QualMap        map[string]*sdkproto.Quals
	Columns        []string
	Limit          int64
	ConnectionName string
	TtlSeconds     int64
	// contains filtered or unexported fields
}

type CacheStats

type CacheStats struct {
	// keep count of hits and misses
	Hits   int
	Misses int
}

type IndexBucket

type IndexBucket struct {
	Items []*IndexItem
}

IndexBucket contains index items for all cache results for a given table and connection

func IndexBucketfromProto

func IndexBucketfromProto(b *proto.IndexBucket) *IndexBucket

func (*IndexBucket) Append

func (b *IndexBucket) Append(item *IndexItem) *IndexBucket

func (*IndexBucket) AsProto

func (b *IndexBucket) AsProto() *proto.IndexBucket

func (*IndexBucket) Get

func (b *IndexBucket) Get(req *CacheRequest, keyColumns map[string]*proto.KeyColumn) *IndexItem

Get finds an index item which satisfies all columns

type IndexItem

type IndexItem struct {
	Columns       []string
	Key           string
	Limit         int64
	Quals         map[string]*proto.Quals
	InsertionTime time.Time
	PageCount     int64
}

IndexItem stores the columns and cached index for a single cached query result note - this index item it tied to a specific table and set of quals

func NewIndexItem

func NewIndexItem(req *CacheRequest) *IndexItem

func (IndexItem) SatisfiesColumns

func (i IndexItem) SatisfiesColumns(columns []string) bool

SatisfiesColumns returns whether this index item satisfies the given columns used when determining whether this IndexItem satisfies a cache reques

func (IndexItem) SatisfiesLimit

func (i IndexItem) SatisfiesLimit(limit int64) bool

SatisfiesLimit returns whether this index item satisfies the given limit used when determining whether this IndexItem satisfies a cache reques

func (IndexItem) SatisfiesQuals

func (i IndexItem) SatisfiesQuals(checkQualMap map[string]*proto.Quals, keyColumns map[string]*proto.KeyColumn) bool

SatisfiesQuals does this index item satisfy the check quals all data returned by check quals is returned by index quals

i.e. check quals must be a 'subset' of index quals
eg
   our quals [], check quals [id="1"] 				-> SATISFIED
   our quals [id="1"], check quals [id="1"] 		-> SATISFIED
   our quals [id="1"], check quals [id="1", foo=2] -> SATISFIED
   our quals [id="1", foo=2], check quals [id="1"] -> NOT SATISFIED

NOTE: some columns cannot use this subset logic. Generally this applies to columns which represent a filter which is executed server side to filter the data returned. In this case, we only identify a cache hit if the cached data has the _same_ value for the given colummn

NOTE: if the IndexItem has a limit, the quals must be IDENTICAL (ignoring ordering)

func (IndexItem) SatisfiesTtl

func (i IndexItem) SatisfiesTtl(ttlSeconds int64) bool

SatisfiesTtl does this index item satisfy the ttl requirement

type QueryCache

type QueryCache struct {
	Stats *CacheStats

	// map of connection name to plugin schema
	PluginSchemaMap map[string]*grpc.PluginSchema
	// contains filtered or unexported fields
}

func NewQueryCache

func NewQueryCache(pluginName string, pluginSchemaMap map[string]*grpc.PluginSchema, maxCacheStorageMb int) (*QueryCache, error)

func (*QueryCache) AbortSet

func (c *QueryCache) AbortSet(ctx context.Context, callId string, err error)

func (*QueryCache) ClearForConnection

func (c *QueryCache) ClearForConnection(ctx context.Context, connectionName string)

ClearForConnection removes all cache entries for the given connection

func (*QueryCache) EndSet

func (c *QueryCache) EndSet(ctx context.Context, callId string) (err error)

func (*QueryCache) Get

func (c *QueryCache) Get(ctx context.Context, req *CacheRequest, streamRowFunc func(row *sdkproto.Row)) error

func (*QueryCache) IterateSet

func (c *QueryCache) IterateSet(ctx context.Context, row *sdkproto.Row, callId string) error

func (*QueryCache) StartSet

func (c *QueryCache) StartSet(_ context.Context, req *CacheRequest)

StartSet begins a streaming cache Set operation. NOTE: this mutates req

Jump to

Keyboard shortcuts

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