MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / new

Method new

nodedb-raft/src/node/core.rs:80–102  ·  view source on GitHub ↗

Create a new Raft node. Call `restore()` before ticking. If `config.starts_as_learner` is `true`, the node boots in the `Learner` role and will never run an election timeout or become a leader until it is promoted via `promote_self_to_voter`.

(config: RaftConfig, storage: S)

Source from the content-addressed store, hash-verified

78 /// `Learner` role and will never run an election timeout or become a
79 /// leader until it is promoted via `promote_self_to_voter`.
80 pub fn new(config: RaftConfig, storage: S) -> Self {
81 let now = Instant::now();
82 let role = if config.starts_as_observer {
83 NodeRole::Observer
84 } else if config.starts_as_learner {
85 NodeRole::Learner
86 } else {
87 NodeRole::Follower
88 };
89 Self {
90 log: RaftLog::new(storage),
91 role,
92 hard_state: HardState::new(),
93 volatile: VolatileState::new(),
94 leader_state: None,
95 election_deadline: now + config.election_timeout_max,
96 heartbeat_deadline: now,
97 votes_received: HashSet::new(),
98 ready: Ready::default(),
99 leader_id: 0,
100 config,
101 }
102 }
103
104 /// Restore state from persistent storage. Must be called before ticking.
105 pub fn restore(&mut self) -> Result<()> {

Callers

nothing calls this directly

Calls 1

nowFunction · 0.85

Tested by

no test coverage detected