Skip to content

Commit

Permalink
only wait rpc time in Host::reset
Browse files Browse the repository at this point in the history
  • Loading branch information
critical27 committed Oct 26, 2021
1 parent e8c20eb commit e37c4f9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
20 changes: 20 additions & 0 deletions src/kvstore/raftex/Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ Host::Host(const HostAddr& addr, std::shared_ptr<RaftPart> part, bool isLearner)
"%s[Host: %s:%d] ", part_->idStr_.c_str(), addr_.host.c_str(), addr_.port)),
cachingPromise_(folly::SharedPromise<cpp2::AppendLogResponse>()) {}

void Host::reset() {
std::unique_lock<std::mutex> 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<std::mutex> g(lock_);

Expand Down
13 changes: 2 additions & 11 deletions src/kvstore/raftex/Host.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,8 @@ class Host final : public std::enable_shared_from_this<Host> {
stopped_ = true;
}

void reset() {
std::unique_lock<std::mutex> 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();

Expand Down

0 comments on commit e37c4f9

Please sign in to comment.