raftengine

package
v0.0.0-...-e2172d6 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2024 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 returns operator that can be used if other operators do not succeed.

func ForceJoin

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

ForceJoin returns operator that sends rpc request to join an existing cluster, even if already part of a cluster.

func ForceNewCluster

func ForceNewCluster() Operator

ForceNewCluster returns operator that initializes a new cluster from state dir.

func InitCluster

func InitCluster() Operator

InitCluster returns operator that initializes a new cluster and create first raft node..

func Join

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

Join returns operator that sends rpc request to join an existing cluster.

func Members

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

Members returns operator that adds the given members to the raft node.

func Restart

func Restart() Operator

Restart returns operator that restarts raft node from state dir.

func Restore

func Restore(path string) Operator

Restore returns operator that initializes 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