Skip to content

Commit

Permalink
fix always loop when no log need to send
Browse files Browse the repository at this point in the history
  • Loading branch information
liwenhui-soul committed Jan 26, 2022
1 parent be4b679 commit 54813bb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/kvstore/raftex/Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,18 @@ Host::prepareAppendLogRequest() {
<< idStr_ << "My lastLogId in wal is " << part_->wal()->lastLogId()
<< ", but you are seeking " << lastLogIdSent_ + 1
<< ", so i have nothing to send, logIdToSend_ = " << logIdToSend_;
return nebula::cpp2::ErrorCode::E_RAFT_NO_WAL_FOUND;
auto req = std::make_shared<cpp2::AppendLogRequest>();
req->space_ref() = part_->spaceId();
req->part_ref() = part_->partitionId();
req->current_term_ref() = logTermToSend_;
req->committed_log_id_ref() = committedLogId_;
req->leader_addr_ref() = part_->address().host;
req->leader_port_ref() = part_->address().port;
req->last_log_term_sent_ref() = lastLogTermSent_;
// the purpose of setting last_log_id to -1 is to make remote host return committedLogId which
// could be used as lastLogIdSent in next loop
req->last_log_id_sent_ref() = -1;
return req;
}

auto it = part_->wal()->iterator(lastLogIdSent_ + 1, logIdToSend_);
Expand Down
6 changes: 6 additions & 0 deletions src/kvstore/raftex/RaftPart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,12 @@ void RaftPart::processAppendLogResponses(const AppendLogResponses& resps,
LOG_EVERY_N(WARNING, 100) << idStr_ << "Only " << numSucceeded
<< " hosts succeeded, Need to try again";
usleep(1000);
{
std::lock_guard<std::mutex> g(raftLock_);
// wal could be rollback between two cycles, if we still use the old lastLogId, we may always
// get E_RAFT_NO_WAL_FOUND
lastLogId = std::min(wal_->lastLogId(), lastLogId);
}
replicateLogs(eb, std::move(iter), currTerm, lastLogId, committedId, prevLogTerm, prevLogId);
}
}
Expand Down

0 comments on commit 54813bb

Please sign in to comment.