raftengine

package
v0.0.0-...-be2123a Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Admin

type Admin interface {
	LeaderView
	StatusReader
	ConfigReader
	AddVoter(ctx context.Context, id string, address string, prevIndex uint64) (uint64, error)
	RemoveServer(ctx context.Context, id string, prevIndex uint64) (uint64, error)
	TransferLeadership(ctx context.Context) error
	TransferLeadershipToServer(ctx context.Context, id string, address string) error
}

type ConfigReader

type ConfigReader interface {
	Configuration(ctx context.Context) (Configuration, error)
}

type Configuration

type Configuration struct {
	Servers []Server
}

type Engine

type Factory

type Factory interface {
	EngineType() string
	Create(cfg FactoryConfig) (*FactoryResult, error)
}

Factory creates raft engine instances. Engine-specific configuration (timeouts, tick intervals, etc.) is provided at factory construction time; the Create method receives only engine-agnostic parameters.

type FactoryConfig

type FactoryConfig struct {
	LocalID      string
	LocalAddress string
	DataDir      string
	Peers        []Server
	Bootstrap    bool
	StateMachine StateMachine
}

FactoryConfig holds engine-agnostic parameters for creating a raft engine.

type FactoryResult

type FactoryResult struct {
	Engine            Engine
	RegisterTransport func(grpc.ServiceRegistrar)
	// Close releases engine-specific resources that are not owned by
	// Engine.Close (e.g. raft log stores, transport managers). Callers
	// must call Engine.Close first to ensure the raft instance is fully
	// shut down before the underlying stores and transports are released.
	Close func() error
}

FactoryResult holds the output of Factory.Create.

type HealthReader

type HealthReader interface {
	CheckServing(ctx context.Context) error
}

type LeaderInfo

type LeaderInfo struct {
	ID      string
	Address string
}

type LeaderView

type LeaderView interface {
	State() State
	Leader() LeaderInfo
	VerifyLeader(ctx context.Context) error
	// LinearizableRead blocks until the returned index is safe to read from the
	// local FSM on that node.
	LinearizableRead(ctx context.Context) (uint64, error)
}

type ProposalResult

type ProposalResult struct {
	CommitIndex uint64
	Response    any
}

type Proposer

type Proposer interface {
	Propose(ctx context.Context, data []byte) (*ProposalResult, error)
}

type Server

type Server struct {
	ID       string
	Address  string
	Suffrage string
}

type Snapshot

type Snapshot interface {
	WriteTo(w io.Writer) (int64, error)
	Close() error
}

Snapshot is an owned export handle from the state machine. Callers are responsible for closing it after WriteTo completes.

type State

type State string
const (
	StateFollower  State = "follower"
	StateCandidate State = "candidate"
	StateLeader    State = "leader"
	StateShutdown  State = "shutdown"
	StateUnknown   State = "unknown"
)

type StateMachine

type StateMachine interface {
	Apply(data []byte) any
	// Snapshot should capture a stable export handle quickly. Expensive snapshot
	// serialization belongs in Snapshot.WriteTo, which the engine can run off
	// the main raft loop.
	Snapshot() (Snapshot, error)
	Restore(r io.Reader) error
}

StateMachine is the interface that engine-agnostic state machines must implement. Both the hashicorp and etcd backends use this contract.

type Status

type Status struct {
	State             State
	Leader            LeaderInfo
	Term              uint64
	CommitIndex       uint64
	AppliedIndex      uint64
	LastLogIndex      uint64
	LastSnapshotIndex uint64
	FSMPending        uint64
	NumPeers          uint64
	LastContact       time.Duration
}

type StatusReader

type StatusReader interface {
	Status() Status
}

Directories

Path Synopsis
Package raftenginetest provides a shared conformance test suite for raftengine.Engine implementations.
Package raftenginetest provides a shared conformance test suite for raftengine.Engine implementations.

Jump to

Keyboard shortcuts

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