MCPcopy Create free account
hub / github.com/e2wugui/zeze / onTimer

Method onTimer

ZezeJava/ZezeJava/src/main/java/Zeze/Raft/Raft.java:521–554  ·  view source on GitHub ↗

每个Raft使用一个固定Timer,根据不同的状态执行相应操作。 【简化】不同状态下不管维护管理不同的Timer了。

()

Source from the content-addressed store, hash-verified

519 * 【简化】不同状态下不管维护管理不同的Timer了。
520 */
521 private void onTimer() throws Exception {
522 lock();
523 try {
524 if (isShutdown)
525 return;
526 long now = System.currentTimeMillis();
527 switch (getState()) {
528 case Follower:
529 if (now - logSequence.getLeaderActiveTime() > raftConfig.getElectionTimeout()) {
530 logger.warn("LeaderLostTimeout: {} > {}", now - logSequence.getLeaderActiveTime(), raftConfig.getElectionTimeout());
531 convertStateTo(RaftState.Candidate);
532 }
533 break;
534 case Candidate:
535 if (now > nextVoteTime)
536 convertStateTo(RaftState.Candidate); // vote timeout. restart
537 break;
538 case Leader:
539 server.getConfig().forEachConnector(c -> {
540 var cex = (Server.ConnectorEx)c;
541 if (now - cex.getHeartbeatTime() > raftConfig.getLeaderHeartbeatTimer())
542 logSequence.sendHeartbeatTo(cex);
543 });
544 break;
545 }
546 if (++lowPrecisionTimer > 1000) {
547 lowPrecisionTimer = 0;
548 onLowPrecisionTimer();
549 }
550 } finally {
551 unlock();
552 //timerTask = Task.scheduleUnsafe(10, this::onTimer);
553 }
554 }
555
556 private void onLowPrecisionTimer() throws ParseException, RocksDBException {
557 server.getConfig().forEachConnector(Connector::start); // Connector Reconnect Bug?

Callers

nothing calls this directly

Calls 12

lockMethod · 0.95
getStateMethod · 0.95
convertStateToMethod · 0.95
onLowPrecisionTimerMethod · 0.95
unlockMethod · 0.95
getLeaderActiveTimeMethod · 0.80
forEachConnectorMethod · 0.80
getHeartbeatTimeMethod · 0.80
sendHeartbeatToMethod · 0.80
getElectionTimeoutMethod · 0.45
getConfigMethod · 0.45

Tested by

no test coverage detected