cluster

package
v0.0.0-...-0e8e39a Latest Latest
Warning

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

Go to latest
Published: May 15, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const PeerListSep = ","

PeerListSep separates peer definitions in the peer list.

View Source
const PeerOptsSep = ":"

PeerOptsSep separates a peer's options.

Variables

View Source
var ErrClusterConfig = errors.New("invalid cluster configuration")

ErrClusterConfig is the error returned in case of invalid Cluster configuration.

View Source
var ErrDeadlineExceeded error = errors.New("deadline exceeded")

ErrDeadlineExceeded is the error returned if a timeout is specified.

View Source
var ErrPeerParams = errors.New("invalid peer parameters")

ErrPeerParams is the error returned if the peer parameters are invalid.

View Source
var ErrUnknownCommand = errors.New("unknown command")

ErrUnknownCommand is the error returned by fsm.Apply if the command is unknown.

Functions

This section is empty.

Types

type Cluster

type Cluster interface {
	// Raft returns the raft node for this Cluster.
	Raft() *raft.Raft

	// ID returns the Cluster ID
	ID() string

	// IsLeader returns true if the Cluster is the leader.
	IsLeader() bool

	// LeaderAddress returns address of the current leader of the cluster.
	LeaderAddress() string

	// AddVoter adds a new Voter to the cluster.
	AddVoter(id string, bindIP string, bindPort int) error

	// LeadershipTransfer will transfer leadership to another Cluster.
	LeadershipTransfer() error

	// Leader returns a channel which signals on acquiring or losing
	// leadership.  It sends true if the Cluster become the leader, otherwise it
	// returns false.
	Leader() <-chan bool

	// Execute executes the command c bypassing Raft node.
	Execute(c *pb.ClusterCommand) interface{}

	// Done returns a channel that's closed when the Cluster is shutdown.
	Done() <-chan error
}

Cluster is a higher level representation of raft.Raft cluster endpoint.

func New

func New(ctx context.Context, opts ...Option) (c Cluster, err error)

New creates a new Cluster instance.

type FSM

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

FSM implements raft.FSM

func NewFSM

func NewFSM(ctx context.Context) *FSM

NewFSM creates a new raft.FSM instance

func (*FSM) Apply

func (f *FSM) Apply(l *raft.Log) interface{}

Apply log is invoked once a log entry is committed.

func (*FSM) Execute

func (f *FSM) Execute(c *pb.ClusterCommand) interface{}

Execute executes the command c.

func (*FSM) MarshalBinary

func (f *FSM) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.MarshalBinary (https://golang.org/pkg/encoding/#BinaryMarshaler).

func (*FSM) Persist

func (f *FSM) Persist(sink raft.SnapshotSink) error

Persist implements raft.SnapshotSink.Persist.

func (*FSM) Release

func (f *FSM) Release()

Release implements raft.SnapshotSink.Release.

func (*FSM) Restore

func (f *FSM) Restore(rc io.ReadCloser) error

Restore is used to restore an FSM from a snapshot.

func (*FSM) Snapshot

func (f *FSM) Snapshot() (raft.FSMSnapshot, error)

Snapshot is used to support log compaction.

func (*FSM) UnmarshalBinary

func (f *FSM) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.UnmarshalBinary (https://golang.org/pkg/encoding/#BinaryUnmarshaler).

type Option

type Option func(*options) error

Option defines a Cluster configuration option.

func WithBindAddress

func WithBindAddress(v string) Option

WithBindAddress passes the Cluster's bind address.

func WithLoggerName

func WithLoggerName(v string) Option

WithLoggerName sets the Cluster logger name.

func WithPeers

func WithPeers(v string) Option

WithPeers passes the list of peers with which the Clustir should be created.

func WithPingPeriod

func WithPingPeriod(v time.Duration) Option

WithPingPeriod sets the Cluster ping period.

Jump to

Keyboard shortcuts

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