cache

package
v1.11.1 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2021 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package cache is a generated GoMock package.

Index

Constants

View Source
const (

	// NamespaceCacheMinRefreshInterval is a minimun namespace cache refresh interval.
	NamespaceCacheMinRefreshInterval = 2 * time.Second
	// NamespaceCacheRefreshInterval namespace cache refresh interval
	NamespaceCacheRefreshInterval = 10 * time.Second
	// NamespaceCacheRefreshFailureRetryInterval is the wait time
	// if refreshment encounters error
	NamespaceCacheRefreshFailureRetryInterval = 1 * time.Second
)

Variables

View Source
var (
	// DummyCreateTime is the create time used by all entries in the cache.
	DummyCreateTime = time.Time{}
)
View Source
var (
	// ErrCacheFull is returned if Put fails due to cache being filled with pinned elements
	ErrCacheFull = errors.New("Cache capacity is fully occupied with pinned elements")
)
View Source
var SampleRateKey = "sample_retention_rate"

SampleRateKey is key to specify sample rate

View Source
var SampleRetentionKey = "sample_retention_days"

SampleRetentionKey is key to specify sample retention

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Get retrieves an element based on a key, returning nil if the element
	// does not exist
	Get(key interface{}) interface{}

	// Put adds an element to the cache, returning the previous element
	Put(key interface{}, value interface{}) interface{}

	// PutIfNotExist puts a value associated with a given key if it does not exist
	PutIfNotExist(key interface{}, value interface{}) (interface{}, error)

	// Delete deletes an element in the cache
	Delete(key interface{})

	// Release decrements the ref count of a pinned element. If the ref count
	// drops to 0, the element can be evicted from the cache.
	Release(key interface{})

	// Iterator returns the iterator of the cache
	Iterator() Iterator

	// Size returns the number of entries currently stored in the Cache
	Size() int
}

A Cache is a generalized interface to a cache. See cache.LRU for a specific implementation (bounded cache with LRU eviction)

func New

func New(maxSize int, opts *Options) Cache

New creates a new cache with the given options

func NewLRU

func NewLRU(maxSize int) Cache

NewLRU creates a new LRU cache of the given size, setting initial capacity to the max size

func NewLRUWithInitialCapacity

func NewLRUWithInitialCapacity(initialCapacity, maxSize int) Cache

NewLRUWithInitialCapacity creates a new LRU cache with an initial capacity and a max size

func NewSimple added in v0.27.0

func NewSimple(opts *SimpleOptions) Cache

NewSimple creates a new simple cache with given options. Simple cache will never evict entries and it will never reorder the elements. Simple cache also does not have the concept of pinning that LRU cache has. Internally simple cache uses a RWMutex instead of the exclusive Mutex that LRU cache uses. The RWMutex makes simple cache readable by many threads without introducing lock contention.

type CallbackFn added in v0.3.14

type CallbackFn func(prevNamespaces []*NamespaceCacheEntry, nextNamespaces []*NamespaceCacheEntry)

CallbackFn is function to be called when the namespace cache entries are changed it is guaranteed that PrepareCallbackFn and CallbackFn pair will be both called or non will be called

type Entry added in v0.3.5

type Entry interface {
	// Key represents the key
	Key() interface{}
	// Value represents the value
	Value() interface{}
	// CreateTime represents the time when the entry is created
	CreateTime() time.Time
}

Entry represents a key-value entry within the map

type Iterator added in v0.3.5

type Iterator interface {
	// Close closes the iterator
	// and releases any allocated resources
	Close()
	// HasNext return true if there is more items to be returned
	HasNext() bool
	// Next return the next item
	Next() Entry
}

Iterator represents the interface for cache iterators

type MockNamespaceCache added in v0.27.0

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

MockNamespaceCache is a mock of NamespaceCache interface.

func NewMockNamespaceCache added in v0.27.0

func NewMockNamespaceCache(ctrl *gomock.Controller) *MockNamespaceCache

NewMockNamespaceCache creates a new mock instance.

func (*MockNamespaceCache) EXPECT added in v0.27.0

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockNamespaceCache) GetAllNamespace added in v0.27.0

func (m *MockNamespaceCache) GetAllNamespace() map[string]*NamespaceCacheEntry

GetAllNamespace mocks base method.

func (*MockNamespaceCache) GetCacheSize added in v0.27.0

func (m *MockNamespaceCache) GetCacheSize() (int64, int64)

GetCacheSize mocks base method.

func (*MockNamespaceCache) GetNamespace added in v0.27.0

func (m *MockNamespaceCache) GetNamespace(name string) (*NamespaceCacheEntry, error)

GetNamespace mocks base method.

func (*MockNamespaceCache) GetNamespaceByID added in v0.27.0

func (m *MockNamespaceCache) GetNamespaceByID(id string) (*NamespaceCacheEntry, error)

GetNamespaceByID mocks base method.

func (*MockNamespaceCache) GetNamespaceID added in v0.27.0

func (m *MockNamespaceCache) GetNamespaceID(name string) (string, error)

GetNamespaceID mocks base method.

func (*MockNamespaceCache) GetNamespaceName added in v0.27.0

func (m *MockNamespaceCache) GetNamespaceName(id string) (string, error)

GetNamespaceName mocks base method.

func (*MockNamespaceCache) RegisterNamespaceChangeCallback added in v0.27.0

func (m *MockNamespaceCache) RegisterNamespaceChangeCallback(shard int32, initialNotificationVersion int64, prepareCallback PrepareCallbackFn, callback CallbackFn)

RegisterNamespaceChangeCallback mocks base method.

func (*MockNamespaceCache) Start added in v0.27.0

func (m *MockNamespaceCache) Start()

Start mocks base method.

func (*MockNamespaceCache) Stop added in v0.27.0

func (m *MockNamespaceCache) Stop()

Stop mocks base method.

func (*MockNamespaceCache) UnregisterNamespaceChangeCallback added in v0.27.0

func (m *MockNamespaceCache) UnregisterNamespaceChangeCallback(shard int32)

UnregisterNamespaceChangeCallback mocks base method.

type MockNamespaceCacheMockRecorder added in v0.27.0

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

MockNamespaceCacheMockRecorder is the mock recorder for MockNamespaceCache.

func (*MockNamespaceCacheMockRecorder) GetAllNamespace added in v0.27.0

func (mr *MockNamespaceCacheMockRecorder) GetAllNamespace() *gomock.Call

GetAllNamespace indicates an expected call of GetAllNamespace.

func (*MockNamespaceCacheMockRecorder) GetCacheSize added in v0.27.0

func (mr *MockNamespaceCacheMockRecorder) GetCacheSize() *gomock.Call

GetCacheSize indicates an expected call of GetCacheSize.

func (*MockNamespaceCacheMockRecorder) GetNamespace added in v0.27.0

func (mr *MockNamespaceCacheMockRecorder) GetNamespace(name interface{}) *gomock.Call

GetNamespace indicates an expected call of GetNamespace.

func (*MockNamespaceCacheMockRecorder) GetNamespaceByID added in v0.27.0

func (mr *MockNamespaceCacheMockRecorder) GetNamespaceByID(id interface{}) *gomock.Call

GetNamespaceByID indicates an expected call of GetNamespaceByID.

func (*MockNamespaceCacheMockRecorder) GetNamespaceID added in v0.27.0

func (mr *MockNamespaceCacheMockRecorder) GetNamespaceID(name interface{}) *gomock.Call

GetNamespaceID indicates an expected call of GetNamespaceID.

func (*MockNamespaceCacheMockRecorder) GetNamespaceName added in v0.27.0

func (mr *MockNamespaceCacheMockRecorder) GetNamespaceName(id interface{}) *gomock.Call

GetNamespaceName indicates an expected call of GetNamespaceName.

func (*MockNamespaceCacheMockRecorder) RegisterNamespaceChangeCallback added in v0.27.0

func (mr *MockNamespaceCacheMockRecorder) RegisterNamespaceChangeCallback(shard, initialNotificationVersion, prepareCallback, callback interface{}) *gomock.Call

RegisterNamespaceChangeCallback indicates an expected call of RegisterNamespaceChangeCallback.

func (*MockNamespaceCacheMockRecorder) Start added in v0.27.0

Start indicates an expected call of Start.

func (*MockNamespaceCacheMockRecorder) Stop added in v0.27.0

Stop indicates an expected call of Stop.

func (*MockNamespaceCacheMockRecorder) UnregisterNamespaceChangeCallback added in v0.27.0

func (mr *MockNamespaceCacheMockRecorder) UnregisterNamespaceChangeCallback(shard interface{}) *gomock.Call

UnregisterNamespaceChangeCallback indicates an expected call of UnregisterNamespaceChangeCallback.

type NamespaceCache added in v0.27.0

type NamespaceCache interface {
	common.Daemon
	RegisterNamespaceChangeCallback(shard int32, initialNotificationVersion int64, prepareCallback PrepareCallbackFn, callback CallbackFn)
	UnregisterNamespaceChangeCallback(shard int32)
	GetNamespace(name string) (*NamespaceCacheEntry, error)
	GetNamespaceByID(id string) (*NamespaceCacheEntry, error)
	GetNamespaceID(name string) (string, error)
	GetNamespaceName(id string) (string, error)
	GetAllNamespace() map[string]*NamespaceCacheEntry
	GetCacheSize() (sizeOfCacheByName int64, sizeOfCacheByID int64)
}

NamespaceCache is used the cache namespace information and configuration to avoid making too many calls to cassandra. This cache is mainly used by frontend for resolving namespace names to namespace uuids which are used throughout the system. Each namespace entry is kept in the cache for one hour but also has an expiry of 10 seconds. This results in updating the namespace entry every 10 seconds but in the case of a cassandra failure we can still keep on serving requests using the stale entry from cache upto an hour

func NewNamespaceCache added in v0.27.0

func NewNamespaceCache(
	metadataMgr persistence.MetadataManager,
	clusterMetadata cluster.Metadata,
	metricsClient metrics.Client,
	logger log.Logger,
) NamespaceCache

NewNamespaceCache creates a new instance of cache for holding onto namespace information to reduce the load on persistence

type NamespaceCacheEntries added in v0.27.0

type NamespaceCacheEntries []*NamespaceCacheEntry

NamespaceCacheEntries is NamespaceCacheEntry slice

func (NamespaceCacheEntries) Len added in v0.27.0

func (t NamespaceCacheEntries) Len() int

Len return length

func (NamespaceCacheEntries) Less added in v0.27.0

func (t NamespaceCacheEntries) Less(i, j int) bool

Less implements sort.Interface

func (NamespaceCacheEntries) Swap added in v0.27.0

func (t NamespaceCacheEntries) Swap(i, j int)

Swap implements sort.Interface.

type NamespaceCacheEntry added in v0.27.0

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

NamespaceCacheEntry contains the info and config for a namespace

func CreateNamespaceCacheEntry added in v0.27.0

func CreateNamespaceCacheEntry(
	namespace string,
) *NamespaceCacheEntry

CreateNamespaceCacheEntry create a cache entry with namespace

func NewGlobalNamespaceCacheEntryForTest added in v0.27.0

func NewGlobalNamespaceCacheEntryForTest(
	info *persistencespb.NamespaceInfo,
	config *persistencespb.NamespaceConfig,
	repConfig *persistencespb.NamespaceReplicationConfig,
	failoverVersion int64,
	clusterMetadata cluster.Metadata,
) *NamespaceCacheEntry

NewGlobalNamespaceCacheEntryForTest returns an entry with test data

func NewLocalNamespaceCacheEntryForTest added in v0.27.0

func NewLocalNamespaceCacheEntryForTest(
	info *persistencespb.NamespaceInfo,
	config *persistencespb.NamespaceConfig,
	targetCluster string,
	clusterMetadata cluster.Metadata,
) *NamespaceCacheEntry

NewLocalNamespaceCacheEntryForTest returns an entry with test data

func NewNamespaceCacheEntryForTest added in v0.27.0

func NewNamespaceCacheEntryForTest(
	info *persistencespb.NamespaceInfo,
	config *persistencespb.NamespaceConfig,
	isGlobalNamespace bool,
	repConfig *persistencespb.NamespaceReplicationConfig,
	failoverVersion int64,
	clusterMetadata cluster.Metadata,
) *NamespaceCacheEntry

NewNamespaceCacheEntryForTest returns an entry with test data

func (*NamespaceCacheEntry) GetConfig added in v0.27.0

GetConfig return the namespace config

func (*NamespaceCacheEntry) GetConfigVersion added in v0.27.0

func (entry *NamespaceCacheEntry) GetConfigVersion() int64

GetConfigVersion return the namespace config version

func (*NamespaceCacheEntry) GetFailoverNotificationVersion added in v0.27.0

func (entry *NamespaceCacheEntry) GetFailoverNotificationVersion() int64

GetFailoverNotificationVersion return the global notification version of when failover happened

func (*NamespaceCacheEntry) GetFailoverVersion added in v0.27.0

func (entry *NamespaceCacheEntry) GetFailoverVersion() int64

GetFailoverVersion return the namespace failover version

func (*NamespaceCacheEntry) GetInfo added in v0.27.0

GetInfo return the namespace info

func (*NamespaceCacheEntry) GetNamespaceNotActiveErr added in v0.27.0

func (entry *NamespaceCacheEntry) GetNamespaceNotActiveErr() error

GetNamespaceNotActiveErr return err if namespace is not active, nil otherwise

func (*NamespaceCacheEntry) GetNotificationVersion added in v0.27.0

func (entry *NamespaceCacheEntry) GetNotificationVersion() int64

GetNotificationVersion return the global notification version of when namespace changed

func (*NamespaceCacheEntry) GetReplicationConfig added in v0.27.0

func (entry *NamespaceCacheEntry) GetReplicationConfig() *persistencespb.NamespaceReplicationConfig

GetReplicationConfig return the namespace replication config

func (*NamespaceCacheEntry) GetReplicationPolicy added in v0.27.0

func (entry *NamespaceCacheEntry) GetReplicationPolicy() ReplicationPolicy

GetReplicationPolicy return the derived workflow replication policy

func (*NamespaceCacheEntry) GetRetention added in v1.11.0

func (entry *NamespaceCacheEntry) GetRetention(
	workflowID string,
) time.Duration

GetRetention returns retention in days for given workflow

func (*NamespaceCacheEntry) IsGlobalNamespace added in v0.27.0

func (entry *NamespaceCacheEntry) IsGlobalNamespace() bool

IsGlobalNamespace return whether the namespace is a global namespace

func (*NamespaceCacheEntry) IsNamespaceActive added in v0.27.0

func (entry *NamespaceCacheEntry) IsNamespaceActive() bool

IsNamespaceActive return whether the namespace is active, i.e. non global namespace or global namespace which active cluster is the current cluster

func (*NamespaceCacheEntry) IsSampledForLongerRetention added in v0.27.0

func (entry *NamespaceCacheEntry) IsSampledForLongerRetention(
	workflowID string,
) bool

IsSampledForLongerRetention return should given workflow been sampled or not

func (*NamespaceCacheEntry) IsSampledForLongerRetentionEnabled added in v0.27.0

func (entry *NamespaceCacheEntry) IsSampledForLongerRetentionEnabled(
	workflowID string,
) bool

IsSampledForLongerRetentionEnabled return whether sample for longer retention is enabled or not

type Options

type Options struct {
	// TTL controls the time-to-live for a given cache entry.  Cache entries that
	// are older than the TTL will not be returned.
	TTL time.Duration

	// InitialCapacity controls the initial capacity of the cache
	InitialCapacity int

	// Pin prevents in-use objects from getting evicted.
	Pin bool

	// RemovedFunc is an optional function called when an element
	// is scheduled for deletion
	RemovedFunc RemovedFunc
}

Options control the behavior of the cache

type PrepareCallbackFn added in v0.5.0

type PrepareCallbackFn func()

PrepareCallbackFn is function to be called before CallbackFn is called, it is guaranteed that PrepareCallbackFn and CallbackFn pair will be both called or non will be called

type RemovedFunc

type RemovedFunc func(interface{})

RemovedFunc is a type for notifying applications when an item is scheduled for removal from the Cache. If f is a function with the appropriate signature and i is the interface{} scheduled for deletion, Cache calls go f(i)

type ReplicationPolicy added in v0.7.0

type ReplicationPolicy int

ReplicationPolicy is the namespace's replication policy, derived from namespace's replication config

const (
	// ReplicationPolicyOneCluster indicate that workflows does not need to be replicated
	// applicable to local namespace & global namespace with one cluster
	ReplicationPolicyOneCluster ReplicationPolicy = 0
	// ReplicationPolicyMultiCluster indicate that workflows need to be replicated
	ReplicationPolicyMultiCluster ReplicationPolicy = 1
)

type SimpleOptions added in v0.27.0

type SimpleOptions struct {
	// InitialCapacity controls the initial capacity of the cache
	InitialCapacity int

	// RemovedFunc is an optional function called when an element
	// is scheduled for deletion
	RemovedFunc RemovedFunc
}

SimpleOptions provides options that can be used to configure SimpleCache

Jump to

Keyboard shortcuts

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