From e37c4f9f33f6a21766fce38844b4de97ea48f5b9 Mon Sep 17 00:00:00 2001 From: Doodle <13706157+critical27@users.noreply.github.com> Date: Tue, 26 Oct 2021 17:02:05 +0800 Subject: [PATCH] only wait rpc time in Host::reset --- src/kvstore/raftex/Host.cpp | 20 ++++++++++++++++++++ src/kvstore/raftex/Host.h | 13 ++----------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/kvstore/raftex/Host.cpp b/src/kvstore/raftex/Host.cpp index a6ab1e6d5bf..29fedc2c9bd 100644 --- a/src/kvstore/raftex/Host.cpp +++ b/src/kvstore/raftex/Host.cpp @@ -36,6 +36,26 @@ Host::Host(const HostAddr& addr, std::shared_ptr part, bool isLearner) "%s[Host: %s:%d] ", part_->idStr_.c_str(), addr_.host.c_str(), addr_.port)), cachingPromise_(folly::SharedPromise()) {} +void Host::reset() { + std::unique_lock g(lock_); + LOG(WARNING) << idStr_ << "wtf " << requestOnGoing_; + bool ongoing = noMoreRequestCV_.wait_for( + g, std::chrono::milliseconds(FLAGS_raft_rpc_timeout_ms << 1), [this] { + return !requestOnGoing_; + }); + if (ongoing) { + LOG(WARNING) << idStr_ << "!requestOnGoing_ is still false after wait"; + requestOnGoing_ = false; + } + logIdToSend_ = 0; + logTermToSend_ = 0; + lastLogIdSent_ = 0; + lastLogTermSent_ = 0; + committedLogId_ = 0; + sendingSnapshot_ = false; + followerCommittedLogId_ = 0; +} + void Host::waitForStop() { std::unique_lock g(lock_); diff --git a/src/kvstore/raftex/Host.h b/src/kvstore/raftex/Host.h index 740a53efcd6..fa3b17f1bcb 100644 --- a/src/kvstore/raftex/Host.h +++ b/src/kvstore/raftex/Host.h @@ -39,17 +39,8 @@ class Host final : public std::enable_shared_from_this { stopped_ = true; } - void reset() { - std::unique_lock g(lock_); - noMoreRequestCV_.wait(g, [this] { return !requestOnGoing_; }); - logIdToSend_ = 0; - logTermToSend_ = 0; - lastLogIdSent_ = 0; - lastLogTermSent_ = 0; - committedLogId_ = 0; - sendingSnapshot_ = false; - followerCommittedLogId_ = 0; - } + // only invoked from RaftPart + void reset(); void waitForStop();