Skip to content

Commit

Permalink
Fix failed UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
heng committed Aug 21, 2019
1 parent 471171e commit 7012a56
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
19 changes: 10 additions & 9 deletions src/kvstore/raftex/Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ folly::Future<cpp2::AppendLogResponse> Host::appendLogs(
if (cachingPromise_.size() <= FLAGS_max_outstanding_requests) {
pendingReq_ = std::make_tuple(term,
logId,
committedLogId,
prevLogTerm,
prevLogId);
committedLogId);
return cachingPromise_.getFuture();
} else {
PLOG_EVERY_N(INFO, 200) << idStr_
Expand All @@ -155,14 +153,17 @@ folly::Future<cpp2::AppendLogResponse> Host::appendLogs(
VLOG(2) << idStr_ << "About to send the AppendLog request";

// No request is ongoing, let's send a new request
if (UNLIKELY(lastLogIdSent_ == 0 && lastLogTermSent_ == 0)) {
LOG(INFO) << idStr_ << "This is the first time to send the logs to this host";
lastLogIdSent_ = prevLogId;
lastLogTermSent_ = prevLogTerm;
}
CHECK_GE(prevLogTerm, lastLogTermSent_);
CHECK_GE(prevLogId, lastLogIdSent_);
logTermToSend_ = term;
logIdToSend_ = logId;
lastLogTermSent_ = prevLogTerm;
lastLogIdSent_ = prevLogId;
committedLogId_ = committedLogId;
pendingReq_ = std::make_tuple(0, 0, 0, 0, 0);
pendingReq_ = std::make_tuple(0, 0, 0);
promise_ = std::move(cachingPromise_);
cachingPromise_ = folly::SharedPromise<cpp2::AppendLogResponse>();
ret = promise_.getFuture();
Expand All @@ -183,7 +184,7 @@ void Host::setResponse(const cpp2::AppendLogResponse& r) {
promise_.setValue(r);
cachingPromise_.setValue(r);
cachingPromise_ = folly::SharedPromise<cpp2::AppendLogResponse>();
pendingReq_ = std::make_tuple(0, 0, 0, 0, 0);
pendingReq_ = std::make_tuple(0, 0, 0);
requestOnGoing_ = false;
}

Expand Down Expand Up @@ -257,7 +258,7 @@ void Host::appendLogsInternal(folly::EventBase* eb,
self->promise_ = std::move(self->cachingPromise_);
self->cachingPromise_
= folly::SharedPromise<cpp2::AppendLogResponse>();
self->pendingReq_ = std::make_tuple(0, 0, 0, 0, 0);
self->pendingReq_ = std::make_tuple(0, 0, 0);
}
}

Expand Down Expand Up @@ -437,7 +438,7 @@ folly::Future<cpp2::AppendLogResponse> Host::sendAppendLogRequest(

bool Host::noRequest() const {
CHECK(!lock_.try_lock());
static auto emptyTup = std::make_tuple(0, 0, 0, 0, 0);
static auto emptyTup = std::make_tuple(0, 0, 0);
return pendingReq_ == emptyTup;
}

Expand Down
6 changes: 3 additions & 3 deletions src/kvstore/raftex/Host.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ class Host final : public std::enable_shared_from_this<Host> {
}

private:
// <term, logId, committedLogId, lastLogTermSent, lastLogIdSent>
using Request = std::tuple<TermID, LogID, LogID, TermID, LogID>;
// <term, logId, committedLogId>
using Request = std::tuple<TermID, LogID, LogID>;

std::shared_ptr<RaftPart> part_;
const HostAddr addr_;
Expand All @@ -115,7 +115,7 @@ class Host final : public std::enable_shared_from_this<Host> {
folly::SharedPromise<cpp2::AppendLogResponse> promise_;
folly::SharedPromise<cpp2::AppendLogResponse> cachingPromise_;

Request pendingReq_{0, 0, 0, 0, 0};
Request pendingReq_{0, 0, 0};

// These logId and term pointing to the latest log we need to send
LogID logIdToSend_{0};
Expand Down
3 changes: 3 additions & 0 deletions src/kvstore/raftex/RaftPart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,9 @@ bool RaftPart::needToStartElection() {
role_ == Role::FOLLOWER &&
(lastMsgRecvDur_.elapsedInSec() >= FLAGS_raft_heartbeat_interval_secs ||
term_ == 0)) {
LOG(INFO) << idStr_ << "Start leader election, reason: lastMsgDur "
<< lastMsgRecvDur_.elapsedInSec()
<< ", term " << term_;
role_ = Role::CANDIDATE;
}

Expand Down
2 changes: 1 addition & 1 deletion src/kvstore/raftex/test/LogCommandTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ TEST_F(LogCommandTest, CommandInMiddle) {

ASSERT_EQ(3, leader_->commitTimes_);
// need to sleep a bit more
sleep(1);
sleep(FLAGS_raft_heartbeat_interval_secs + 1);
checkConsensus(copies_, 0, 9, msgs);
}

Expand Down

0 comments on commit 7012a56

Please sign in to comment.