Documentation ¶
Overview ¶
Ringman implements a consistent hash ring for service sharding, backed either by Hashicorp's Memberlist directly, or by Sidecar service discovery platform. It maintains state about which nodes are available in a cluster and can be queried for a node to match a hash key.
Index ¶
- Constants
- Variables
- type Delegate
- func (d *Delegate) GetBroadcasts(overhead, limit int) [][]byte
- func (d *Delegate) LocalState(join bool) []byte
- func (d *Delegate) MergeRemoteState(buf []byte, join bool)
- func (d *Delegate) NodeMeta(limit int) []byte
- func (d *Delegate) NotifyJoin(node *memberlist.Node)
- func (d *Delegate) NotifyLeave(node *memberlist.Node)
- func (d *Delegate) NotifyMsg(message []byte)
- func (d *Delegate) NotifyUpdate(node *memberlist.Node)
- type HashRingManager
- func (r *HashRingManager) AddNode(nodeName string) error
- func (r *HashRingManager) GetNode(key string) (string, error)
- func (r *HashRingManager) Pending() int
- func (r *HashRingManager) Ping() bool
- func (r *HashRingManager) RemoveNode(nodeName string) error
- func (r *HashRingManager) Run(looper director.Looper) error
- func (r *HashRingManager) Stop()
- type LoggingBridge
- type MemberlistRing
- func (r *MemberlistRing) HttpGetNodeHandler(w http.ResponseWriter, req *http.Request)
- func (r *MemberlistRing) HttpListNodesHandler(w http.ResponseWriter, req *http.Request)
- func (r *MemberlistRing) HttpMux() *http.ServeMux
- func (r *MemberlistRing) Manager() *HashRingManager
- func (r *MemberlistRing) Shutdown()
- type NodeMetadata
- type Ring
- type RingCommand
- type RingReply
- type SidecarRing
Constants ¶
const ( CmdAddNode = iota CmdRemoveNode = iota CmdGetNode = iota CmdPing = iota )
const ( CommandChannelLength = 10 // How big a buffer on our mailbox channel? PingTimeout = 5 * time.Millisecond // This should be PLENTY of spare time )
const (
DefaultReceiverCapacity = 50
)
Variables ¶
var (
ErrNilManager error = errors.New("HashRingManager has not been initialized!")
)
Functions ¶
This section is empty.
Types ¶
type Delegate ¶
type Delegate struct { RingMan *HashRingManager // contains filtered or unexported fields }
Delegate is a Memberlist delegate that is responsible for handling integration between the hash ring and Memberlist messages. See the Memberlist documentation for detailed explanations of the callback methods.
func NewDelegate ¶
func NewDelegate(ringMan *HashRingManager, meta *NodeMetadata) *Delegate
func (*Delegate) GetBroadcasts ¶
func (*Delegate) LocalState ¶
func (*Delegate) MergeRemoteState ¶
func (*Delegate) NotifyJoin ¶
func (d *Delegate) NotifyJoin(node *memberlist.Node)
func (*Delegate) NotifyLeave ¶
func (d *Delegate) NotifyLeave(node *memberlist.Node)
func (*Delegate) NotifyUpdate ¶
func (d *Delegate) NotifyUpdate(node *memberlist.Node)
type HashRingManager ¶
type HashRingManager struct { HashRing *hashring.HashRing // contains filtered or unexported fields }
func NewHashRingManager ¶
func NewHashRingManager(nodeList []string) *HashRingManager
NewHashRingManager returns a properly configured HashRingManager. It accepts zero or mode nodes to initialize the ring with.
func (*HashRingManager) AddNode ¶
func (r *HashRingManager) AddNode(nodeName string) error
AddNode is a blocking call that will send an add message on the message channel for the HashManager.
func (*HashRingManager) GetNode ¶
func (r *HashRingManager) GetNode(key string) (string, error)
GetNode requests a node from the ring to serve the provided key
func (*HashRingManager) Pending ¶
func (r *HashRingManager) Pending() int
Pending returns the number of pending commands in the command channel
func (*HashRingManager) Ping ¶
func (r *HashRingManager) Ping() bool
Ping is a simple ping through the main processing loop with a timeout to make sure this thing is running the background goroutine.
func (*HashRingManager) RemoveNode ¶
func (r *HashRingManager) RemoveNode(nodeName string) error
RemoveNode is a blocking call that will send an add message on the message channel for the HashManager.
func (*HashRingManager) Run ¶
func (r *HashRingManager) Run(looper director.Looper) error
Run runs in a loop over the contents of cmdChan and processes the incoming work. This acts as the synchronization around the HashRing itself which is not mutable and has to be replaced on each command.
func (*HashRingManager) Stop ¶
func (r *HashRingManager) Stop()
Stop the HashRingManager from running. This is currently permanent since the internal cmdChan it closes can't be re-opened.
type LoggingBridge ¶
type LoggingBridge struct {
// contains filtered or unexported fields
}
type MemberlistRing ¶
type MemberlistRing struct { Memberlist *memberlist.Memberlist // contains filtered or unexported fields }
A MemberlistRing is a ring backed by Hashicorp's Memberlist directly. It exchanges gossip messages directly between instances of this service and requires some open ports for them to communicate with each other. The nodes will need to have some seeds provided that allow them to find each other.
func NewDefaultMemberlistRing ¶
func NewDefaultMemberlistRing(clusterSeeds []string, port string) (*MemberlistRing, error)
NewDefaultMemberlistRing returns a MemberlistRing configured using the DefaultLANConfig from the memberlist documentation. clusterSeeds must be 0 or more hosts to seed the cluster with. Note that the ring will be _running_ when returned from this method.
func NewMemberlistRing ¶
func NewMemberlistRing(mlConfig *memberlist.Config, clusterSeeds []string, port string, clusterName string) (*MemberlistRing, error)
NewMemberlistRing configures a MemberlistRing according to the Memberlist configuration specified. clusterSeeds must be 0 or more hosts to seed the cluster with. Note that the ring will be _running_ when returned from this method.
* mlConfig is a memberlist config struct * clusterSeeds are the hostnames of the machines we'll bootstrap from * port is our own service port that the service (not memberist) will use
func (*MemberlistRing) HttpGetNodeHandler ¶
func (r *MemberlistRing) HttpGetNodeHandler(w http.ResponseWriter, req *http.Request)
HttpGetNodeHandler is an http.Handler that will return an object containing the node that currently owns a specific key.
func (*MemberlistRing) HttpListNodesHandler ¶
func (r *MemberlistRing) HttpListNodesHandler(w http.ResponseWriter, req *http.Request)
HttpListNodesHandler is an http.Handler that will return a JSON-encoded list of the Memberlist nodes in the current ring.
func (*MemberlistRing) HttpMux ¶
func (r *MemberlistRing) HttpMux() *http.ServeMux
HttpMux returns an http.ServeMux configured to run the HTTP handlers on the MemberlistRing. You can either use this one, or mount the handlers on a mux of your own choosing (e.g. Gorilla mux or httprouter)
func (*MemberlistRing) Manager ¶
func (r *MemberlistRing) Manager() *HashRingManager
func (*MemberlistRing) Shutdown ¶
func (r *MemberlistRing) Shutdown()
Shutdown shuts down the memberlist node and stops the HashRingManager
type NodeMetadata ¶
type NodeMetadata struct {
ServicePort string
}
func DecodeNodeMetadata ¶
func DecodeNodeMetadata(data []byte) (*NodeMetadata, error)
DecodeNodeMetadata takes a byte slice and deserializes it
type Ring ¶
type Ring interface { HttpMux() *http.ServeMux Shutdown() Manager() *HashRingManager }
type RingCommand ¶
type SidecarRing ¶
type SidecarRing struct {
// contains filtered or unexported fields
}
A SidecarRing is a ring backed by service discovery from Sidecar https://github.com/Nitro/sidecar . Sidecar itself uses Memberlist under the covers, but layers a lot more on top. Sidecar takes care of all the work of managing and bootstrapping the cluster so we don't need to know anything about cluster seeds. This service is expected to subscribe to Sidecar events, however, and uses a Sidecar Receiver to process them.
func NewSidecarRing ¶
func NewSidecarRing(sidecarUrl string, svcName string, svcPort int64) (*SidecarRing, error)
NewSidecarRing returns a properly configured SidecarRing that will filter incoming changes by the service name provided and will only watch the ServicePort number passed in. If the SidecarUrl is not empty string, then we will call that address to get initial state on bootstrap.
func (*SidecarRing) HttpGetNodeHandler ¶
func (r *SidecarRing) HttpGetNodeHandler(w http.ResponseWriter, req *http.Request)
HttpGetNodeHandler is an http.Handler that will return an object containing the node that currently owns a specific key.
func (*SidecarRing) HttpListNodesHandler ¶
func (r *SidecarRing) HttpListNodesHandler(w http.ResponseWriter, req *http.Request)
HttpListNodesHandler is an http.Handler that will return a JSON-encoded list of the Sidecar nodes in the current ring.
func (*SidecarRing) HttpMux ¶
func (r *SidecarRing) HttpMux() *http.ServeMux
HttpMux returns an http.ServeMux configured to run the HTTP handlers on the SidecarRing. You can either use this one, or mount the handlers on a mux of your own choosing (e.g. Gorilla mux or httprouter)
func (*SidecarRing) Manager ¶
func (r *SidecarRing) Manager() *HashRingManager
func (*SidecarRing) Shutdown ¶
func (r *SidecarRing) Shutdown()
Shutdown stops the Receiver and the HashringManager