Documentation
¶
Overview ¶
Package gossipcache provides a Gossip powered groupcache
Index ¶
- Constants
- func InferCacheBaseURL(cfg *memberlist.Config) (string, error)
- func NewGossipTransport(conf *Config) (memberlist.Transport, *transport.Config, error)
- func NewGossipTransportConfig(conf *Config) (*transport.Config, error)
- func NewMemberlistLogger(l slog.Logger) *log.Logger
- func PrepareCacheBaseURL(s string) (string, error)
- func SetMemberlistLogger(cfg *memberlist.Config, l slog.Logger) error
- type Cluster
- type ClusterConfigOption
- func WithAddress(host string) ClusterConfigOption
- func WithAliveDelegate(handler func(*Cluster, *memberlist.Node) error) ClusterConfigOption
- func WithConflictDelegate(handler func(*Cluster, *memberlist.Node, *memberlist.Node)) ClusterConfigOption
- func WithDefaultLANConfig() ClusterConfigOption
- func WithDefaultLocalConfig() ClusterConfigOption
- func WithDefaultWANConfig() ClusterConfigOption
- func WithDelegateProtocolVersion(version, min, max uint8) ClusterConfigOption
- func WithEventDelegate(handler func(*Cluster, *memberlist.Node, memberlist.NodeEventType)) ClusterConfigOption
- func WithGetBroadcastDelegate(handler func(*Cluster, int, int) [][]byte) ClusterConfigOption
- func WithGossipAdvertise(host string, port int16) ClusterConfigOption
- func WithGossipKey(salt string, key []byte) ClusterConfigOption
- func WithGossipKeyBase64(salt, key string) ClusterConfigOption
- func WithGossipLogger(logger slog.Logger) ClusterConfigOption
- func WithGossipPort(port int16) ClusterConfigOption
- func WithLocalStateDelegate(handler func(*Cluster, bool) []byte) ClusterConfigOption
- func WithMergeDelegate(handler func(*Cluster, []*memberlist.Node) error) ClusterConfigOption
- func WithMergeRemoteStateDelegate(handler func(*Cluster, []byte, bool)) ClusterConfigOption
- func WithNodeMetaDelegate(handler func(cluster *Cluster, limit int) []byte) ClusterConfigOption
- func WithNotifyMsgDelegate(handler func(cluster *Cluster, userData []byte)) ClusterConfigOption
- func WithPingDelegate(payload []byte, ...) ClusterConfigOption
- func WithTransport(transport memberlist.Transport) ClusterConfigOption
- type ClusterDelegate
- func (cd *ClusterDelegate) AckPayload() []byte
- func (cd *ClusterDelegate) GetBroadcasts(overhead, limit int) [][]byte
- func (cd *ClusterDelegate) LocalState(join bool) []byte
- func (cd *ClusterDelegate) MergeRemoteState(buf []byte, join bool)
- func (cd *ClusterDelegate) NodeMeta(limit int) []byte
- func (cd *ClusterDelegate) NotifyAlive(peer *memberlist.Node) error
- func (cd *ClusterDelegate) NotifyConflict(existing, other *memberlist.Node)
- func (cd *ClusterDelegate) NotifyJoin(node *memberlist.Node)
- func (cd *ClusterDelegate) NotifyLeave(node *memberlist.Node)
- func (cd *ClusterDelegate) NotifyMerge(peers []*memberlist.Node) error
- func (cd *ClusterDelegate) NotifyMsg(userData []byte)
- func (cd *ClusterDelegate) NotifyPingComplete(peer *memberlist.Node, rtt time.Duration, payload []byte)
- func (cd *ClusterDelegate) NotifyUpdate(node *memberlist.Node)
- type Config
- type GossipCache
Constants ¶
const ( // DefaultCacheBasePath is the default Path under the CacheBaseURL for the groupcache DefaultCacheBasePath = "/_groupcache/" // DefaultCacheReplicas indicated the default number of replicas for the groupcache DefaultCacheReplicas = 50 )
Variables ¶
This section is empty.
Functions ¶
func InferCacheBaseURL ¶ added in v0.4.0
func InferCacheBaseURL(cfg *memberlist.Config) (string, error)
InferCacheBaseURL produces a CacheBaseURL pointing to https on 443/tcp of Transport's AdveriseAddr
func NewGossipTransport ¶ added in v0.4.0
NewGossipTransport creates a transport.Transport from a Config
func NewGossipTransportConfig ¶ added in v0.4.0
NewGossipTransportConfig creates a transport.Config from a Config
func NewMemberlistLogger ¶
NewMemberlistLogger creates a standard logger to consume memberlist logs
func PrepareCacheBaseURL ¶ added in v0.4.0
PrepareCacheBaseURL sanitises a CacheBaseURL value
func SetMemberlistLogger ¶
func SetMemberlistLogger(cfg *memberlist.Config, l slog.Logger) error
SetMemberlistLogger sets a memberlist.Config to use a given slog.Logger
Types ¶
type Cluster ¶
type Cluster struct {
// contains filtered or unexported fields
}
Cluster implements a memberlist for GossipCache
func NewCluster ¶
func NewCluster(conf *memberlist.Config, options ...ClusterConfigOption) (*Cluster, error)
NewCluster creates a new memberlist cluster for GossipCache
func Prepare ¶
func Prepare(conf *memberlist.Config, options ...ClusterConfigOption) ( *Cluster, *memberlist.Config, error)
Prepare prepares a Cluster to be created
type ClusterConfigOption ¶
type ClusterConfigOption func(*Cluster, *memberlist.Config) error
ClusterConfigOption is used to adjust the memberlist.Config before creating the cluster
func WithAddress ¶
func WithAddress(host string) ClusterConfigOption
WithAddress creates a configuration option to set a specific binding address
func WithAliveDelegate ¶
func WithAliveDelegate(handler func(*Cluster, *memberlist.Node) error) ClusterConfigOption
WithAliveDelegate sets a callback to be invoked when a message about a live node is received from the network. Returning a non-nil error prevents the node from being considered a peer
func WithConflictDelegate ¶
func WithConflictDelegate(handler func(*Cluster, *memberlist.Node, *memberlist.Node)) ClusterConfigOption
WithConflictDelegate sets a callback to receive notifications about an attempt to join with a name already in use
func WithDefaultLANConfig ¶
func WithDefaultLANConfig() ClusterConfigOption
WithDefaultLANConfig sets the cluster configuration to the default recommended by memberlist for local network environments
func WithDefaultLocalConfig ¶
func WithDefaultLocalConfig() ClusterConfigOption
WithDefaultLocalConfig sets the cluster configuration to the default recommended by memberlist for local loopback environments
func WithDefaultWANConfig ¶
func WithDefaultWANConfig() ClusterConfigOption
WithDefaultWANConfig sets the cluster configuration to the default recommended by memberlist for WAN environments
func WithDelegateProtocolVersion ¶
func WithDelegateProtocolVersion(version, min, max uint8) ClusterConfigOption
WithDelegateProtocolVersion sets the Protocol versions we handle
func WithEventDelegate ¶
func WithEventDelegate(handler func(*Cluster, *memberlist.Node, memberlist.NodeEventType)) ClusterConfigOption
WithEventDelegate sets a callback to receive notifications about members joining and leaving
func WithGetBroadcastDelegate ¶
func WithGetBroadcastDelegate(handler func(*Cluster, int, int) [][]byte) ClusterConfigOption
WithGetBroadcastDelegate sets a callback to retrieve a list of buffers to broadcast
func WithGossipAdvertise ¶
func WithGossipAdvertise(host string, port int16) ClusterConfigOption
WithGossipAdvertise creates a configuration option for the Node to advertise different address/port than the one it's locally bound to
func WithGossipKey ¶
func WithGossipKey(salt string, key []byte) ClusterConfigOption
WithGossipKey creates a configuration option for the cluster's encryption
func WithGossipKeyBase64 ¶
func WithGossipKeyBase64(salt, key string) ClusterConfigOption
WithGossipKeyBase64 creates a configuration option for the cluster's encryption
func WithGossipLogger ¶
func WithGossipLogger(logger slog.Logger) ClusterConfigOption
WithGossipLogger creates a configuration option for the Node to use a given slog.Logger
func WithGossipPort ¶
func WithGossipPort(port int16) ClusterConfigOption
WithGossipPort creates a configuration option to set a specific TCP/UDP port for the Gossip Node
func WithLocalStateDelegate ¶
func WithLocalStateDelegate(handler func(*Cluster, bool) []byte) ClusterConfigOption
WithLocalStateDelegate sets a callback to send the LocalState to a remote. The 'join' boolean indicates this is for a join instead of a push/pull
func WithMergeDelegate ¶
func WithMergeDelegate(handler func(*Cluster, []*memberlist.Node) error) ClusterConfigOption
WithMergeDelegate sets a callback when a merge operation could take place. If the return value is non-nil, the merge is canceled.
func WithMergeRemoteStateDelegate ¶
func WithMergeRemoteStateDelegate(handler func(*Cluster, []byte, bool)) ClusterConfigOption
WithMergeRemoteStateDelegate sets a callback to receive the LocalState of a remote. The 'join' boolean indicates this is for a join instead of a push/pull
func WithNodeMetaDelegate ¶
func WithNodeMetaDelegate(handler func(cluster *Cluster, limit int) []byte) ClusterConfigOption
WithNodeMetaDelegate sets a callback to provide information about the current node
func WithNotifyMsgDelegate ¶
func WithNotifyMsgDelegate(handler func(cluster *Cluster, userData []byte)) ClusterConfigOption
WithNotifyMsgDelegate sets a callback for received user-data
func WithPingDelegate ¶
func WithPingDelegate(payload []byte, completed func(*Cluster, *memberlist.Node, time.Duration, []byte)) ClusterConfigOption
WithPingDelegate sets a callback to notify an observer how long it took for a ping message to complete a round trip.
It can also be used for writing arbitrary byte slices into ack messages
func WithTransport ¶
func WithTransport(transport memberlist.Transport) ClusterConfigOption
WithTransport creates a configuration option to set the cluster's transport
type ClusterDelegate ¶
type ClusterDelegate struct {
// contains filtered or unexported fields
}
ClusterDelegate hooks handlers into the Memberlist Cluster life cycle
func (*ClusterDelegate) AckPayload ¶
func (cd *ClusterDelegate) AckPayload() []byte
AckPayload is invoked when an ack is being sent; the returned bytes will be appended to the ack
func (*ClusterDelegate) GetBroadcasts ¶
func (cd *ClusterDelegate) GetBroadcasts(overhead, limit int) [][]byte
GetBroadcasts is called when user data messages can be broadcast.
func (*ClusterDelegate) LocalState ¶
func (cd *ClusterDelegate) LocalState(join bool) []byte
LocalState is used for a TCP Push/Pull
func (*ClusterDelegate) MergeRemoteState ¶
func (cd *ClusterDelegate) MergeRemoteState(buf []byte, join bool)
MergeRemoteState is invoked after a TCP Push/Pull
func (*ClusterDelegate) NodeMeta ¶
func (cd *ClusterDelegate) NodeMeta(limit int) []byte
NodeMeta is used to retrieve meta-data about the current node when broadcasting an alive message
func (*ClusterDelegate) NotifyAlive ¶
func (cd *ClusterDelegate) NotifyAlive(peer *memberlist.Node) error
NotifyAlive is invoked when a message about a live node is received from the network
func (*ClusterDelegate) NotifyConflict ¶
func (cd *ClusterDelegate) NotifyConflict(existing, other *memberlist.Node)
NotifyConflict is invoked when a name conflict is detected
func (*ClusterDelegate) NotifyJoin ¶
func (cd *ClusterDelegate) NotifyJoin(node *memberlist.Node)
NotifyJoin is invoked when a node is detected to have joined.
func (*ClusterDelegate) NotifyLeave ¶
func (cd *ClusterDelegate) NotifyLeave(node *memberlist.Node)
NotifyLeave is invoked when a node is detected to have left.
func (*ClusterDelegate) NotifyMerge ¶
func (cd *ClusterDelegate) NotifyMerge(peers []*memberlist.Node) error
NotifyMerge is invoked when a merge could take place.
func (*ClusterDelegate) NotifyMsg ¶
func (cd *ClusterDelegate) NotifyMsg(userData []byte)
NotifyMsg is called when a user-data message is received.
func (*ClusterDelegate) NotifyPingComplete ¶
func (cd *ClusterDelegate) NotifyPingComplete(peer *memberlist.Node, rtt time.Duration, payload []byte)
NotifyPingComplete is invoked when an ack for a ping is received
func (*ClusterDelegate) NotifyUpdate ¶
func (cd *ClusterDelegate) NotifyUpdate(node *memberlist.Node)
NotifyUpdate is invoked when a node is detected to have
type Config ¶ added in v0.4.0
type Config struct { // Context Context context.Context // Logger is an optional logger to bind to memberlist and groupcache Logger slog.Logger // Transport is the Cluster's transport configuration Transport *transport.Config // Memberlist is the Cluster's configuration Memberlist *memberlist.Config // CacheReplicas is the number of replicas in the groupcache. // If zero or negative it will be set to DefaultCacheReplicas CacheReplicas int // CacheBaseURL is the base of the advertised URL for the groupcache. // Path and Query string components will be ignored CacheBaseURL string // CacheBasePath is the path under the CacheBaseURL where the groupcache // handler is mounted CacheBasePath string // ClientTLSConfig is the tls.Config to be used when connecting to other // nodes of the cluster when https scheme is used ClientTLSConfig *tls.Config }
Config represents the configuration used to setup the GossipCache node
func (*Config) SetDefaults ¶ added in v0.4.0
SetDefaults populates Config with defaults, except for CacheBaseURL which we will attempt to populate after memberlist is prepared
type GossipCache ¶ added in v0.4.0
type GossipCache struct {
*groupcache.HTTPPool
}
GossipCache is a groupcache cluster managed using memberlist