raftmembership

package module
v0.0.0-...-3846634 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 13, 2018 License: Apache-2.0 Imports: 3 Imported by: 0

README

raft-membership Build Status Coverage Status Go Report Card GoDoc

This repository provides the raftmembership package, which contains an extensions of the raft Go package from Hashicorp to easily make a node join or leave a cluster.

Documentation

The documentation for this package can be found on Godoc.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleChangeRequests

func HandleChangeRequests(r *raft.Raft, requests <-chan *ChangeRequest)

HandleChangeRequests processes ChangeRequest's received through the given channel, using the given raft.Raft instance to add or remove peers to the cluster according to the received requests.

Types

type ChangeRequest

type ChangeRequest struct {
	// contains filtered or unexported fields
}

ChangeRequest represents a request to change a server's membership in a raft cluster (either join or leave).

A requesting server uses an implementation of the membership Changer interface to connect to a target server through some network transport layer and to ask to join or leave the target server's cluster. The target server internally uses ChangeRequest and HandleChangeRequests as helpers to implement handlers to process such requests coming from the network transport layer.

func NewJoinRequest

func NewJoinRequest(id raft.ServerID, address raft.ServerAddress) *ChangeRequest

NewJoinRequest creates a new membership ChangeRequest to join a cluster.

func NewLeaveRequest

func NewLeaveRequest(id raft.ServerID) *ChangeRequest

NewLeaveRequest creates a new membership ChangeRequest to leave a cluster.

func (*ChangeRequest) Address

func (r *ChangeRequest) Address() raft.ServerAddress

Address of the server requesting to change its membership.

func (*ChangeRequest) Done

func (r *ChangeRequest) Done(err error)

Done should be invoked by the code handling this request (such as HandleChangeRequests) to notify callers that the it has been processed, either successfully or not.

func (*ChangeRequest) Error

func (r *ChangeRequest) Error(timeout time.Duration) error

Error blocks until this ChangeRequest is fully processed or the given timeout is reached and returns any error hit while handling the request, or nil if none was met.

func (*ChangeRequest) ID

func (r *ChangeRequest) ID() raft.ServerID

ID of the server requesting to change its membership.

func (*ChangeRequest) Kind

func (r *ChangeRequest) Kind() ChangeRequestKind

Kind is the type of membership change requested, either join leave.

type ChangeRequestKind

type ChangeRequestKind int

ChangeRequestKind is kind of membership change being requested.

const (
	JoinRequest ChangeRequestKind = iota
	LeaveRequest
)

Possible values for ChangeRequestKind

func (ChangeRequestKind) String

func (k ChangeRequestKind) String() string

type Changer

Changer is an API that can be used by a raft server to change its membership in a cluster (i.e. either join it or leave it).

It works by using some transport layer (e.g. HTTP, TCP, etc) to send a membership change request to a target server that is part of the cluster and that can handle such requests, possibly redirecting the requesting server to another server (e.g. the cluster leader).

It is effectively an extensions of the raft.Transport interface, with additional semantics for joining/leaving a raft cluster.

type ErrDifferentLeader

type ErrDifferentLeader struct {
	// contains filtered or unexported fields
}

ErrDifferentLeader is returned by ChangeRequest.Error() when the request to join or leave a cluster failed because the target peer is not the leader. The network address of the leader as currently known by the target peer is attached to the error, so clients can perform again the request, this time using the given leader address as target peer.

func (*ErrDifferentLeader) Error

func (e *ErrDifferentLeader) Error() string

func (*ErrDifferentLeader) Leader

func (e *ErrDifferentLeader) Leader() string

Leader is the address of the leader as currently known.

type ErrUnknownLeader

type ErrUnknownLeader struct{}

ErrUnknownLeader is returned by ChangeRequest.Error() when the request to join or leave a cluster failed because the target peer is not the leader, and at the moment it also does not know the address of the leader (this can happen for example during leader elections). Clients typically want to retry after a short time.

func (*ErrUnknownLeader) Error

func (e *ErrUnknownLeader) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL