Categorygithub.com/hashicorp/memberlist
modulepackage
0.5.3
Repository: https://github.com/hashicorp/memberlist.git
Documentation: pkg.go.dev

# README

memberlist GoDoc CircleCI

memberlist is a Go library that manages cluster membership and member failure detection using a gossip based protocol.

The use cases for such a library are far-reaching: all distributed systems require membership, and memberlist is a re-usable solution to managing cluster membership and node failure detection.

memberlist is eventually consistent but converges quickly on average. The speed at which it converges can be heavily tuned via various knobs on the protocol. Node failures are detected and network partitions are partially tolerated by attempting to communicate to potentially dead nodes through multiple routes.

Building

If you wish to build memberlist you'll need Go version 1.2+ installed.

Please check your installation with:

go version

Usage

Memberlist is surprisingly simple to use. An example is shown below:

/* Create the initial memberlist from a safe configuration.
   Please reference the godoc for other default config types.
   http://godoc.org/github.com/hashicorp/memberlist#Config
*/
list, err := memberlist.Create(memberlist.DefaultLocalConfig())
if err != nil {
	panic("Failed to create memberlist: " + err.Error())
}

// Join an existing cluster by specifying at least one known member.
n, err := list.Join([]string{"1.2.3.4"})
if err != nil {
	panic("Failed to join cluster: " + err.Error())
}

// Ask for members of the cluster
for _, member := range list.Members() {
	fmt.Printf("Member: %s %s\n", member.Name, member.Addr)
}

// Continue doing whatever you need, memberlist will maintain membership
// information in the background. Delegates can be used for receiving
// events when members join or leave.

The most difficult part of memberlist is configuring it since it has many available knobs in order to tune state propagation delay and convergence times. Memberlist provides a default configuration that offers a good starting point, but errs on the side of caution, choosing values that are optimized for higher convergence at the cost of higher bandwidth usage.

For complete documentation, see the associated Godoc.

Protocol

memberlist is based on "SWIM: Scalable Weakly-consistent Infection-style Process Group Membership Protocol". However, we extend the protocol in a number of ways:

  • Several extensions are made to increase propagation speed and convergence rate.
  • Another set of extensions, that we call Lifeguard, are made to make memberlist more robust in the presence of slow message processing (due to factors such as CPU starvation, and network delay or loss).

For details on all of these extensions, please read our paper "Lifeguard : SWIM-ing with Situational Awareness", along with the memberlist source. We welcome any questions related to the protocol on our issue tracker.

Metrics Emission and Compatibility

This library can emit metrics using either github.com/armon/go-metrics or github.com/hashicorp/go-metrics. Choosing between the libraries is controlled via build tags.

Build Tags

  • armonmetrics - Using this tag will cause metrics to be routed to armon/go-metrics
  • hashicorpmetrics - Using this tag will cause all metrics to be routed to hashicorp/go-metrics

If no build tag is specified, the default behavior is to use armon/go-metrics.

Deprecating armon/go-metrics

Emitting metrics to armon/go-metrics is officially deprecated. Usage of armon/go-metrics will remain the default until mid-2025 with opt-in support continuing to the end of 2025.

Migration To migrate an application currently using the older armon/go-metrics to instead use hashicorp/go-metrics the following should be done.

  1. Upgrade libraries using armon/go-metrics to consume hashicorp/go-metrics/compat instead. This should involve only changing import statements. All repositories in the hashicorp namespace
  2. Update an applications library dependencies to those that have the compatibility layer configured.
  3. Update the application to use hashicorp/go-metrics for configuring metrics export instead of armon/go-metrics
    • Replace all application imports of github.com/armon/go-metrics with github.com/hashicorp/go-metrics
    • Instrument your build system to build with the hashicorpmetrics tag.

Eventually once the default behavior changes to use hashicorp/go-metrics by default (mid-2025), you can drop the hashicorpmetrics build tag.

# Functions

AddLabelHeaderToPacket prefixes outgoing packets with the correct header if the label is not empty.
AddLabelHeaderToStream prefixes outgoing streams with the correct header if the label is not empty.
Create will create a new Memberlist using the given configuration.
DefaultLANConfig returns a sane set of configurations for Memberlist.
DefaultLocalConfig works like DefaultConfig, however it returns a configuration that is optimized for a local loopback environments.
DefaultWANConfig works like DefaultConfig, however it returns a configuration that is optimized for most WAN environments.
No description provided by the author
No description provided by the author
No description provided by the author
NewKeyring constructs a new container for a set of encryption keys.
NewNetTransport returns a net transport with the given configuration.
ParseCIDRs return a possible empty list of all Network that have been parsed In case of error, it returns succesfully parsed CIDRs and the last error found.
RemoveLabelHeaderFromPacket removes any label header from the provided packet and returns it along with the remaining packet contents.
RemoveLabelHeaderFromStream removes any label header from the beginning of the stream if present and returns it along with an updated conn with that header removed.
ValidateKey will check to see if the key is valid and returns an error if not.

# Constants

LabelMaxSize is the maximum length of a packet or stream label.
Maximum size for node meta data.
No description provided by the author
No description provided by the author
No description provided by the author
Version 3 added support for TCP pings but we kept the default protocol version at 2 to ease transition to this new feature.
This is the minimum and maximum protocol version that we can _understand_.
This is the minimum and maximum protocol version that we can _understand_.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
ChannelEventDelegate is used to enable an application to receive events about joins and leaves over a channel instead of a direct function call.
No description provided by the author
No description provided by the author
No description provided by the author
MockAddress is a wrapper which adds the net.Addr interface to our mock address scheme.
MockNetwork is used as a factory that produces MockTransport instances which are uniquely addressed and wired up to talk to each other.
MockTransport directly plumbs messages to other transports its MockNetwork.
NetTransport is a Transport implementation that uses connectionless UDP for packet operations, and ad-hoc TCP connections for stream operations.
NetTransportConfig is used to configure a net transport.
Node represents a node in the cluster.
NodeEvent is a single event related to node activity in the memberlist.
NoPingResponseError is used to indicate a 'ping' packet was successfully issued but no response was received.
Packet is used to provide some metadata about incoming packets from peers over a packet connection, as well as the packet payload.
TransmitLimitedQueue is used to queue messages to broadcast to the cluster (via gossip) but limits the number of transmits per message.

# Interfaces

AliveDelegate is used to involve a client in processing a node "alive" message.
Broadcast is something that can be broadcasted via gossip to the memberlist cluster.
ConflictDelegate is a used to inform a client that a node has attempted to join which would result in a name conflict.
Delegate is the interface that clients must implement if they want to hook into the gossip layer of Memberlist.
EventDelegate is a simpler delegate that is used only to receive notifications about members joining and leaving.
IngestionAwareTransport is not used.
MergeDelegate is used to involve a client in a potential cluster merge operation.
NamedBroadcast is an optional extension of the Broadcast interface that gives each message a unique string name, and that is used to optimize You shoud ensure that Invalidates() checks the same uniqueness as the example below: func (b *foo) Invalidates(other Broadcast) bool { nb, ok := other.(NamedBroadcast) if !ok { return false } return b.Name() == nb.Name() } Invalidates() isn't currently used for NamedBroadcasts, but that may change in the future.
No description provided by the author
PingDelegate is used to notify an observer how long it took for a ping message to complete a round trip.
Transport is used to abstract over communicating with other peers.
UniqueBroadcast is an optional interface that indicates that each message is intrinsically unique and there is no need to scan the broadcast queue for duplicates.

# Type aliases

NodeEventType are the types of events that can be sent from the ChannelEventDelegate.
No description provided by the author