Documentation ¶
Index ¶
- Constants
- type Option
- func WithConvictionThreshold(convictionThreshold float64) Option
- func WithInterval(interval time.Duration) Option
- func WithLogger(logger *zap.Logger) Option
- func WithMaxMessageSize(size int) Option
- func WithOnJoin(cb func(peerAddr string)) Option
- func WithOnLeave(cb func(peerAddr string)) Option
- func WithOnUpdate(cb func(peerAddr string, key string, value string)) Option
- func WithSeedCB(seedCB func() []string) Option
- type Options
- type Scuttlebutt
Constants ¶
const ( DefaultMaxMessageSize = 512 DefaultConvictionThreshold = 8.0 DefaultInterval = time.Millisecond * 500 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Options)
func WithConvictionThreshold ¶
func WithInterval ¶
func WithLogger ¶
func WithMaxMessageSize ¶
func WithOnJoin ¶
func WithOnLeave ¶
func WithSeedCB ¶
type Options ¶
type Options struct { // SeedCB is a callback that returns a list of seed addresses to use to // join the cluster. This will be called whenever the node does not know // about any other nodes in the cluster. If nil the node will not attempt // to seed and must wait for the other nodes to contact it instead. SeedCB func() []string // OnJoin is invoked when a peer joins the cluster. OnJoin func(peerAddr string) // OnLeave is invoked when a peer leaves the cluster or is considered // inactive. OnLeave func(peerAddr string) // OnUpdate is invoked when a peers state is updated. OnUpdate func(peerAddr string, key string, value string) // MaxMessageSize is the maximum allowed UDP payload for gossip messages. // If the MTU is known this should be increased to the maximum size. If not // set default to 512 bytes. MaxMessageSize int // ConvictionThreshold is the value if phi in the failure detector to // consider a node down. If not set defaults to 8.0. ConvictionThreshold float64 // Interval is the time between gossip rounds, when the node selects // a random peer to sync with. // If not set defaults to 500ms. Interval time.Duration Logger *zap.Logger }
type Scuttlebutt ¶
type Scuttlebutt struct {
// contains filtered or unexported fields
}
Scuttlebutt handles cluster membership using the scuttlebutt protocol. This is thread safe.
func Create ¶
func Create(addr string, options ...Option) (*Scuttlebutt, error)
Create will create a new Scuttlebutt using the given configuration. This will start listening on the network to allow other nodes to join, though will not attempt to join the cluster itself unless contacted by another node. After this the given configuration should not be modified again.
func (*Scuttlebutt) Addrs ¶
func (s *Scuttlebutt) Addrs() []string
Addrs returns the addresses of the peers known by this node (including ourselves).
func (*Scuttlebutt) BindAddr ¶
func (s *Scuttlebutt) BindAddr() string
BindAddr returns the address the transport listener is bound to. Note this may be different from the configured bind addr if the system chooses the addr (such as using a port of 0).
func (*Scuttlebutt) Lookup ¶
func (s *Scuttlebutt) Lookup(addr string, key string) (string, bool)
Lookup looks up the given key in the known state of the peer with the address. Since the cluster state is eventually consistent, this isn't guaranteed to be up to date with the actual state of the peer, though should converge quickly.
func (*Scuttlebutt) Shutdown ¶
func (s *Scuttlebutt) Shutdown() error
Shutdown closes all background networking and stops gossiping its state to the cluster.
func (*Scuttlebutt) UpdateLocal ¶
func (s *Scuttlebutt) UpdateLocal(key string, value string)
UpdateLocal updates this nodes state with the given key-value pair. This will be propagated to the other nodes in the cluster.