etcd

package
v0.0.0-...-4edef61 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: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrFSMSnapshotFileCRC is returned when the on-disk CRC32C footer does not
	// match the computed checksum — the .fsm file is corrupt.
	ErrFSMSnapshotFileCRC = errors.New("fsm snapshot: file CRC32C mismatch (file corrupt)")

	// ErrFSMSnapshotTokenCRC is returned when the footer and the token CRC
	// disagree before restore — the metadata is suspect; do not auto-rewrite.
	ErrFSMSnapshotTokenCRC = errors.New("fsm snapshot: token CRC32C mismatch (metadata corrupt)")

	// ErrFSMSnapshotNotFound is returned when the expected .fsm file is absent.
	ErrFSMSnapshotNotFound = errors.New("fsm snapshot: file not found")

	// ErrFSMSnapshotTooSmall is returned when the file is shorter than the
	// minimum valid .fsm size (0 or more bytes payload + 4 bytes CRC footer).
	ErrFSMSnapshotTooSmall = errors.New("fsm snapshot: file too small to contain footer")

	// ErrFSMSnapshotTokenInvalid is returned when the token bytes cannot be
	// decoded (wrong length or magic prefix).
	ErrFSMSnapshotTokenInvalid = errors.New("fsm snapshot: token format invalid")

	// ErrFSMSnapshotTooLarge is returned when the payload exceeds fsmMaxInMemPayload.
	// Callers should switch to the streaming path (openFSMSnapshotPayloadReader).
	ErrFSMSnapshotTooLarge = errors.New("fsm snapshot: payload exceeds maximum in-memory size limit")
)

Functions

func DeriveNodeID

func DeriveNodeID(id string) uint64

Types

type Engine

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

func Open

func Open(ctx context.Context, cfg OpenConfig) (*Engine, error)

Open starts the etcd/raft backend.

Single-node bootstrap waits for local leadership so callers can use the engine immediately. Multi-node startup returns after the local node is running; leadership is established asynchronously through raft transport.

func (*Engine) AddVoter

func (e *Engine) AddVoter(ctx context.Context, id string, address string, prevIndex uint64) (uint64, error)

func (*Engine) CheckServing

func (e *Engine) CheckServing(ctx context.Context) error

func (*Engine) Close

func (e *Engine) Close() error

func (*Engine) Configuration

func (e *Engine) Configuration(ctx context.Context) (raftengine.Configuration, error)

func (*Engine) Leader

func (e *Engine) Leader() raftengine.LeaderInfo

func (*Engine) LinearizableRead

func (e *Engine) LinearizableRead(ctx context.Context) (uint64, error)

func (*Engine) Propose

func (e *Engine) Propose(ctx context.Context, data []byte) (*raftengine.ProposalResult, error)

func (*Engine) RemoveServer

func (e *Engine) RemoveServer(ctx context.Context, id string, prevIndex uint64) (uint64, error)

func (*Engine) State

func (e *Engine) State() raftengine.State

func (*Engine) Status

func (e *Engine) Status() raftengine.Status

func (*Engine) TransferLeadership

func (e *Engine) TransferLeadership(ctx context.Context) error

func (*Engine) TransferLeadershipToServer

func (e *Engine) TransferLeadershipToServer(ctx context.Context, id string, address string) error

func (*Engine) VerifyLeader

func (e *Engine) VerifyLeader(ctx context.Context) error

type Factory

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

Factory creates etcd raft engine instances.

func NewFactory

func NewFactory(cfg FactoryConfig) *Factory

NewFactory returns a Factory with the given etcd-specific settings.

func (*Factory) Create

func (*Factory) EngineType

func (f *Factory) EngineType() string

type FactoryConfig

type FactoryConfig struct {
	TickInterval   time.Duration
	HeartbeatTick  int
	ElectionTick   int
	MaxSizePerMsg  uint64
	MaxInflightMsg int
}

FactoryConfig holds etcd-specific engine parameters.

type GRPCTransport

type GRPCTransport struct {
	pb.UnimplementedEtcdRaftServer
	// contains filtered or unexported fields
}

func NewGRPCTransport

func NewGRPCTransport(peers []Peer) *GRPCTransport

func (*GRPCTransport) Close

func (t *GRPCTransport) Close() error

func (*GRPCTransport) Dispatch

func (t *GRPCTransport) Dispatch(ctx context.Context, msg raftpb.Message) error

func (*GRPCTransport) DispatchSnapshotSpool

func (t *GRPCTransport) DispatchSnapshotSpool(ctx context.Context, msg raftpb.Message, spool *snapshotSpool) error

func (*GRPCTransport) Register

func (t *GRPCTransport) Register(server grpc.ServiceRegistrar)

func (*GRPCTransport) RemovePeer

func (t *GRPCTransport) RemovePeer(nodeID uint64)

func (*GRPCTransport) Send

func (*GRPCTransport) SendSnapshot

func (t *GRPCTransport) SendSnapshot(stream pb.EtcdRaft_SendSnapshotServer) error

func (*GRPCTransport) SetFSMPayloadOpener

func (t *GRPCTransport) SetFSMPayloadOpener(fn func(index uint64) (io.ReadCloser, error))

SetFSMPayloadOpener registers the callback used by the bridge mode to stream FSM snapshot payloads directly from disk without materialising the full payload in memory.

func (*GRPCTransport) SetFSMPayloadReader

func (t *GRPCTransport) SetFSMPayloadReader(fn func(index uint64) ([]byte, error))

func (*GRPCTransport) SetFSMSnapDir

func (t *GRPCTransport) SetFSMSnapDir(dir string)

func (*GRPCTransport) SetHandler

func (t *GRPCTransport) SetHandler(handler MessageHandler)

func (*GRPCTransport) SetSpoolDir

func (t *GRPCTransport) SetSpoolDir(dir string)

func (*GRPCTransport) UpsertPeer

func (t *GRPCTransport) UpsertPeer(peer Peer)

type MessageHandler

type MessageHandler func(context.Context, raftpb.Message) error

type MigrationStats

type MigrationStats struct {
	SnapshotBytes int64
	Peers         int
}

func MigrateFSMStore

func MigrateFSMStore(storePath string, destDataDir string, peers []Peer) (*MigrationStats, error)

type OpenConfig

type OpenConfig struct {
	NodeID         uint64
	LocalID        string
	LocalAddress   string
	DataDir        string
	Peers          []Peer
	Bootstrap      bool
	Transport      *GRPCTransport
	TickInterval   time.Duration
	ElectionTick   int
	HeartbeatTick  int
	StateMachine   StateMachine
	MaxSizePerMsg  uint64
	MaxInflightMsg int
}

type Peer

type Peer struct {
	NodeID  uint64
	ID      string
	Address string
}

func LoadPersistedPeers

func LoadPersistedPeers(dataDir string) ([]Peer, bool, error)

func ParsePeers

func ParsePeers(raw string) ([]Peer, error)

type Snapshot

type Snapshot = raftengine.Snapshot

Snapshot is an alias for the shared raftengine.Snapshot interface.

type StateMachine

type StateMachine = raftengine.StateMachine

StateMachine is an alias for the shared raftengine.StateMachine interface.

func AdaptHashicorpFSM

func AdaptHashicorpFSM(fsm raft.FSM) StateMachine

AdaptHashicorpFSM bridges a hashicorp/raft FSM into the etcd-backed engine.

Jump to

Keyboard shortcuts

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