peer

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResolveStorage

func ResolveStorage(cfg *Config) (engine.PeerStorage, error)

ResolveStorage chooses the backing log engine (in-memory, on-disk, or WAL).

Types

type AdminApplyFunc

type AdminApplyFunc func(cmd *pb.AdminCommand) error

AdminApplyFunc consumes admin commands (split, merge, etc.).

type ApplyFunc

type ApplyFunc func(entries []myraft.Entry) error

ApplyFunc consumes committed raft log entries and applies them to the user state machine (LSM, MVCC, etc).

type ConfChangeEvent

type ConfChangeEvent struct {
	Peer       *Peer
	RegionMeta *raftmeta.RegionMeta
	ConfChange raftpb.ConfChangeV2
	Index      uint64
	Term       uint64
}

ConfChangeEvent captures context for a configuration change entry that has been committed and applied by the raft peer.

type ConfChangeHandler

type ConfChangeHandler func(ConfChangeEvent) error

ConfChangeHandler is invoked whenever a configuration change entry is applied. Returning an error aborts Ready processing so callers can surface failures (for example manifest persistence errors) to the raftstore.

type Config

type Config struct {
	RaftConfig       myraft.Config
	Peers            []myraft.Peer
	Transport        transport.Transport
	Apply            ApplyFunc
	AdminApply       AdminApplyFunc
	ConfChange       ConfChangeHandler
	Storage          engine.PeerStorage
	StorageDir       string
	GroupID          uint64
	Region           *raftmeta.RegionMeta
	LogRetainEntries uint64
	MaxInFlightApply uint64
}

Config captures everything required to bootstrap a peer.

type Peer

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

Peer wraps a RawNode with simple storage and apply plumbing.

func NewPeer

func NewPeer(cfg *Config) (*Peer, error)

NewPeer constructs a peer using the provided configuration. The caller must register the peer with the transport before invoking Bootstrap.

func (*Peer) ApplyRegionMetaMirror added in v0.7.2

func (p *Peer) ApplyRegionMetaMirror(meta raftmeta.RegionMeta)

ApplyRegionMetaMirror replaces the peer's in-memory region metadata mirror. It exists only so raftstore can synchronize peer-local snapshots after apply/bootstrap has already advanced the store-local region truth. It must not be treated as a consensus state mutation entrypoint.

func (*Peer) Bootstrap

func (p *Peer) Bootstrap(peers []myraft.Peer) error

Bootstrap injects the initial configuration into the node. It must be called after the peer has been registered with the transport.

func (*Peer) Campaign

func (p *Peer) Campaign() error

Campaign transitions this peer into candidate state.

func (*Peer) Close

func (p *Peer) Close() error

Close releases resources associated with the peer, including background watermark processors.

func (*Peer) Flush

func (p *Peer) Flush() error

Flush forces processing of any pending Ready state.

func (*Peer) ID

func (p *Peer) ID() uint64

ID returns the peer ID.

func (*Peer) LinearizableRead added in v0.3.0

func (p *Peer) LinearizableRead(ctx context.Context) (uint64, error)

LinearizableRead performs a raft ReadIndex round-trip to ensure the peer still holds leadership and returns the corresponding log index. Callers should subsequently wait for that index to be applied before reading state.

func (*Peer) PendingSnapshot

func (p *Peer) PendingSnapshot() (myraft.Snapshot, bool)

PendingSnapshot returns the snapshot retained for resend without removing it from the queue.

func (*Peer) PopPendingSnapshot

func (p *Peer) PopPendingSnapshot() (myraft.Snapshot, bool)

PopPendingSnapshot returns the most recent snapshot recorded during Ready handling, clearing the queue. It returns false when no snapshot is pending.

func (*Peer) Propose

func (p *Peer) Propose(data []byte) error

Propose submits application data to the raft log.

func (*Peer) ProposeAdmin

func (p *Peer) ProposeAdmin(cmdData []byte) error

ProposeAdmin submits an admin command encoded as pb.AdminCommand payload.

func (*Peer) ProposeCommand added in v0.2.0

func (p *Peer) ProposeCommand(req *pb.RaftCmdRequest) error

ProposeCommand encodes the provided raft command request and submits it to the raft log.

func (*Peer) ProposeConfChange

func (p *Peer) ProposeConfChange(cc raftpb.ConfChangeV2) error

ProposeConfChange submits a configuration change entry to the raft log.

func (*Peer) RegionMeta

func (p *Peer) RegionMeta() *raftmeta.RegionMeta

RegionMeta returns a clone of the region metadata associated with this peer. It mirrors TinyKV's approach of surfacing region layout through the store for schedulers and debugging endpoints.

func (*Peer) ResendSnapshot

func (p *Peer) ResendSnapshot(to uint64) bool

ResendSnapshot attempts to resend the last snapshot destined for the provided peer ID. It returns true when a snapshot message was re-enqueued.

func (*Peer) Status

func (p *Peer) Status() myraft.Status

Status returns the raft status snapshot.

func (*Peer) Step

func (p *Peer) Step(msg myraft.Message) error

Step forwards a received raft message to the underlying node.

func (*Peer) Tick

func (p *Peer) Tick() error

Tick increments the logical clock, driving elections and heartbeats.

func (*Peer) TransferLeader

func (p *Peer) TransferLeader(target uint64) error

TransferLeader requests leadership transfer to the provided peer ID.

func (*Peer) WaitApplied

func (p *Peer) WaitApplied(ctx context.Context, index uint64) error

WaitApplied blocks until the provided raft log index has been fully applied.

type RaftLogInfo

type RaftLogInfo struct {
	Pointer  raftmeta.RaftLogPointer
	LastErr  error
	Injected bool
}

Jump to

Keyboard shortcuts

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