raft

package
v0.0.0-...-ac41614 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RequestTimeoutSeconds = 10
)

Variables

View Source
var ECancelConfChange = errors.New("Conf change cancelled")
View Source
var EReceiverUnknown = errors.New("The sender does not know the receiver")
View Source
var ESenderUnknown = errors.New("The receiver does not know who we are")
View Source
var ETimeout = errors.New("The sender timed out while trying to send the message to the receiver")
View Source
var KeyHardState = []byte{1}
View Source
var KeyIsDecommissioning = []byte{4}
View Source
var KeyNodeID = []byte{3}
View Source
var KeyPrefixEntry = []byte{2}
View Source
var KeySnapshot = []byte{0}
View Source
var LogCompactionSize int = 1000

Limit on the number of entries that can accumulate before a snapshot and compaction occurs

Functions

This section is empty.

Types

type PeerAddress

type PeerAddress struct {
	NodeID uint64
	Host   string
	Port   int
}

func (*PeerAddress) IsEmpty

func (peerAddress *PeerAddress) IsEmpty() bool

func (*PeerAddress) ToHTTPURL

func (peerAddress *PeerAddress) ToHTTPURL(endpoint string) string

type RaftMemoryStorage

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

func NewRaftMemoryStorage

func NewRaftMemoryStorage() *RaftMemoryStorage

func (*RaftMemoryStorage) Append

func (raftStorage *RaftMemoryStorage) Append(entries []raftpb.Entry) error

func (*RaftMemoryStorage) ApplyAll

func (raftStorage *RaftMemoryStorage) ApplyAll(hs raftpb.HardState, ents []raftpb.Entry, snap raftpb.Snapshot) error

func (*RaftMemoryStorage) ApplySnapshot

func (raftStorage *RaftMemoryStorage) ApplySnapshot(snap raftpb.Snapshot) error

func (*RaftMemoryStorage) Close

func (raftStorage *RaftMemoryStorage) Close() error

func (*RaftMemoryStorage) CreateSnapshot

func (raftStorage *RaftMemoryStorage) CreateSnapshot(i uint64, cs *raftpb.ConfState, data []byte) (raftpb.Snapshot, error)

func (*RaftMemoryStorage) Entries

func (raftStorage *RaftMemoryStorage) Entries(lo, hi, maxSize uint64) ([]raftpb.Entry, error)

func (*RaftMemoryStorage) FirstIndex

func (raftStorage *RaftMemoryStorage) FirstIndex() (uint64, error)

func (*RaftMemoryStorage) InitialState

func (raftStorage *RaftMemoryStorage) InitialState() (raftpb.HardState, raftpb.ConfState, error)

func (*RaftMemoryStorage) IsDecommissioning

func (raftStorage *RaftMemoryStorage) IsDecommissioning() (bool, error)

func (*RaftMemoryStorage) IsEmpty

func (raftStorage *RaftMemoryStorage) IsEmpty() bool

func (*RaftMemoryStorage) LastIndex

func (raftStorage *RaftMemoryStorage) LastIndex() (uint64, error)

func (*RaftMemoryStorage) NodeID

func (raftStorage *RaftMemoryStorage) NodeID() (uint64, error)

func (*RaftMemoryStorage) Open

func (raftStorage *RaftMemoryStorage) Open() error

func (*RaftMemoryStorage) SetDecommissioningFlag

func (raftStorage *RaftMemoryStorage) SetDecommissioningFlag() error

func (*RaftMemoryStorage) SetHardState

func (raftStorage *RaftMemoryStorage) SetHardState(st raftpb.HardState) error

func (*RaftMemoryStorage) SetIsEmpty

func (raftStorage *RaftMemoryStorage) SetIsEmpty(b bool)

func (*RaftMemoryStorage) SetNodeID

func (raftStorage *RaftMemoryStorage) SetNodeID(id uint64) error

func (*RaftMemoryStorage) Snapshot

func (raftStorage *RaftMemoryStorage) Snapshot() (raftpb.Snapshot, error)

func (*RaftMemoryStorage) Term

func (raftStorage *RaftMemoryStorage) Term(i uint64) (uint64, error)

type RaftNode

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

func NewRaftNode

func NewRaftNode(config *RaftNodeConfig) *RaftNode

func (*RaftNode) AddNode

func (raftNode *RaftNode) AddNode(ctx context.Context, nodeID uint64, context []byte) error

func (*RaftNode) CommittedEntries

func (raftNode *RaftNode) CommittedEntries() ([]raftpb.Entry, error)

func (*RaftNode) ID

func (raftNode *RaftNode) ID() uint64

func (*RaftNode) LastSnapshot

func (raftNode *RaftNode) LastSnapshot() (raftpb.Snapshot, error)

func (*RaftNode) OnCommittedEntry

func (raftNode *RaftNode) OnCommittedEntry(cb func(raftpb.Entry) error)

func (*RaftNode) OnError

func (raftNode *RaftNode) OnError(cb func(error) error)

func (*RaftNode) OnMessages

func (raftNode *RaftNode) OnMessages(cb func([]raftpb.Message) error)

func (*RaftNode) OnReplayDone

func (raftNode *RaftNode) OnReplayDone(cb func() error)

func (*RaftNode) OnSnapshot

func (raftNode *RaftNode) OnSnapshot(cb func(raftpb.Snapshot) error)

func (*RaftNode) Propose

func (raftNode *RaftNode) Propose(ctx context.Context, proposition []byte) error

func (*RaftNode) Receive

func (raftNode *RaftNode) Receive(ctx context.Context, msg raftpb.Message) error

func (*RaftNode) RemoveNode

func (raftNode *RaftNode) RemoveNode(ctx context.Context, nodeID uint64, context []byte) error

func (*RaftNode) ReportSnapshot

func (raftNode *RaftNode) ReportSnapshot(id uint64, status raft.SnapshotStatus)

func (*RaftNode) ReportUnreachable

func (raftNode *RaftNode) ReportUnreachable(id uint64)

func (*RaftNode) Start

func (raftNode *RaftNode) Start() error

func (*RaftNode) Stop

func (raftNode *RaftNode) Stop()

type RaftNodeConfig

type RaftNodeConfig struct {
	ID                      uint64
	CreateClusterIfNotExist bool
	Storage                 RaftNodeStorage
	GetSnapshot             func() ([]byte, error)
	Context                 []byte
}

type RaftNodeStorage

type RaftNodeStorage interface {
	raft.Storage
	IsEmpty() bool
	Open() error
	Close() error
	SetDecommissioningFlag() error
	IsDecommissioning() (bool, error)
	SetNodeID(id uint64) error
	NodeID() (uint64, error)
	SetHardState(st raftpb.HardState) error
	ApplySnapshot(snap raftpb.Snapshot) error
	CreateSnapshot(i uint64, cs *raftpb.ConfState, data []byte) (raftpb.Snapshot, error)
	Append(entries []raftpb.Entry) error
	ApplyAll(hs raftpb.HardState, ents []raftpb.Entry, snap raftpb.Snapshot) error
}

type RaftStorage

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

func NewRaftStorage

func NewRaftStorage(storageDriver StorageDriver) *RaftStorage

func (*RaftStorage) Append

func (raftStorage *RaftStorage) Append(entries []raftpb.Entry) error

func (*RaftStorage) ApplyAll

func (raftStorage *RaftStorage) ApplyAll(hs raftpb.HardState, ents []raftpb.Entry, snap raftpb.Snapshot) error

This should apply the entries, then the hard state, then the snapshot atomically to both in memory and persistent storage This means that if any part fails no change occurs and the error is reported. If persisting the state to disk encounters an error then the operation is aborted and no change occurs.

func (*RaftStorage) ApplySnapshot

func (raftStorage *RaftStorage) ApplySnapshot(snap raftpb.Snapshot) error

func (*RaftStorage) Close

func (raftStorage *RaftStorage) Close() error

func (*RaftStorage) CreateSnapshot

func (raftStorage *RaftStorage) CreateSnapshot(i uint64, cs *raftpb.ConfState, data []byte) (raftpb.Snapshot, error)

Atomically take a snapshot of the current state and compact the entries up to the point that the snapshot was taken

func (*RaftStorage) Entries

func (raftStorage *RaftStorage) Entries(lo, hi, maxSize uint64) ([]raftpb.Entry, error)

func (*RaftStorage) FirstIndex

func (raftStorage *RaftStorage) FirstIndex() (uint64, error)

func (*RaftStorage) InitialState

func (raftStorage *RaftStorage) InitialState() (raftpb.HardState, raftpb.ConfState, error)

START raft.Storage interface methods

func (*RaftStorage) IsDecommissioning

func (raftStorage *RaftStorage) IsDecommissioning() (bool, error)

func (*RaftStorage) IsEmpty

func (raftStorage *RaftStorage) IsEmpty() bool

func (*RaftStorage) LastIndex

func (raftStorage *RaftStorage) LastIndex() (uint64, error)

func (*RaftStorage) NodeID

func (raftStorage *RaftStorage) NodeID() (uint64, error)

func (*RaftStorage) Open

func (raftStorage *RaftStorage) Open() error

func (*RaftStorage) SetDecommissioningFlag

func (raftStorage *RaftStorage) SetDecommissioningFlag() error

func (*RaftStorage) SetHardState

func (raftStorage *RaftStorage) SetHardState(st raftpb.HardState) error

func (*RaftStorage) SetNodeID

func (raftStorage *RaftStorage) SetNodeID(id uint64) error

func (*RaftStorage) Snapshot

func (raftStorage *RaftStorage) Snapshot() (raftpb.Snapshot, error)

func (*RaftStorage) Term

func (raftStorage *RaftStorage) Term(i uint64) (uint64, error)

type TransportHub

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

func NewTransportHub

func NewTransportHub(localPeerID uint64) *TransportHub

func (*TransportHub) AddPeer

func (hub *TransportHub) AddPeer(peerAddress PeerAddress)

func (*TransportHub) Attach

func (hub *TransportHub) Attach(router *mux.Router)

func (*TransportHub) OnReceive

func (hub *TransportHub) OnReceive(cb func(context.Context, raftpb.Message) error)

func (*TransportHub) PeerAddress

func (hub *TransportHub) PeerAddress(nodeID uint64) *PeerAddress

func (*TransportHub) RemovePeer

func (hub *TransportHub) RemovePeer(peerAddress PeerAddress)

func (*TransportHub) Send

func (hub *TransportHub) Send(ctx context.Context, msg raftpb.Message, proxy bool) error

func (*TransportHub) SetDefaultRoute

func (hub *TransportHub) SetDefaultRoute(host string, port int)

func (*TransportHub) SetLocalPeerID

func (hub *TransportHub) SetLocalPeerID(id uint64)

func (*TransportHub) UpdatePeer

func (hub *TransportHub) UpdatePeer(peerAddress PeerAddress)

Jump to

Keyboard shortcuts

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