MCPcopy
hub / github.com/hashicorp/memberlist

github.com/hashicorp/memberlist @v0.5.4 sqlite

repository ↗ · DeepWiki ↗ · release v0.5.4 ↗
545 symbols 2,799 edges 40 files 271 documented · 50%
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
  4. Replace all application imports of github.com/armon/go-metrics with github.com/hashicorp/go-metrics
  5. 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.

Extension points exported contracts — how you extend this code

EventDelegate (Interface)
EventDelegate is a simpler delegate that is used only to receive notifications about members joining and leaving. The me [2 …
event_delegate.go
Transport (Interface)
Transport is used to abstract over communicating with other peers. The packet interface is assumed to be best-effort and [2 …
transport.go
Retryer (Interface)
Retryer provides an interface for repeating operations until they succeed or an exit condition is met. [2 implementers]
internal/retry/retry.go
AliveDelegate (Interface)
AliveDelegate is used to involve a client in processing a node "alive" message. When a node joins, either through a UDP [1 …
alive_delegate.go
PingDelegate (Interface)
PingDelegate is used to notify an observer how long it took for a ping message to complete a round trip. It can also be [1 …
ping_delegate.go
ConflictDelegate (Interface)
ConflictDelegate is a used to inform a client that a node has attempted to join which would result in a name conflict. T [1 …
conflict_delegate.go
Broadcast (Interface)
Broadcast is something that can be broadcasted via gossip to the memberlist cluster. [1 implementers]
queue.go
Delegate (Interface)
Delegate is the interface that clients must implement if they want to hook into the gossip layer of Memberlist. All the [1 …
delegate.go

Core symbols most depended-on inside this repo

Fatalf
called by 466
internal/retry/retry.go
Fatal
called by 146
internal/retry/retry.go
Shutdown
called by 141
transport.go
String
called by 136
state.go
Errorf
called by 95
internal/retry/retry.go
aliveNode
called by 76
state.go
Members
called by 60
memberlist.go
Create
called by 59
memberlist.go

Shape

Method 240
Function 229
Struct 56
Interface 15
TypeAlias 5

Languages

Go100%

Modules by API surface

memberlist_test.go74 symbols
state_test.go56 symbols
net.go48 symbols
state.go41 symbols
memberlist.go33 symbols
net_test.go26 symbols
internal/retry/retry.go25 symbols
transport.go24 symbols
queue.go24 symbols
util.go19 symbols
net_transport.go17 symbols
mock_transport.go17 symbols

Dependencies from manifests, versioned

github.com/armon/go-metricsv0.4.1 · 1×
github.com/davecgh/go-spewv1.1.1 · 1×
github.com/google/btreev1.1.3 · 1×
github.com/hashicorp/errwrapv1.1.0 · 1×
github.com/hashicorp/go-immutable-radixv1.0.0 · 1×
github.com/hashicorp/go-metricsv0.5.4 · 1×
github.com/hashicorp/go-msgpack/v2v2.1.5 · 1×
github.com/hashicorp/go-multierrorv1.1.1 · 1×
github.com/hashicorp/go-sockaddrv1.0.7 · 1×
github.com/hashicorp/golang-lruv0.5.0 · 1×
github.com/miekg/dnsv1.1.68 · 1×
github.com/pmezard/go-difflibv1.0.0 · 1×

For agents

$ claude mcp add memberlist \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact