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

Method tick

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

Drive time-based events: election timeout, heartbeat.

(&mut self)

Source from the content-addressed store, hash-verified

211
212 /// Drive time-based events: election timeout, heartbeat.
213 pub fn tick(&mut self) {
214 let now = Instant::now();
215
216 match self.role {
217 NodeRole::Follower | NodeRole::Candidate => {
218 if now >= self.election_deadline {
219 self.start_election();
220 }
221 }
222 NodeRole::Leader => {
223 if now >= self.heartbeat_deadline {
224 self.replicate_to_all();
225 self.heartbeat_deadline = now + self.config.heartbeat_interval;
226 }
227 }
228 NodeRole::Learner => {
229 // Learners never run election timeouts. They catch up
230 // passively via AppendEntries from the leader.
231 }
232 NodeRole::Observer => {
233 // Observers never run election timeouts. They receive entries
234 // from the source leader and apply them locally. Acks are
235 // advisory and never gate commit on the source.
236 }
237 }
238 }
239
240 /// Propose a new entry (leader only). Returns the log index.
241 pub fn propose(&mut self, data: Vec<u8>) -> Result<u64> {

Calls 3

nowFunction · 0.85
start_electionMethod · 0.80
replicate_to_allMethod · 0.80