Documentation ¶
Overview ¶
Package raft is a distributed consensus package that implements the Raft protocol.
This package is internally used by Dragonboat, applications are not expected to import this package.
Index ¶
- Constants
- Variables
- func ClusterID(clusterID uint64) string
- func IsLocalMessageType(t pb.MessageType) bool
- func NodeID(nodeID uint64) string
- type ILogDB
- type LogTestHelper
- func (l *LogTestHelper) AllEntries() []pb.Entry
- func (l *LogTestHelper) Append(ents []pb.Entry) error
- func (l *LogTestHelper) AppliedTo(index uint64)
- func (l *LogTestHelper) CheckBound(low uint64, high uint64) error
- func (l *LogTestHelper) Entries(start uint64, maxsize uint64) ([]pb.Entry, error)
- func (l *LogTestHelper) EntriesToApply() ([]pb.Entry, error)
- func (l *LogTestHelper) EntriesToSave() []pb.Entry
- func (l *LogTestHelper) FirstIndex() uint64
- func (l *LogTestHelper) GetCommitted() uint64
- func (l *LogTestHelper) GetConflictIndex(ents []pb.Entry) (uint64, error)
- func (l *LogTestHelper) GetEntries(low uint64, high uint64, maxsize uint64) ([]pb.Entry, error)
- func (l *LogTestHelper) HasEntriesToApply() bool
- func (l *LogTestHelper) LastIndex() uint64
- func (l *LogTestHelper) MatchTerm(index uint64, term uint64) (bool, error)
- func (l *LogTestHelper) SetCommitted(v uint64)
- func (l *LogTestHelper) Term(index uint64) (uint64, error)
- func (l *LogTestHelper) TryAppend(index uint64, logTerm uint64, committed uint64, ents []pb.Entry) (uint64, bool, error)
- func (l *LogTestHelper) TryCommit(index uint64, term uint64) (bool, error)
- func (l *LogTestHelper) UnstableOffset() uint64
- func (l *LogTestHelper) UpToDate(index uint64, term uint64) (bool, error)
- type Peer
- func (p *Peer) ApplyConfigChange(cc pb.ConfigChange) error
- func (p *Peer) Commit(ud pb.Update)
- func (p *Peer) GetUpdate(moreToApply bool, lastApplied uint64) (pb.Update, error)
- func (p *Peer) Handle(m pb.Message) error
- func (p *Peer) HasEntryToApply() bool
- func (p *Peer) HasUpdate(moreToApply bool) bool
- func (p *Peer) NotifyRaftLastApplied(lastApplied uint64)
- func (p *Peer) ProposeConfigChange(cc pb.ConfigChange, key uint64) error
- func (p *Peer) ProposeEntries(ents []pb.Entry) error
- func (p *Peer) QuiescedTick() error
- func (p *Peer) RateLimited() bool
- func (p *Peer) ReadIndex(ctx pb.SystemCtx) error
- func (p *Peer) RejectConfigChange() error
- func (p *Peer) ReportSnapshotStatus(nodeID uint64, reject bool) error
- func (p *Peer) ReportUnreachableNode(nodeID uint64) error
- func (p *Peer) RequestLeaderTransfer(target uint64) error
- func (p *Peer) RestoreRemotes(ss pb.Snapshot) error
- func (p *Peer) Tick() error
- type PeerAddress
- type State
- type Status
Constants ¶
const ( // NoLeader is the flag used to indcate that there is no leader or the leader // is unknown. NoLeader uint64 = 0 // NoNode is the flag used to indicate that the node id field is not set. NoNode uint64 = 0 )
Variables ¶
var ErrCompacted = errors.New("entry compacted")
ErrCompacted is the error returned to indicate that the requested entries are no longer in the LogDB due to compaction.
var ErrSnapshotOutOfDate = errors.New("snapshot out of date")
ErrSnapshotOutOfDate is the error returned to indicate that the concerned snapshot is considered as out of date.
ErrUnavailable is the error returned to indicate that requested entries are not available in LogDB.
Functions ¶
func IsLocalMessageType ¶
func IsLocalMessageType(t pb.MessageType) bool
IsLocalMessageType returns a boolean value indicating whether the specified message type is a local message type.
Types ¶
type ILogDB ¶
type ILogDB interface { // GetRange returns the range of the entries in LogDB. GetRange() (uint64, uint64) // SetRange updates the ILogDB to extend the entry range known to the ILogDB. SetRange(index uint64, length uint64) // NodeState returns the state of the node persistent in LogDB. NodeState() (pb.State, pb.Membership) // SetState sets the persistent state known to ILogDB. SetState(ps pb.State) // CreateSnapshot sets the snapshot known to ILogDB CreateSnapshot(ss pb.Snapshot) error // ApplySnapshot makes the snapshot known to ILogDB and also update the entry // range known to ILogDB. ApplySnapshot(ss pb.Snapshot) error // Term returns the entry term of the specified entry. Term(index uint64) (uint64, error) // Entries returns entries between [low, high) with total size of entries // limited to maxSize bytes. Entries(low uint64, high uint64, maxSize uint64) ([]pb.Entry, error) // Snapshot returns the metadata for the most recent snapshot known to the // LogDB. Snapshot() pb.Snapshot // Compact performs entry range compaction on ILogDB up to the entry // specified by index. Compact(index uint64) error // Append makes the given entries known to the ILogDB instance. This is // usually not how entries are persisted. Append(entries []pb.Entry) error }
ILogDB is a read-only interface to the underlying persistent storage to allow the raft package to access raft state, entries, snapshots stored in the persistent storage. Entries stored in the persistent storage accessible via ILogDB is usually not required in normal cases.
type LogTestHelper ¶
type LogTestHelper struct {
// contains filtered or unexported fields
}
LogTestHelper is a helper type used for testing logEntry.
func NewLog ¶
func NewLog(logdb ILogDB) *LogTestHelper
NewLog creates and returns a new LogTestHelper instance used for testing purpose.
func (*LogTestHelper) CheckBound ¶
func (l *LogTestHelper) CheckBound(low uint64, high uint64) error
CheckBound ...
func (*LogTestHelper) EntriesToApply ¶
func (l *LogTestHelper) EntriesToApply() ([]pb.Entry, error)
EntriesToApply ...
func (*LogTestHelper) EntriesToSave ¶
func (l *LogTestHelper) EntriesToSave() []pb.Entry
EntriesToSave ...
func (*LogTestHelper) GetConflictIndex ¶
func (l *LogTestHelper) GetConflictIndex(ents []pb.Entry) (uint64, error)
GetConflictIndex ...
func (*LogTestHelper) GetEntries ¶
GetEntries ...
func (*LogTestHelper) HasEntriesToApply ¶
func (l *LogTestHelper) HasEntriesToApply() bool
HasEntriesToApply ...
func (*LogTestHelper) MatchTerm ¶
func (l *LogTestHelper) MatchTerm(index uint64, term uint64) (bool, error)
MatchTerm ...
func (*LogTestHelper) SetCommitted ¶
func (l *LogTestHelper) SetCommitted(v uint64)
SetCommitted ...
func (*LogTestHelper) TryAppend ¶
func (l *LogTestHelper) TryAppend(index uint64, logTerm uint64, committed uint64, ents []pb.Entry) (uint64, bool, error)
TryAppend ...
func (*LogTestHelper) TryCommit ¶
func (l *LogTestHelper) TryCommit(index uint64, term uint64) (bool, error)
TryCommit ...
func (*LogTestHelper) UnstableOffset ¶
func (l *LogTestHelper) UnstableOffset() uint64
UnstableOffset ...
type Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
Peer is the interface struct for interacting with the underlying Raft protocol implementation.
func Launch ¶
func Launch(config config.Config, logdb ILogDB, events server.IRaftEventListener, addresses []PeerAddress, initial bool, newNode bool) Peer
Launch starts or restarts a Raft node.
func (*Peer) ApplyConfigChange ¶
func (p *Peer) ApplyConfigChange(cc pb.ConfigChange) error
ApplyConfigChange applies a raft membership change to the local raft node.
func (*Peer) HasEntryToApply ¶
HasEntryToApply returns a boolean flag indicating whether there are more entries ready to be applied.
func (*Peer) HasUpdate ¶
HasUpdate returns a boolean value indicating whether there is any Update ready to be processed.
func (*Peer) NotifyRaftLastApplied ¶
NotifyRaftLastApplied passes on the lastApplied index confirmed by the RSM to the raft state machine.
func (*Peer) ProposeConfigChange ¶
func (p *Peer) ProposeConfigChange(cc pb.ConfigChange, key uint64) error
ProposeConfigChange proposes a raft membership change.
func (*Peer) ProposeEntries ¶
ProposeEntries proposes specified entries in a batched mode using a single MTPropose message.
func (*Peer) QuiescedTick ¶
QuiescedTick moves the logical clock forward by one tick in quiesced mode.
func (*Peer) RateLimited ¶
RateLimited returns a boolean flag indicating whether the Raft node is rate limited.
func (*Peer) ReadIndex ¶
ReadIndex starts a ReadIndex operation. The ReadIndex protocol is defined in the section 6.4 of the Raft thesis.
func (*Peer) RejectConfigChange ¶
RejectConfigChange rejects the currently pending raft membership change.
func (*Peer) ReportSnapshotStatus ¶
ReportSnapshotStatus reports the status of the snapshot to the local raft node.
func (*Peer) ReportUnreachableNode ¶
ReportUnreachableNode marks the specified node as not reachable.
func (*Peer) RequestLeaderTransfer ¶
RequestLeaderTransfer makes a request to transfer the leadership to the specified target node.
func (*Peer) RestoreRemotes ¶
RestoreRemotes applies the remotes info obtained from the specified snapshot.
type PeerAddress ¶
PeerAddress is the basic info for a peer in the Raft cluster.