From 6405167e5090ba02ac8930c57daab6eb887d7540 Mon Sep 17 00:00:00 2001 From: panda-sheep <59197347+panda-sheep@users.noreply.github.com> Date: Thu, 6 Aug 2020 18:26:21 +0800 Subject: [PATCH] raft lease is always valid when replica is one Synchronize storage 2.0 pr 69 (#2276) Co-authored-by: dangleptr <37216992+dangleptr@users.noreply.github.com> --- src/kvstore/raftex/RaftPart.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/kvstore/raftex/RaftPart.cpp b/src/kvstore/raftex/RaftPart.cpp index 5699625fbe4..70918b5bc5e 100644 --- a/src/kvstore/raftex/RaftPart.cpp +++ b/src/kvstore/raftex/RaftPart.cpp @@ -1876,6 +1876,10 @@ void RaftPart::checkAndResetPeers(const std::vector& peers) { } bool RaftPart::leaseValid() { + std::lock_guard g(raftLock_); + if (hosts_.empty()) { + return true; + } // When majority has accepted a log, leader obtains a lease which last for heartbeat. // However, we need to take off the net io time. On the left side of the inequality is // the time duration since last time leader send a log (the log has been accepted as well)