etcdraft

package
v1.1.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2020 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MaxSnapshotFiles = 5

MaxSnapshotFiles defines max number of etcd/raft snapshot files to retain on filesystem. Snapshot files are read from newest to oldest, until first intact file is found. The more snapshot files we keep around, the more we mitigate the impact of a corrupted snapshots. This is exported for testing purpose. This MUST be greater equal than 1.

Functions

func GenerateRaftPeers

func GenerateRaftPeers(config *order.Config) ([]raft.Peer, error)

func ListSnapshots

func ListSnapshots(logger raft.Logger, snapDir string) []uint64

ListSnapshots returns a list of RaftIndex of snapshots stored on disk. If a file is corrupted, rename the file.

func NewNode

func NewNode(opts ...order.Option) (order.Order, error)

NewNode new raft node

Types

type MemoryStorage

type MemoryStorage interface {
	raft.Storage
	Append(entries []raftpb.Entry) error
	SetHardState(st raftpb.HardState) error
	CreateSnapshot(i uint64, cs *raftpb.ConfState, data []byte) (raftpb.Snapshot, error)
	Compact(compactIndex uint64) error
	ApplySnapshot(snap raftpb.Snapshot) error
}

MemoryStorage is currently backed by etcd/raft.MemoryStorage. This interface is defined to expose dependencies of fsm so that it may be swapped in the future. TODO(jay) Add other necessary methods to this interface once we need them in implementation, e.g. ApplySnapshot.

type Node

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

func (*Node) Commit

func (n *Node) Commit() chan *pb.Block

func (*Node) IsLeader

func (n *Node) IsLeader() bool

func (*Node) Prepare

func (n *Node) Prepare(tx *pb.Transaction) error

Add the transaction into txpool and broadcast it to other nodes

func (*Node) Quorum

func (n *Node) Quorum() uint64

func (*Node) Ready

func (n *Node) Ready() bool

func (*Node) ReportState

func (n *Node) ReportState(height uint64, hash types.Hash)

func (*Node) Start

func (n *Node) Start() error

Start or restart raft node

func (*Node) Step

func (n *Node) Step(ctx context.Context, msg []byte) error

func (*Node) Stop

func (n *Node) Stop()

Stop the raft node

type RAFT

type RAFT struct {
	ElectionTick              int          `mapstructure:"election_tick"`
	HeartbeatTick             int          `mapstructure:"heartbeat_tick"`
	MaxSizePerMsg             uint64       `mapstructure:"max_size_per_msg"`
	MaxInflightMsgs           int          `mapstructure:"max_inflight_msgs"`
	CheckQuorum               bool         `mapstructure:"check_quorum"`
	PreVote                   bool         `mapstructure:"pre_vote"`
	DisableProposalForwarding bool         `mapstructure:"disable_proposal_forwarding"`
	TxPoolConfig              TxPoolConfig `mapstructure:"tx_pool"`
}

type RAFTConfig

type RAFTConfig struct {
	RAFT RAFT
}

type RaftStorage

type RaftStorage struct {
	SnapshotCatchUpEntries uint64
	// contains filtered or unexported fields
}

RaftStorage encapsulates storages needed for etcd/raft data, i.e. memory, wal

func CreateStorage

func CreateStorage(
	lg raft.Logger,
	walDir string,
	snapDir string,
	dbDir string,
	ram MemoryStorage,
) (*RaftStorage, storage.Storage, error)

CreateStorage attempts to create a storage to persist etcd/raft data. If data presents in specified disk, they are loaded to reconstruct storage state.

func (*RaftStorage) ApplySnapshot

func (rs *RaftStorage) ApplySnapshot(snap raftpb.Snapshot)

ApplySnapshot applies snapshot to local memory storage

func (*RaftStorage) Close

func (rs *RaftStorage) Close() error

Close closes storage

func (*RaftStorage) Snapshot

func (rs *RaftStorage) Snapshot() raftpb.Snapshot

Snapshot returns the latest snapshot stored in memory

func (*RaftStorage) Store

func (rs *RaftStorage) Store(entries []raftpb.Entry, hardstate raftpb.HardState, snapshot raftpb.Snapshot) error

Store persists etcd/raft data

func (*RaftStorage) TakeSnapshot

func (rs *RaftStorage) TakeSnapshot(i uint64, cs raftpb.ConfState, data []byte) error

TakeSnapshot takes a snapshot at index i from MemoryStorage, and persists it to wal and disk.

type TxPoolConfig

type TxPoolConfig struct {
	PackSize  int           `mapstructure:"pack_size"`
	BlockTick time.Duration `mapstructure:"block_tick"`
	PoolSize  int           `mapstructure:"pool_size"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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