cluster

package
v0.0.0-...-40ef43a Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultRetainSnapshotCount is the default number of snaphots to keep.
	DefaultRetainSnapshotCount = 2
	// DefaultRaftTimeout is the default timeout of the Raft cluster.
	DefaultRaftTimeout = 10 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cluster

type Cluster struct {
	// RaftDirectory is the directory where all the Raft protocol files (e.g.
	// the log, the snaphots, the persistent store) will be kept.
	RaftDirectory string
	// RaftBindAddress is the network address on which the Raft protocol will
	// be listening on.
	RaftBindAddress string
	// RaftRetainSnapshotCount is the number of Raft snaphots to keep.
	RaftRetainSnapshotCount int
	// RaftTimeout is the timeout of the Raft cluster.
	RaftTimeout time.Duration
	// NodeID is the unique ID of the server in the cluster.
	NodeID string
	// Raft is the underlying Raft consensus cluster.
	Raft *raft.Raft
	// Transport is the underlying transport layer for Raft.
	Transport *raft.NetworkTransport
	// Snapshots is the underlying snapshots store.
	Snapshots *raft.FileSnapshotStore
}

Cluster represents a raft cluster

func New

func New(nodeID string, fsm raft.FSM, options ...Option) (*Cluster, error)

New creates a new Cluster and associates it with the given finite state machine (FSM), with the given cluster options.

func (*Cluster) Bootstrap

func (c *Cluster) Bootstrap(nodes ...Node) error

Bootstrap bootstraps the Cluster with the set of nodes; if none is provided, the cluster is bootstrapped with this single node.

func (*Cluster) Join

func (c *Cluster) Join(nodeID string, address string) error

Join joins a node, identified by nodeID and located at address, to this cluster. The node must be ready to respond to Raft communications at that address.

type Node

type Node struct {
	ID      string
	Address string
}

Node represents a node in the Cluster.

type Option

type Option func(cluster *Cluster)

Option represents the optional function.

func WithRaftBindAddress

func WithRaftBindAddress(value string) Option

WithRaftBindAddress sets up the network address on which the Raft protocol endpoint will be made available.

func WithRaftDirectory

func WithRaftDirectory(value string) Option

WithRaftDirectory sets up the directory where Raft protocol will be kept.

func WithRaftRetainSnapshotCount

func WithRaftRetainSnapshotCount(value int) Option

WithRaftRetainSnapshotCount sets up the number of Raft snapshots to keep.

func WithRaftTimeout

func WithRaftTimeout(value time.Duration) Option

WithRaftTimeout sets up the timeout of the Raft cluster.

Jump to

Keyboard shortcuts

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