libuav original
Dependents: UAVCAN UAVCAN_Subscriber
RaftCore Class Reference
This class implements log replication and voting. More...
#include <raft_core.hpp>
Inherits uavcan::TimerBase.
Data Structures | |
| struct | LogEntryInfo |
| This class is used to perform log searches. More... | |
Public Member Functions | |
| int | init (const uint8_t cluster_size, const TransferPriority priority) |
| Once started, the logic runs in the background until destructor is called. | |
| Log::Index | getCommitIndex () const |
| This function is mostly needed for testing. | |
| bool | areAllLogEntriesCommitted () const |
| This essentially indicates whether the server could replicate log since last allocation. | |
| bool | isLeader () const |
| Only the leader can call appendLog(). | |
| void | appendLog (const Entry::FieldTypes::unique_id &unique_id, NodeID node_id) |
| Inserts one entry into log. | |
| template<typename Predicate > | |
| LazyConstructor< LogEntryInfo > | traverseLogFromEndUntil (const Predicate &predicate) const |
| This method is used by the allocator to query existence of certain entries in the Raft log. | |
| const PersistentState & | getPersistentState () const |
| These accessors are needed for debugging, visualization and testing. | |
Private Member Functions | |
| void | startOneShotWithDeadline (MonotonicTime deadline) |
| Various ways to start the timer - periodically or once. | |
| MonotonicDuration | getPeriod () const |
| Returns period if the timer is in periodic mode. | |
Detailed Description
This class implements log replication and voting.
It does not implement client-server interaction at all; instead it just exposes a public method for adding allocation entries.
Note that this class uses std::rand(), so the RNG must be properly seeded by the application.
Activity registration:
- persistent state update error
- switch to candidate (this defines timeout between reelections)
- newer term in response (also switch to follower)
- append entries request with term >= currentTerm
- vote granted
Definition at line 64 of file raft_core.hpp.
Member Function Documentation
| void appendLog | ( | const Entry::FieldTypes::unique_id & | unique_id, |
| NodeID | node_id | ||
| ) |
Inserts one entry into log.
This method will trigger an assertion failure and return error if the current node is not the leader. If operation fails, the node may give up its Leader status.
Definition at line 832 of file raft_core.hpp.
| bool areAllLogEntriesCommitted | ( | ) | const |
This essentially indicates whether the server could replicate log since last allocation.
Definition at line 820 of file raft_core.hpp.
| Log::Index getCommitIndex | ( | ) | const |
This function is mostly needed for testing.
Definition at line 815 of file raft_core.hpp.
| const PersistentState& getPersistentState | ( | ) | const |
These accessors are needed for debugging, visualization and testing.
Definition at line 905 of file raft_core.hpp.
| int init | ( | const uint8_t | cluster_size, |
| const TransferPriority | priority | ||
| ) |
Once started, the logic runs in the background until destructor is called.
- Parameters:
-
cluster_size If set, this value will be used and stored in the persistent storage. If not set, value from the persistent storage will be used. If not set and there's no such key in the persistent storage, initialization will fail.
Definition at line 731 of file raft_core.hpp.
| bool isLeader | ( | ) | const |
Only the leader can call appendLog().
Definition at line 825 of file raft_core.hpp.
| LazyConstructor<LogEntryInfo> traverseLogFromEndUntil | ( | const Predicate & | predicate ) | const |
This method is used by the allocator to query existence of certain entries in the Raft log.
Predicate is a callable of the following prototype: bool (const LogEntryInfo& entry) Once the predicate returns true, the loop will be terminated and the method will return an initialized lazy contructor with the last visited entry; otherwise the constructor will not be initialized. In this case, lazy constructor is used as boost::optional. The log is always traversed from HIGH to LOW index values, i.e. entry 0 will be traversed last.
Definition at line 878 of file raft_core.hpp.
Generated on Tue Jul 12 2022 17:17:38 by
1.7.2