raftengine

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2022 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrStopped is returned by the Engine methods after a call to
	// Shutdown or when it has not started.
	ErrStopped = errors.New("raft: node not ready yet or has been stopped")
	// ErrNoLeader is returned by the Engine methods when leader lost, or
	// no elected cluster leader.
	ErrNoLeader = errors.New("raft: no elected cluster leader")
)

Functions

This section is empty.

Types

type Config

type Config interface {
	Mux() Mux
	RaftConfig() *raft.Config
	SnapInterval() uint64
	Pool() membership.Pool
	Storage() storage.Storage
	Dial() transport.Dial
	TickInterval() time.Duration
	StateMachine() StateMachine
	Context() context.Context
	DrainTimeout() time.Duration
	GroupID() uint64
	Logger() raftlog.Logger
}

Config define common configuration used by the daemon.

type Engine

type Engine interface {
	LinearizableRead(ctx context.Context) error
	Push(m etcdraftpb.Message) error
	TransferLeadership(context.Context, uint64) error
	Status() (raft.Status, error)
	Shutdown(context.Context) error
	ProposeReplicate(ctx context.Context, data []byte) error
	ProposeConfChange(ctx context.Context, m *raftpb.Member, t etcdraftpb.ConfChangeType) error
	CreateSnapshot() (etcdraftpb.Snapshot, error)
	Start(addr string, oprs ...Operator) error
	ReportUnreachable(id uint64)
	ReportSnapshot(id uint64, status raft.SnapshotStatus)
	ReportShutdown(id uint64)
}

Engine represents the underlying raft node processor.

func New

func New(cfg Config) Engine

New construct and return new engine from the provided config.

type Mux

type Mux interface {
	Start()
	Stop()
	// contains filtered or unexported methods
}

Mux represents a multi node state that is participating in multiple consensus groups, a mux is more efficient than a collection of nodes. the name mux stands for "multiplexer". Like the standard "http.ServeMux".

func NewMux

func NewMux() Mux

NewMux return's a new mux.

type Operator

type Operator interface {
	fmt.Stringer
	// contains filtered or unexported methods
}

Operator is a bootstrapper func that determine the action that is to be performed or considered.

func Fallback

func Fallback(ops ...Operator) Operator

Fallback return's operator that can be used if other operators do not succeed.

func ForceJoin

func ForceJoin(addr string, timeout time.Duration) Operator

ForceJoin return's operator that send rpc request to join an existing cluster, even if already part of a cluster.

func ForceNewCluster

func ForceNewCluster() Operator

ForceNewCluster return's operator that initialize a new cluster from state dir.

func InitCluster

func InitCluster() Operator

InitCluster return's operator that initialize a new cluster and create first raft node..

func Join

func Join(addr string, timeout time.Duration) Operator

Join return's operator that send rpc request to join an existing cluster.

func Members

func Members(membs ...raftpb.Member) Operator

Members return's operator that add the given members to the raft node.

func Restart

func Restart() Operator

Restart return's operator that restart raft node from state dir.

func Restore

func Restore(path string) Operator

Restore return's operator that initialize a new cluster from snapshot file

type StateMachine

type StateMachine interface {
	// Apply committed raft log entry.
	Apply([]byte)

	// Snapshot is used to write the current state to a snapshot file,
	// on stable storage and compacting the raft logs.
	Snapshot() (io.ReadCloser, error)

	// Restore is used to restore state machine from a snapshot.
	Restore(io.ReadCloser) error
}

StateMachine define an interface that must be implemented by application to make use of the raft replicated log.

Jump to

Keyboard shortcuts

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