quorum

package module
v0.0.0-...-0034cdf Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2018 License: MIT Imports: 21 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Address which other nodes can reach this one from
	IP string
	// Port to expose HTTP API on
	Port string

	// Config to pass into Memberlist
	MemberlistConfig *memberlist.Config

	// Directory to store persistent raft data
	RaftDir string
	// Port for the raft library to listen on
	RaftPort string
	// Pool size of the underlying TCP Transport layer
	RaftPoolSize int
	// Timeout for each request of the underlying TCP Transport layer
	RaftTimeout time.Duration
	// Number of snapshots to retain
	RaftRetain int
	// Config to pass into Raft
	RaftConfig *raft.Config

	// Interface that will return the set of peers to join. This is also
	// used when trying to rejoin the cluster when we have been removed
	// or we are in split brain.
	PeerFinder PeerFinder

	// If the ratio of memberlist members to raft members is less than or
	// equal to this ratio, we are in split-brain. Typical this is set to
	// 0.5 which allows a majority of nodes to keep operating.
	QuorumRatio float64

	// How often to check the state of the quorum cluster and detect
	// split-brain
	CheckStatePeriod time.Duration
	// How often the leader checks membership info and removes dead servers
	// from the raft configuration
	LeaderLoopPeriod time.Duration
	// Timeout for requests to the cluster using the HTTP API
	APIRequestTimeout time.Duration
	// How long after a node is dead in memberlist do we prune it from the
	// raft group
	PruneDuration time.Duration

	// User specified FSM for the underlying raft layer
	FSM raft.FSM
}

func NewDefaultConfig

func NewDefaultConfig(initialPeerSet []string) (*Config, error)

type DefaultPeerFinder

type DefaultPeerFinder struct {
	InitialPeerSet []string
}

func NewDefaultPeerFinder

func NewDefaultPeerFinder(initialPeerSet []string) *DefaultPeerFinder

func (*DefaultPeerFinder) Peers

func (d *DefaultPeerFinder) Peers() []string

type HTTPApi

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

func NewHTTPApi

func NewHTTPApi(quorumNode *QuorumNode) *HTTPApi

func (*HTTPApi) Join

func (*HTTPApi) Leave

func (h *HTTPApi) Leave(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

func (*HTTPApi) Start

func (h *HTTPApi) Start(router *httprouter.Router)

Register any endpoints to the router

type HTTPClient

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

func NewHTTPClient

func NewHTTPClient() *HTTPClient

func (*HTTPClient) Join

func (d *HTTPClient) Join(ctx context.Context, target string, jreq *JoinRequest) (*JoinResponse, error)

func (*HTTPClient) Leave

func (d *HTTPClient) Leave(ctx context.Context, target string, lreq *LeaveRequest) (*LeaveResponse, error)

type IdMap

type IdMap map[string]string

type JoinRequest

type JoinRequest struct {
	ServerID      string `json:"server_id"`
	ServerAddress string `json:"server_address"`
}

type JoinResponse

type JoinResponse struct {
	OK     bool   `json:"ok"`
	Leader string `json:"leader"`
}

type LeaveRequest

type LeaveRequest struct {
	ServerID string `json:"server_id"`
}

type LeaveResponse

type LeaveResponse struct {
	OK bool `json:"ok"`
}

type Metrics

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

func NewMetrics

func NewMetrics() (*Metrics, error)

NewMetrics returns a populated, and registered *Metrics, or an error.

func (*Metrics) MemberlistMembers

func (a *Metrics) MemberlistMembers(val int64)

func (*Metrics) RaftMembers

func (a *Metrics) RaftMembers(val int64)

func (*Metrics) Register

func (a *Metrics) Register() error

func (*Metrics) SplitBrain

func (a *Metrics) SplitBrain(val int)

type PeerFinder

type PeerFinder interface {
	Peers() []string
}

type Population

type Population struct {
	Memberlist int64
	Raft       int64
}

func (*Population) Ratio

func (p *Population) Ratio() float64

type PruneMap

type PruneMap map[string]time.Time

type QuorumNode

type QuorumNode struct {
	Config *Config

	Memberlist *memberlist.Memberlist
	Raft       *raft.Raft

	APIClient   *HTTPClient
	JoinRequest *JoinRequest

	Population *atomic.Value
	SplitBrain *int32
	// contains filtered or unexported fields
}

func NewQuorumNode

func NewQuorumNode(config *Config) (*QuorumNode, error)

func (*QuorumNode) Apply

func (q *QuorumNode) Apply(l *raft.Log) interface{}

func (*QuorumNode) GetLeader

func (q *QuorumNode) GetLeader() (string, error)

func (*QuorumNode) GetPopulation

func (q *QuorumNode) GetPopulation() Population

func (*QuorumNode) IsSplitBrain

func (q *QuorumNode) IsSplitBrain() bool

func (*QuorumNode) Join

func (q *QuorumNode) Join(serverId string, serverAddress string) error

func (*QuorumNode) Remove

func (q *QuorumNode) Remove(serverId string) error

func (*QuorumNode) Restore

func (q *QuorumNode) Restore(rc io.ReadCloser) error

func (*QuorumNode) Shutdown

func (q *QuorumNode) Shutdown(ctx context.Context) error

func (*QuorumNode) Snapshot

func (q *QuorumNode) Snapshot() (raft.FSMSnapshot, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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