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 Peer
- func (rc *Peer) ApplyConfigChange(cc pb.ConfigChange)
- func (rc *Peer) Commit(ud pb.Update)
- func (rc *Peer) DumpRaftInfoToLog(addrMap map[uint64]string)
- func (rc *Peer) GetLeaderID() uint64
- func (rc *Peer) GetUpdate(moreEntriesToApply bool) pb.Update
- func (rc *Peer) Handle(m pb.Message)
- func (rc *Peer) HasUpdate(moreEntriesToApply bool) bool
- func (rc *Peer) LocalStatus() Status
- func (rc *Peer) NotifyRaftLastApplied(lastApplied uint64)
- func (rc *Peer) ProposeConfigChange(configChange pb.ConfigChange, key uint64)
- func (rc *Peer) ProposeEntries(ents []pb.Entry)
- func (rc *Peer) QuiescedTick()
- func (rc *Peer) ReadIndex(ctx pb.SystemCtx)
- func (rc *Peer) RejectConfigChange()
- func (rc *Peer) ReportSnapshotStatus(nodeID uint64, reject bool)
- func (rc *Peer) ReportUnreachableNode(nodeID uint64)
- func (rc *Peer) RequestLeaderTransfer(target uint64)
- func (rc *Peer) RestoreRemotes(ss pb.Snapshot)
- func (rc *Peer) Tick()
- 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 )
const (
// RaftLogTypeName is the type name of the raft log
RaftLogTypeName = "three-stage"
)
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 persistented 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 sbapshot 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 Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
Peer is the interface struct for interacting with the underlying Raft protocol implementation.
func LaunchPeer ¶
func LaunchPeer(config *config.Config, logdb ILogDB, addresses []PeerAddress, initial bool, newNode bool) (*Peer, error)
LaunchPeer starts or restarts a Raft node.
func (*Peer) ApplyConfigChange ¶
func (rc *Peer) ApplyConfigChange(cc pb.ConfigChange)
ApplyConfigChange applies a raft membership change to the local raft node.
func (*Peer) DumpRaftInfoToLog ¶
DumpRaftInfoToLog prints the raft state to log for debugging purposes.
func (*Peer) HasUpdate ¶
HasUpdate returns a boolean value indicating whether there is any Update ready to be processed.
func (*Peer) LocalStatus ¶
LocalStatus returns the current local status of the raft node.
func (*Peer) NotifyRaftLastApplied ¶
NotifyRaftLastApplied passes on the lastApplied index confirmed by the RSM to the raft state machine.
func (*Peer) ProposeConfigChange ¶
func (rc *Peer) ProposeConfigChange(configChange pb.ConfigChange, key uint64)
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 ¶
func (rc *Peer) QuiescedTick()
QuiescedTick moves the logical clock forward by one tick in quiesced mode.
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 ¶
func (rc *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.
type State ¶
type State uint64
State is the state of a raft node defined in the raft paper, possible states are leader, follower, candidate and observer. Observer is non-voting member node.