cache

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2019 License: MIT Imports: 19 Imported by: 14

Documentation

Index

Constants

View Source
const (

	// DomainCacheRefreshInterval domain cache refresh interval
	DomainCacheRefreshInterval = 10 * time.Second
)

Variables

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

type CallbackFn added in v0.3.14

type CallbackFn func(prevDomains []*DomainCacheEntry, nextDomains []*DomainCacheEntry)

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

type DomainCache

type DomainCache interface {
	common.Daemon
	RegisterDomainChangeCallback(shard int, initialNotificationVersion int64, prepareCallback PrepareCallbackFn, callback CallbackFn)
	UnregisterDomainChangeCallback(shard int)
	GetDomain(name string) (*DomainCacheEntry, error)
	GetDomainByID(id string) (*DomainCacheEntry, error)
	GetDomainID(name string) (string, error)
	GetDomainName(id string) (string, error)
	GetAllDomain() map[string]*DomainCacheEntry
	GetCacheSize() (sizeOfCacheByName int64, sizeOfCacheByID int64)
}

DomainCache is used the cache domain information and configuration to avoid making too many calls to cassandra. This cache is mainly used by frontend for resolving domain names to domain uuids which are used throughout the system. Each domain entry is kept in the cache for one hour but also has an expiry of 10 seconds. This results in updating the domain 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 NewDomainCache

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

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

type DomainCacheEntries added in v0.3.13

type DomainCacheEntries []*DomainCacheEntry

DomainCacheEntries is DomainCacheEntry slice

func (DomainCacheEntries) Len added in v0.3.13

func (t DomainCacheEntries) Len() int

Len return length

func (DomainCacheEntries) Less added in v0.3.13

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

Less implements sort.Interface

func (DomainCacheEntries) Swap added in v0.3.13

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

Swap implements sort.Interface.

type DomainCacheEntry added in v0.3.12

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

DomainCacheEntry contains the info and config for a domain

func CreateDomainCacheEntry added in v0.3.14

func CreateDomainCacheEntry(domainName string) *DomainCacheEntry

CreateDomainCacheEntry create a cache entry with domainName

func NewDomainCacheEntryForTest added in v0.5.2

func NewDomainCacheEntryForTest(
	info *persistence.DomainInfo,
	config *persistence.DomainConfig,
	isGlobalDomain bool,
	repConfig *persistence.DomainReplicationConfig,
	failoverVersion int64,
	clusterMetadata cluster.Metadata,
) *DomainCacheEntry

NewDomainCacheEntryForTest returns an entry with test data

func NewGlobalDomainCacheEntryForTest added in v0.6.0

func NewGlobalDomainCacheEntryForTest(
	info *persistence.DomainInfo,
	config *persistence.DomainConfig,
	repConfig *persistence.DomainReplicationConfig,
	failoverVersion int64,
	clusterMetadata cluster.Metadata,
) *DomainCacheEntry

NewGlobalDomainCacheEntryForTest returns an entry with test data

func NewLocalDomainCacheEntryForTest added in v0.6.0

func NewLocalDomainCacheEntryForTest(
	info *persistence.DomainInfo,
	config *persistence.DomainConfig,
	targetCluster string,
	clusterMetadata cluster.Metadata,
) *DomainCacheEntry

NewLocalDomainCacheEntryForTest returns an entry with test data

func (*DomainCacheEntry) GetConfig added in v0.3.12

func (entry *DomainCacheEntry) GetConfig() *persistence.DomainConfig

GetConfig return the domain config

func (*DomainCacheEntry) GetConfigVersion added in v0.3.12

func (entry *DomainCacheEntry) GetConfigVersion() int64

GetConfigVersion return the domain config version

func (*DomainCacheEntry) GetDomainNotActiveErr added in v0.3.12

func (entry *DomainCacheEntry) GetDomainNotActiveErr() error

GetDomainNotActiveErr return err if domain is not active, nil otherwise

func (*DomainCacheEntry) GetFailoverNotificationVersion added in v0.3.13

func (entry *DomainCacheEntry) GetFailoverNotificationVersion() int64

GetFailoverNotificationVersion return the global notification version of when failover happened

func (*DomainCacheEntry) GetFailoverVersion added in v0.3.12

func (entry *DomainCacheEntry) GetFailoverVersion() int64

GetFailoverVersion return the domain failover version

func (*DomainCacheEntry) GetInfo added in v0.3.12

func (entry *DomainCacheEntry) GetInfo() *persistence.DomainInfo

GetInfo return the domain info

func (*DomainCacheEntry) GetNotificationVersion added in v0.3.13

func (entry *DomainCacheEntry) GetNotificationVersion() int64

GetNotificationVersion return the global notification version of when domain changed

func (*DomainCacheEntry) GetReplicationConfig added in v0.3.12

func (entry *DomainCacheEntry) GetReplicationConfig() *persistence.DomainReplicationConfig

GetReplicationConfig return the domain replication config

func (*DomainCacheEntry) GetReplicationPolicy added in v0.7.0

func (entry *DomainCacheEntry) GetReplicationPolicy() ReplicationPolicy

GetReplicationPolicy return the derived workflow replication policy

func (*DomainCacheEntry) GetRetentionDays added in v0.4.0

func (entry *DomainCacheEntry) GetRetentionDays(workflowID string) int32

GetRetentionDays returns retention in days for given workflow

func (*DomainCacheEntry) IsDomainActive added in v0.3.12

func (entry *DomainCacheEntry) IsDomainActive() bool

IsDomainActive return whether the domain is active, i.e. non global domain or global domain which active cluster is the current cluster

func (*DomainCacheEntry) IsGlobalDomain added in v0.3.12

func (entry *DomainCacheEntry) IsGlobalDomain() bool

IsGlobalDomain return whether the domain is a global domain

func (*DomainCacheEntry) IsSampledForLongerRetention added in v0.4.0

func (entry *DomainCacheEntry) IsSampledForLongerRetention(workflowID string) bool

IsSampledForLongerRetention return should given workflow been sampled or not

func (*DomainCacheEntry) IsSampledForLongerRetentionEnabled added in v0.4.0

func (entry *DomainCacheEntry) IsSampledForLongerRetentionEnabled(workflowID string) bool

IsSampledForLongerRetentionEnabled return whether sample for longer retention is enabled or not

type DomainCacheMock added in v0.3.14

type DomainCacheMock struct {
	mock.Mock
}

DomainCacheMock is an autogenerated mock type for the DomainCache type

func (*DomainCacheMock) GetAllDomain added in v0.3.14

func (_m *DomainCacheMock) GetAllDomain() map[string]*DomainCacheEntry

GetAllDomain provides a mock function with given fields:

func (*DomainCacheMock) GetCacheSize added in v0.3.14

func (_m *DomainCacheMock) GetCacheSize() (int64, int64)

GetCacheSize provides a mock function with given fields:

func (*DomainCacheMock) GetDomain added in v0.3.14

func (_m *DomainCacheMock) GetDomain(name string) (*DomainCacheEntry, error)

GetDomain provides a mock function with given fields: name

func (*DomainCacheMock) GetDomainByID added in v0.3.14

func (_m *DomainCacheMock) GetDomainByID(id string) (*DomainCacheEntry, error)

GetDomainByID provides a mock function with given fields: id

func (*DomainCacheMock) GetDomainID added in v0.3.14

func (_m *DomainCacheMock) GetDomainID(name string) (string, error)

GetDomainID provides a mock function with given fields: name

func (*DomainCacheMock) GetDomainName added in v0.7.0

func (_m *DomainCacheMock) GetDomainName(id string) (string, error)

GetDomainName provides a mock function with given fields: id

func (*DomainCacheMock) RegisterDomainChangeCallback added in v0.3.14

func (_m *DomainCacheMock) RegisterDomainChangeCallback(shard int, initialNotificationVersion int64,
	prepareCallbackFn PrepareCallbackFn, callback CallbackFn)

RegisterDomainChangeCallback provides a mock function with given fields: shard, initialNotificationVersion, prepareCallbackFn, callback

func (*DomainCacheMock) Start added in v0.3.14

func (_m *DomainCacheMock) Start()

Start provides a mock function with given fields:

func (*DomainCacheMock) Stop added in v0.3.14

func (_m *DomainCacheMock) Stop()

Stop provides a mock function with given fields:

func (*DomainCacheMock) UnregisterDomainChangeCallback added in v0.3.14

func (_m *DomainCacheMock) UnregisterDomainChangeCallback(shard int)

UnregisterDomainChangeCallback provides a mock function with given fields: shard

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 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 domain's replication policy, derived from domain's replication config

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

Jump to

Keyboard shortcuts

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