Documentation
¶
Overview ¶
Package galaxycache provides a data loading mechanism with caching and de-duplication that works across a set of peer processes.
Each data Get first consults its local cache, otherwise delegates to the requested key's canonical owner, which then checks its cache or finally gets the data. In the common case, many concurrent cache misses across a set of peers for the same key result in just one cache fill.
In most cases, one will construct a Universe with NewUniverse, and then construct a Galaxy with Universe.NewGalaxy.
Expiration/TTL ¶
Galaxy implementations support the concept of a value's expiration time. This may either be set by providing an BackendGetterWithInfo implementation to Universe.NewGalaxyWithBackendInfo which returns a non-zero BackendGetInfo.Expiration.
Additionally, Universe.NewGalaxy and Universe.NewGalaxyWithBackendInfo may take WithGetTTL and [WithPeekTTL] as arguments to provide default expiration-times. [WithPeekTTL] only applies to values that are pulled from peers via RemoteFetcher.Peek and RemoteFetcherWithInfo.PeekWithInfo requests.
Index ¶
- Variables
- type AtomicInt
- type BackendGetInfo
- type BackendGetter
- type BackendGetterWithInfo
- type ByteCodec
- type CacheStats
- type CacheType
- type Codec
- type CopyingByteCodec
- type FetchMode
- type FetchProtocol
- type Galaxy
- type GalaxyOption
- func WithClock(clk clocks.Clock) GalaxyOption
- func WithGetTTL(maxTTL, jitter time.Duration) GalaxyOption
- func WithHotCacheRatio(r int64) GalaxyOption
- func WithIdleStatsAgeResetWindow(age time.Duration) GalaxyOption
- func WithMaxCandidates(n int) GalaxyOption
- func WithPreviousPeerPeeking(cfg PeekPeerCfg) GalaxyOption
- func WithPromoter(p promoter.Interface) GalaxyOption
- type GalaxyStats
- type GetInfo
- type GetOptions
- type GetterFunc
- type GetterFuncWithInfo
- type HCStatsWithTime
- type HashOptions
- type NotFoundErr
- type NullFetchProtocol
- type PeekPeerCfg
- type Peer
- type PeerPicker
- type RemoteFetcher
- type RemoteFetcherWithInfo
- type StringCodec
- type TrivialNotFoundErr
- type Universe
- func (universe *Universe) AddPeer(peer Peer) error
- func (universe *Universe) GetGalaxy(name string) *Galaxy
- func (universe *Universe) IncludeSelf() bool
- func (universe *Universe) ListPeers() map[string]RemoteFetcher
- func (universe *Universe) NewGalaxy(name string, cacheBytes int64, getter BackendGetter, opts ...GalaxyOption) *Galaxy
- func (universe *Universe) NewGalaxyWithBackendInfo(name string, cacheBytes int64, getter BackendGetterWithInfo, ...) *Galaxy
- func (universe *Universe) RemovePeers(ids ...string) error
- func (universe *Universe) SelfID() string
- func (universe *Universe) Set(peerURLs ...string) error
- func (universe *Universe) SetIncludeSelf(incSelf bool)
- func (universe *Universe) SetPeers(peers ...Peer) error
- func (universe *Universe) Shutdown() error
- type UniverseOpt
Constants ¶
This section is empty.
Variables ¶
var ( MGets = stats.Int64("galaxycache/gets", "The number of Get requests", stats.UnitDimensionless) MLoads = stats.Int64("galaxycache/loads", "The number of gets/cacheHits", stats.UnitDimensionless) MLoadErrors = stats.Int64("galaxycache/loads_errors", "The number of errors encountered during Get", stats.UnitDimensionless) MCacheHits = stats.Int64("galaxycache/cache_hits", "The number of times that the cache was hit", stats.UnitDimensionless) MPeerLoads = stats.Int64("galaxycache/peer_loads", "The number of remote loads or remote cache hits", stats.UnitDimensionless) MPeerLoadErrors = stats.Int64("galaxycache/peer_errors", "The number of remote errors", stats.UnitDimensionless) MBackendLoads = stats.Int64("galaxycache/backend_loads", "The number of successful loads from the backend getter", stats.UnitDimensionless) MBackendLoadErrors = stats.Int64("galaxycache/local_load_errors", "The number of failed backend loads", stats.UnitDimensionless) MPeeks = stats.Int64("galaxycache/peeks", "The number of remote cache hits via Peek requests", stats.UnitDimensionless) MCoalescedLoads = stats.Int64("galaxycache/coalesced_loads", "The number of loads coalesced by singleflight", stats.UnitDimensionless) MCoalescedCacheHits = stats.Int64("galaxycache/coalesced_cache_hits", "The number of coalesced times that the cache was hit", stats.UnitDimensionless) MCoalescedPeerLoads = stats.Int64("galaxycache/coalesced_peer_loads", "The number of coalesced remote loads or remote cache hits", stats.UnitDimensionless) MCoalescedPeeks = stats.Int64("galaxycache/coalesced_peeks", "The number of coalesced remote loads via Peek requests", stats.UnitDimensionless) MCoalescedPeekHits = stats.Int64("galaxycache/coalesced_peek_hits", "The number of coalesced remote cache hits via Peek requests", stats.UnitDimensionless) MCoalescedBackendLoads = stats.Int64("galaxycache/coalesced_backend_loads", "The number of coalesced successful loads from the backend getter", stats.UnitDimensionless) MCoalescedPeekErrors = stats.Int64("galaxycache/coalesced_peek_errors", "The number of coalesced remote Peek requests that failed with errors other than Not Found", stats.UnitDimensionless) MServerRequests = stats.Int64("galaxycache/server_requests", "The number of Gets that came over the network from peers", stats.UnitDimensionless) MKeyLength = stats.Int64("galaxycache/key_length", "The length of keys", stats.UnitBytes) MValueLength = stats.Int64("galaxycache/value_length", "The length of values", stats.UnitBytes) MRoundtripLatencyMilliseconds = stats.Float64("galaxycache/roundtrip_latency", "Roundtrip latency in milliseconds", stats.UnitMilliseconds) MCacheSize = stats.Int64("galaxycache/cache_bytes", "The number of bytes used for storing Keys and Values in the cache", stats.UnitBytes) MCacheEntries = stats.Int64("galaxycache/cache_entries", "The number of entries in the cache", stats.UnitDimensionless) MGetterFuncLatencyMilliseconds = stats.Float64("galaxycache/getterfunc_latency", "Local getter function latency in milliseconds", stats.UnitMilliseconds) )
Opencensus stats
var ( // GalaxyKey tags the name of the galaxy GalaxyKey = tag.MustNewKey("galaxy") // CacheLevelKey tags the level at which data was found on Get CacheLevelKey = tag.MustNewKey("cache-hit-level") // CacheTypeKey tags the galaxy sub-cache the metric applies to CacheTypeKey = tag.MustNewKey("cache-type") )
var AllViews = []*view.View{ {Measure: MGets, TagKeys: []tag.Key{GalaxyKey}, Aggregation: view.Count()}, {Measure: MLoads, TagKeys: []tag.Key{GalaxyKey}, Aggregation: view.Count()}, {Measure: MLoadErrors, TagKeys: []tag.Key{GalaxyKey}, Aggregation: view.Count()}, {Measure: MCacheHits, TagKeys: []tag.Key{GalaxyKey, CacheLevelKey}, Aggregation: view.Count()}, {Measure: MPeerLoads, TagKeys: []tag.Key{GalaxyKey}, Aggregation: view.Count()}, {Measure: MPeerLoadErrors, TagKeys: []tag.Key{GalaxyKey}, Aggregation: view.Count()}, {Measure: MPeeks, TagKeys: []tag.Key{GalaxyKey}, Aggregation: view.Count()}, {Measure: MBackendLoads, TagKeys: []tag.Key{GalaxyKey}, Aggregation: view.Count()}, {Measure: MBackendLoadErrors, TagKeys: []tag.Key{GalaxyKey}, Aggregation: view.Count()}, {Measure: MCoalescedPeeks, TagKeys: []tag.Key{GalaxyKey}, Aggregation: view.Count()}, {Measure: MCoalescedPeekHits, TagKeys: []tag.Key{GalaxyKey}, Aggregation: view.Count()}, {Measure: MCoalescedLoads, TagKeys: []tag.Key{GalaxyKey}, Aggregation: view.Count()}, {Measure: MCoalescedCacheHits, TagKeys: []tag.Key{GalaxyKey, CacheLevelKey}, Aggregation: view.Count()}, {Measure: MCoalescedPeekErrors, TagKeys: []tag.Key{GalaxyKey}, Aggregation: view.Count()}, {Measure: MCoalescedPeerLoads, TagKeys: []tag.Key{GalaxyKey}, Aggregation: view.Count()}, {Measure: MCoalescedBackendLoads, TagKeys: []tag.Key{GalaxyKey}, Aggregation: view.Count()}, {Measure: MServerRequests, TagKeys: []tag.Key{GalaxyKey}, Aggregation: view.Count()}, {Measure: MKeyLength, TagKeys: []tag.Key{GalaxyKey}, Aggregation: defaultBytesDistribution}, {Measure: MValueLength, TagKeys: []tag.Key{GalaxyKey}, Aggregation: defaultBytesDistribution}, {Measure: MRoundtripLatencyMilliseconds, TagKeys: []tag.Key{GalaxyKey}, Aggregation: defaultMillisecondsDistribution}, {Measure: MCacheSize, TagKeys: []tag.Key{GalaxyKey, CacheTypeKey}, Aggregation: view.LastValue()}, {Measure: MCacheEntries, TagKeys: []tag.Key{GalaxyKey, CacheTypeKey}, Aggregation: view.LastValue()}, {Measure: MGetterFuncLatencyMilliseconds, TagKeys: []tag.Key{GalaxyKey}, Aggregation: defaultMillisecondsDistribution}, }
AllViews is a slice of default views for people to use
Functions ¶
This section is empty.
Types ¶
type AtomicInt ¶
type AtomicInt struct {
// contains filtered or unexported fields
}
An AtomicInt is an int64 to be accessed atomically. It thinly wraps atomic.Int64 with go1.19+
type BackendGetInfo ¶ added in v1.4.0
type BackendGetInfo struct {
// Expiration is a timestamp at which this value should be considered expired
// the zero-value is no expiration.
// Values should always be in the future according to the clock for this universe/galaxy
Expiration time.Time
}
BackendGetInfo contains additional information from a BackendGetterWithInfo implementation. Currently, this is just an expiration, but, it may expand in the future.
type BackendGetter ¶
type BackendGetter interface {
// Get populates dest with the value identified by key
//
// The returned data must be unversioned. That is, key must
// uniquely describe the loaded data, without an implicit
// current time, and without relying on cache expiration
// mechanisms.
Get(ctx context.Context, key string, dest Codec) error
}
A BackendGetter loads data for a key.
type BackendGetterWithInfo ¶ added in v1.4.0
type BackendGetterWithInfo interface {
// GetWithInfo populates dest with the value identified by key
//
// The returned data must be unversioned. That is, the key must
// uniquely describe the loaded data. One may set Expiration on the
// [BackendGetInfo] return value.
GetWithInfo(ctx context.Context, key string, dest Codec) (BackendGetInfo, error)
}
BackendGetterWithInfo provides the GetWithInfo method for an enhanced BackendGetter that's capable of returning expiration information (and may provide other enhancements later)
type ByteCodec ¶
type ByteCodec []byte
ByteCodec is a byte slice type that implements Codec
func (*ByteCodec) MarshalBinary ¶
MarshalBinary on a ByteCodec returns the bytes
func (*ByteCodec) UnmarshalBinary ¶
UnmarshalBinary on a ByteCodec sets the ByteCodec to a copy of the provided data
type CacheStats ¶
CacheStats are returned by stats accessors on Galaxy.
type CacheType ¶
type CacheType uint8
CacheType represents a type of cache.
const ( // MainCache is the cache for items that this peer is the // owner of. MainCache CacheType = iota + 1 // HotCache is the cache for items that seem popular // enough to replicate to this node, even though it's not the // owner. HotCache // CandidateCache is the cache for peer-owned keys that // may become popular enough to put in the HotCache CandidateCache )
type CopyingByteCodec ¶
type CopyingByteCodec []byte
CopyingByteCodec is a byte slice type that implements Codec and returns a copy of the bytes when marshaled
func (*CopyingByteCodec) MarshalBinary ¶
func (c *CopyingByteCodec) MarshalBinary() ([]byte, error)
MarshalBinary on a CopyingByteCodec returns a copy of the bytes
func (*CopyingByteCodec) UnmarshalBinary ¶
func (c *CopyingByteCodec) UnmarshalBinary(data []byte) error
UnmarshalBinary on a CopyingByteCodec sets the ByteCodec to a copy of the provided data
type FetchMode ¶ added in v1.3.0
type FetchMode uint8
FetchMode is a trimode enum indicating how to handle fetching
const ( // Normal fetch behavior: check local cache, then peer, then do a local backend fetch FetchModeRegular FetchMode = iota // Like Regular, but only issue peek calls to peers, so we don't incur backend gets there. // (the peek call may have a very short deadline, if issued (controlled at the galaxy level)) FetchModeNoPeerBackend // Only check whether this is in-cache FetchModePeek )
type FetchProtocol ¶
type FetchProtocol interface {
// NewFetcher instantiates the connection between the current and a
// remote peer and returns a RemoteFetcher to be used for fetching
// data from that peer
NewFetcher(url string) (RemoteFetcher, error)
}
FetchProtocol defines the chosen fetching protocol to peers (namely HTTP or GRPC) and implements the instantiation method for that connection (creating a new RemoteFetcher)
type Galaxy ¶
type Galaxy struct {
// Stats are statistics on the galaxy.
Stats GalaxyStats
// contains filtered or unexported fields
}
A Galaxy is a cache namespace and associated data spread over a group of 1 or more machines.
func (*Galaxy) CacheStats ¶
func (g *Galaxy) CacheStats(which CacheType) CacheStats
CacheStats returns stats about the provided cache within the galaxy.
func (*Galaxy) Get ¶
Get as defined here is the primary "get" called on a galaxy to find the value for the given key, using the following logic: - First, try the local cache; if its a cache hit, we're done - On a cache miss, search for which peer is the owner of the key based on the consistent hash - If a different peer is the owner, use the corresponding fetcher to Fetch from it; otherwise, if the calling instance is the key's canonical owner, call the BackendGetter to retrieve the value (which will now be cached locally) This is a wrapper around GetWithOptions.
func (*Galaxy) GetWithOptions ¶ added in v1.3.0
func (g *Galaxy) GetWithOptions(ctx context.Context, opts GetOptions, key string, dest Codec) (GetInfo, error)
GetWithOptions as defined here is the primary "get" called on a galaxy to find the value for the given key, using the following logic:
First, try the local cache; if its a cache hit, we're done
if the FetchMode is FetchModePeek; we're done, return a Not Found
otherwise, search for which peer is the owner of the key based on the consistent hash
If a different peer is the owner and the FetchMode is not FetchModeNoPeerBackend: use the corresponding fetcher to Fetch from it
if the peer request fails with a Not Found; return a Not Found
if the peer request fails with any other error, fallthrough to the local BackendGetter
if peer-peeking is enabled, and this instance is the key's owner, and we're within the configured warmup period, send a Peek request with a short-deadline to the "fallthrough owner" (who would own this key if the calling instance wasn't in the hash-ring)
if that fails or returns Not Found fallthrough
call the BackendGetter to retrieve the value (which will now be cached locally).
return whatever the BackendGetter provides
type GalaxyOption ¶
type GalaxyOption interface {
// contains filtered or unexported methods
}
GalaxyOption is an interface for implementing functional galaxy options
func WithClock ¶
func WithClock(clk clocks.Clock) GalaxyOption
WithClock lets one override the clock used internally for key-stats accounting (among other things).
func WithGetTTL ¶ added in v1.4.0
func WithGetTTL(maxTTL, jitter time.Duration) GalaxyOption
WithGetTTL allows the client to specify a maximum Time To Live (TTL) for the values in this galaxy, with an optional jitter.
Jitter may be 0 to always set the expiration to be exactly maxTTL time in the future.
If a value has an Expiration time closer than maxTTL in the future it will be left alone no matter the source. Conversely, if there is no Expiration set, or it's farther in the future than maxTTL, a new one will be set based on the value of maxTTL and jitter.
Setting a non-zero Jitter will randomly pick an expiry between maxTTL-Jitter and maxTTL in the future. When set appropriately, this can be leveraged to prevent values populated at about the same time from expiring simultaneously and causing a burst in activity while rehydrating values. When used, Jitter values should be large enough that, over a reasonable number of maxTTL intervals, keys that are continually accessed will spread their expiration across the entire interval.
Negative TTLs and jitter values are silently ignored, and jitter values that are greater than maxTTL will be capped at maxTTL.
func WithHotCacheRatio ¶
func WithHotCacheRatio(r int64) GalaxyOption
WithHotCacheRatio allows the client to specify a ratio for the main-to-hot cache sizes for the galaxy; defaults to 8:1
func WithIdleStatsAgeResetWindow ¶
func WithIdleStatsAgeResetWindow(age time.Duration) GalaxyOption
WithIdleStatsAgeResetWindow overrides the default interval after which a key that's been idle for a while gets its stats reset (such that that hit is recorded as if it were the first).
func WithMaxCandidates ¶
func WithMaxCandidates(n int) GalaxyOption
WithMaxCandidates allows the client to specify the size of the candidate cache by the max number of candidates held at one time; defaults to 100
func WithPreviousPeerPeeking ¶ added in v1.3.0
func WithPreviousPeerPeeking(cfg PeekPeerCfg) GalaxyOption
WithPreviousPeerPeeking enables peer-peeking and sets the config
func WithPromoter ¶
func WithPromoter(p promoter.Interface) GalaxyOption
WithPromoter allows the client to specify a promoter for the galaxy; defaults to a simple QPS comparison
type GalaxyStats ¶
type GalaxyStats struct {
Gets AtomicInt // any Get request, including from peers
Loads AtomicInt // (gets - cacheHits)
CoalescedLoads AtomicInt // inside singleflight
MaincacheHits AtomicInt // number of maincache hits
HotcacheHits AtomicInt // number of hotcache hits
PeerLoads AtomicInt // either remote load or remote cache hit (not an error)
PeerLoadErrors AtomicInt // errors on getFromPeer
BackendLoads AtomicInt // load from backend locally
BackendLoadErrors AtomicInt // total bad local loads
PeerPeekHits AtomicInt // peer Peek hits
PeerPeeks AtomicInt // peer Peek requests
CoalescedMaincacheHits AtomicInt // maincache hit in singleflight
CoalescedHotcacheHits AtomicInt // hotcache hit in singleflight
CoalescedPeerLoads AtomicInt // peer load in singleflight
CoalescedBackendLoads AtomicInt // backend load in singleflight
CoalescedPeerPeekHits AtomicInt // peek hit in singleflight
CoalescedPeerPeeks AtomicInt // peek request in singleflight
CoalescedPeerPeekErrors AtomicInt // peek failure (not not-found) in singleflight
ServerRequests AtomicInt // gets that came over the network from peers
}
GalaxyStats are per-galaxy statistics.
type GetInfo ¶ added in v1.3.0
type GetInfo struct {
// If non-zero, Expiry provides an expiration time after which
// Galaxycache should not return this value (and should ideally evict
// it from the cache to prevent unexpired, but more recently-touched
// items from being evicted)
Expiry time.Time
}
GetInfo provides information about the Get call and any auxilliary information for the value. Notably whether there's an expiration associated with the returned value.
type GetOptions ¶ added in v1.3.0
type GetOptions struct {
// FetchMode
FetchMode FetchMode
}
type GetterFunc ¶
A GetterFunc implements BackendGetter with a function.
type GetterFuncWithInfo ¶ added in v1.4.0
A GetterFuncWithInfo implements BackendGetterWithInfo with a function.
func (GetterFuncWithInfo) GetWithInfo ¶ added in v1.4.0
func (f GetterFuncWithInfo) GetWithInfo(ctx context.Context, key string, dest Codec) (BackendGetInfo, error)
GetWithInfo implements [BackendGetterWithInfo.GetWithInfo]
type HCStatsWithTime ¶
type HCStatsWithTime struct {
// contains filtered or unexported fields
}
HCStatsWithTime includes a time stamp along with the hotcache stats to ensure updates happen no more than once per second
type HashOptions ¶
type HashOptions struct {
// Replicas specifies the number of key replicas on the consistent hash.
// If zero, it defaults to 50.
Replicas int
// HashFn specifies the hash function of the consistent hash.
// If nil, it defaults to crc32.ChecksumIEEE.
HashFn consistenthash.Hash
}
HashOptions specifies the the hash function and the number of replicas for consistent hashing
type NotFoundErr ¶ added in v1.3.0
type NotFoundErr interface {
error
IsNotFound()
}
NotFoundErr is an error indicating that the key was not found. If an error unwraps to it (with errors.As), Galaxycache may skip a local lookup and return an error implementing this interface (possibly forwarding an error message from the remote peer (fetch protocol permitting) TrivialNotFoundErr is available for wrapping to satisfy this requirement.
type NullFetchProtocol ¶
type NullFetchProtocol struct{}
NullFetchProtocol implements FetchProtocol, but always returns errors. (useful for unit-testing)
func (*NullFetchProtocol) NewFetcher ¶
func (n *NullFetchProtocol) NewFetcher(url string) (RemoteFetcher, error)
NewFetcher instantiates the connection between the current and a remote peer and returns a RemoteFetcher to be used for fetching data from that peer
type PeekPeerCfg ¶ added in v1.3.0
type PeekPeerCfg struct {
// PeekTimeout is the timeout to use when making Peek requests for this Galaxy.
// this may be in the 2-10ms range for local networks, as the remote
// end should always service this request from memory.
PeekTimeout time.Duration `` /* 260-byte string literal not displayed */
// WarmTime indicates how long after this galaxy initializes to stop
// making Peek requests for a range after it took over that range.
// This should be on par with the cache-warming time for initial startup.
// Ranges transfered to this instance from peers that scale-down will
// send Peek requests to those dying peers until it starts erroring.
WarmTime time.Duration `` /* 126-byte string literal not displayed */
// PeekedValueMaxTTL and PeekedValueTTLJitter allow one to specify a maximum Time To Live (TTL) for
// the values in this Galaxy pulled from peers via Peek requests.
//
// Jitter may be 0 to always set the expiration to be exactly maxTTL time in
// the future.
//
// If a value has an Expiration time closer than maxTTL in the
// future it will be left alone no matter the source. Conversely, if there is
// no Expiration set, or it's farther in the future than maxTTL, a new one will
// be set based on the value of maxTTL and jitter.
//
// Setting a non-zero Jitter will randomly pick an expiry between maxTTL-Jitter
// and maxTTL in the future. When set appropriately, this can be leveraged to
// prevent values populated at about the same time from expiring
// simultaneously and causing a burst in activity while rehydrating values.
// When used, Jitter values should be large enough that, over a reasonable
// number of maxTTL intervals, keys that are continually accessed will
// spread their expiration across the entire interval.
//
// Negative TTLs and jitter values are silently ignored, and jitter values that
// are greater than maxTTL will be capped at maxTTL.
PeekedValueMaxTTL time.Duration `dialsdesc:"max time in the future to allow a value pulled in via a Peek request have their expiration"`
PeekedValueTTLJitter time.Duration `dialsdesc:"max interval by to reduce the TTL by from PeekedValueMaxTTL"`
}
PeekPeerCfg provides tuning parameters Peeking behavior, when configured.
func (*PeekPeerCfg) Verify ¶ added in v1.3.0
func (p *PeekPeerCfg) Verify() error
Verify implements the github.com/vimeo/dials.VerifiedConfig interface
type Peer ¶
type Peer struct {
// Unique ID for this peer (e.g. in k8s may be a pod name)
ID string
// URI or URL that the registered PeerFetcher can connect to
// URI should be a valid base URL,
// for example "example.net:8000" or "10.32.54.231:8123".
URI string
}
Peer is an ID and ip:port/url tuple for a specific peer
type PeerPicker ¶
type PeerPicker struct {
// contains filtered or unexported fields
}
PeerPicker is in charge of dealing with peers: it contains the hashing options (hash function and number of replicas), consistent hash map of peers, and a map of RemoteFetchers to those peers
type RemoteFetcher ¶
type RemoteFetcher interface {
Fetch(context context.Context, galaxy string, key string) ([]byte, error)
Peek(context context.Context, galaxy string, key string) ([]byte, error)
// Close closes a client-side connection (may be a nop)
Close() error
}
RemoteFetcher is the interface that must be implemented to fetch from other peers; the PeerPicker contains a map of these fetchers corresponding to each other peer address
type RemoteFetcherWithInfo ¶ added in v1.4.0
type RemoteFetcherWithInfo interface {
RemoteFetcher
FetchWithInfo(context context.Context, galaxy string, key string) ([]byte, BackendGetInfo, error)
PeekWithInfo(context context.Context, galaxy string, key string) ([]byte, BackendGetInfo, error)
}
RemoteFetcherWithInfo is an extension of RemoteFetcher, allowing RemoteFetcher implementations to optionally provide BackendGetInfo. (the zero-value is assumed otherwise)
type StringCodec ¶
type StringCodec string
StringCodec is a string type that implements Codec
func (*StringCodec) MarshalBinary ¶
func (c *StringCodec) MarshalBinary() ([]byte, error)
MarshalBinary on a StringCodec returns the bytes underlying the string
func (*StringCodec) UnmarshalBinary ¶
func (c *StringCodec) UnmarshalBinary(data []byte) error
UnmarshalBinary on a StringCodec sets the StringCodec to a stringified copy of the provided data
type TrivialNotFoundErr ¶ added in v1.3.0
type TrivialNotFoundErr struct{}
TrivialNotFoundErr is an error-type that can be wrapped to mark the error as a not-found. (and unwrap to NotFoundErr)
func (TrivialNotFoundErr) Error ¶ added in v1.3.0
func (TrivialNotFoundErr) Error() string
Error implements error
func (TrivialNotFoundErr) IsNotFound ¶ added in v1.3.0
func (TrivialNotFoundErr) IsNotFound()
IsNotFound implements NotFoundErr
type Universe ¶
type Universe struct {
// contains filtered or unexported fields
}
Universe defines the primary container for all galaxycache operations. It contains the galaxies and PeerPicker
func NewUniverse ¶
func NewUniverse(protocol FetchProtocol, selfID string, opts ...UniverseOpt) *Universe
NewUniverse is the main constructor for the Universe object. It is passed a FetchProtocol (to specify fetching via GRPC or HTTP) and its own URL along with options.
func NewUniverseWithOpts ¶
func NewUniverseWithOpts(protocol FetchProtocol, selfID string, options *HashOptions) *Universe
NewUniverseWithOpts is a deprecated constructor for the Universe object that defines a non-default hash function and number of replicas. Deprecated: Please use `NewUniverse` with the `WithHashOpts` option instead.
func (*Universe) AddPeer ¶
AddPeer updates the Universe's list of peers to include the passed peer (contained in the PeerPicker). The Peer's URI value should be a valid base URL as understood by the RemoteFetcher implementation, while the ID may be anything that's unique, for example "example.net:8000" (However, in k8s, it's recommended to use a pod name (possibly with some qualification)). If Set, SetPeers and AddPeer calls are mixed, the ID and URI fields must match.
func (*Universe) GetGalaxy ¶
GetGalaxy returns the named galaxy previously created with NewGalaxy, or nil if there's no such galaxy.
func (*Universe) IncludeSelf ¶ added in v1.1.1
IncludeSelf returns a bool indicating whether the "self ID" for the universe is currently included in the PeerPicker's hash-ring This is generally not useful oustide of tests that need to verify whether events are being handled correctly.
func (*Universe) ListPeers ¶
func (universe *Universe) ListPeers() map[string]RemoteFetcher
ListPeers returns a map of remote fetchers keyed by Peer ID, useful for testing incremental changes to galaxycache peers.
func (*Universe) NewGalaxy ¶
func (universe *Universe) NewGalaxy(name string, cacheBytes int64, getter BackendGetter, opts ...GalaxyOption) *Galaxy
NewGalaxy creates a coordinated galaxy-aware BackendGetter from a BackendGetter.
The returned Galaxy tries (but does not guarantee) to run only one [BackendGetter.Get] call for a given key across an entire set of peer processes. Concurrent callers both in the local process and in other processes receive copies of the answer once the original Get completes.
The galaxy name must be unique for each BackendGetter.
func (*Universe) NewGalaxyWithBackendInfo ¶ added in v1.4.0
func (universe *Universe) NewGalaxyWithBackendInfo(name string, cacheBytes int64, getter BackendGetterWithInfo, opts ...GalaxyOption) *Galaxy
NewGalaxyWithBackendInfo creates a coordinated galaxy-aware BackendGetter from a BackendGetterWithInfo.
The returned Galaxy tries (but does not guarantee) to run only one [BackendGetterWithInfo.GetWithInfo] call for a given key across an entire set of peer processes. Concurrent callers both in the local process and in other processes receive copies of the answer once the original Get completes.
The galaxy name must be unique for each BackendGetter.
func (*Universe) RemovePeers ¶
RemovePeers updates the Universe's list of peers to remove the passed peers IDs (contained in the PeerPicker). The arguments should match the ID field on SetPeers and AddPeers calls and the URLs passed to Set. unrecognized IDs are ignored
func (*Universe) SelfID ¶ added in v1.1.1
SelfID returns the selfID that was passed to the constructor and is used for self-identification in the hash-ring.
func (*Universe) Set ¶
Set updates the Universe's list of peers (contained in the PeerPicker). Each PeerURL value should be a valid base URL, for example "example.net:8000". This is a compatibility wrapper around SetPeers which sets the ID and URI equal.
func (*Universe) SetIncludeSelf ¶
SetIncludeSelf toggles the inclusion of the "self ID" for the universe in the PeerPicker's hash-ring
func (*Universe) SetPeers ¶
SetPeers updates the Universe's list of peers (contained in the PeerPicker). Each Peer's URI value should be a valid base URL, while the ID may be anything that's unique, for example "example.net:8000". If AddPeer, Set and SetPeers are mixed, the ID and URI fields must match.
type UniverseOpt ¶
type UniverseOpt func(*universeOpts)
UniverseOpt is a functional Universe option.
func WithHashOpts ¶
func WithHashOpts(hashOpts *HashOptions) UniverseOpt
WithHashOpts sets the HashOptions on a universe.
func WithRecorder ¶
func WithRecorder(recorder stats.Recorder) UniverseOpt
WithRecorder allows you to override the default stats.Recorder used for stats.
func WithUniversalClock ¶ added in v1.3.0
func WithUniversalClock(clock clocks.Clock) UniverseOpt
WithUniversalClock specifices a clock to use at the universe level (and for galaxies to inherit by default)
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cachekey defines several helper functions for building up and decoding keys for use by clients of galaxycache.
|
Package cachekey defines several helper functions for building up and decoding keys for use by clients of galaxycache. |
|
compattest
|
|
|
peercfg
module
|
|
|
Package consistenthash provides an implementation of a ring hash.
|
Package consistenthash provides an implementation of a ring hash. |
|
chtest
Package chtest provides some helper hash-functions for use with the parent consistenthash package (and galaxycache) to provide particular owners for specific keys.
|
Package chtest provides some helper hash-functions for use with the parent consistenthash package (and galaxycache) to provide particular owners for specific keys. |
|
Package jsoncodec provides some helpful wrappers and a core Codec implementation to make using JSON payloads easy within systems using Galaxycache.
|
Package jsoncodec provides some helpful wrappers and a core Codec implementation to make using JSON payloads easy within systems using Galaxycache. |
|
k8swatch
module
|
|
|
Package lru implements an LRU cache.
|
Package lru implements an LRU cache. |
|
expiry
Package expiry provides a type-safe heap implementation that's specialized for handling expiring cache-entries.
|
Package expiry provides a type-safe heap implementation that's specialized for handling expiring cache-entries. |
|
Package singleflight provides a duplicate function call suppression mechanism.
|
Package singleflight provides a duplicate function call suppression mechanism. |
