Commit 677d9ebe authored by Georgios Bitzes's avatar Georgios Bitzes
Browse files

raft: pre-format string description of vote request

parent c106e502
Pipeline #1507424 failed with stages
in 89 minutes and 36 seconds
......@@ -537,10 +537,12 @@ void RaftDispatcher::warnIfLagging(LogIndex leaderCommitIndex) {
}
}
RaftVoteResponse RaftDispatcher::requestVote(RaftVoteRequest &req) {
RaftVoteResponse RaftDispatcher::requestVote(const RaftVoteRequest &req) {
std::string reqDescr = req.describe(false);
std::scoped_lock lock(raftCommand);
if(req.candidate == state.getMyself()) {
qdb_throw("received vote request from myself: " << req.describe(false));
qdb_throw("received vote request from myself: " << reqDescr);
}
if(!contains(state.getNodes(), req.candidate)) {
......@@ -569,7 +571,7 @@ RaftVoteResponse RaftDispatcher::requestVote(RaftVoteRequest &req) {
if(req.lastIndex <= journal.getCommitIndex()) {
if(req.lastIndex < journal.getLogStart()) {
qdb_event("Vetoing " << req.describe(false) << " because its lastIndex (" << req.lastIndex << ") is before my log start (" << journal.getLogStart() << ") - way too far behind me.");
qdb_event("Vetoing " << reqDescr << " because its lastIndex (" << req.lastIndex << ") is before my log start (" << journal.getLogStart() << ") - way too far behind me.");
return {snapshot->term, RaftVote::VETO};
}
......@@ -585,25 +587,25 @@ RaftVoteResponse RaftDispatcher::requestVote(RaftVoteRequest &req) {
// If the node were to ascend, it'll try and remove my req.lastIndex entry
// as inconsistent, which I consider committed already... Veto!
if(req.lastTerm != myLastIndexTerm) {
qdb_event("Vetoing " << req.describe(false) << " because its ascension would overwrite my committed entry with index " << req.lastIndex);
qdb_event("Vetoing " << reqDescr << " because its ascension would overwrite my committed entry with index " << req.lastIndex);
return {snapshot->term, RaftVote::VETO};
}
if(req.lastIndex+1 <= journal.getCommitIndex()) {
// If the node were to ascend, it would add a leadership marker, and try
// to remove my committed req.lastIndex+1 entry as conflicting. Veto!
qdb_event("Vetoing " << req.describe(false) << " because its ascension would overwrite my committed entry with index " << req.lastIndex+1 << " through the addition of a leadership marker.");
qdb_event("Vetoing " << reqDescr << " because its ascension would overwrite my committed entry with index " << req.lastIndex+1 << " through the addition of a leadership marker.");
return {snapshot->term, RaftVote::VETO};
}
}
if(snapshot->term != req.term) {
qdb_event("Rejecting " << req.describe(false) << " because of a term mismatch: " << snapshot->term << " vs " << req.term);
qdb_event("Rejecting " << reqDescr << " because of a term mismatch: " << snapshot->term << " vs " << req.term);
return {snapshot->term, RaftVote::REFUSED};
}
if(!snapshot->votedFor.empty() && snapshot->votedFor != req.candidate) {
qdb_event("Rejecting " << req.describe(false) << " since I've voted already in this term (" << snapshot->term << ") for " << snapshot->votedFor.toString());
qdb_event("Rejecting " << reqDescr << " since I've voted already in this term (" << snapshot->term << ") for " << snapshot->votedFor.toString());
return {snapshot->term, RaftVote::REFUSED};
}
......@@ -615,12 +617,12 @@ RaftVoteResponse RaftDispatcher::requestVote(RaftVoteRequest &req) {
}
if(req.lastTerm < myLastTerm) {
qdb_event("Rejecting " << req.describe(false) << " since my journal is more up-to-date, based on last term: " << myLastIndex << "," << myLastTerm << " vs " << req.lastIndex << "," << req.lastTerm);
qdb_event("Rejecting " << reqDescr << " since my journal is more up-to-date, based on last term: " << myLastIndex << "," << myLastTerm << " vs " << req.lastIndex << "," << req.lastTerm);
return {snapshot->term, RaftVote::REFUSED};
}
if(req.lastTerm == myLastTerm && req.lastIndex < myLastIndex) {
qdb_event("Rejecting " << req.describe(false) << " since my journal is more up-to-date, based on last index: " << myLastIndex << "," << myLastTerm << " vs " << req.lastIndex << "," << req.lastTerm);
qdb_event("Rejecting " << reqDescr << " since my journal is more up-to-date, based on last index: " << myLastIndex << "," << myLastTerm << " vs " << req.lastIndex << "," << req.lastTerm);
return {snapshot->term, RaftVote::REFUSED};
}
......@@ -637,12 +639,12 @@ RaftVoteResponse RaftDispatcher::requestVote(RaftVoteRequest &req) {
// Therefore, register the heartbeat twice just to be sure.
heartbeatTracker.heartbeat(std::chrono::steady_clock::now());
if(!state.grantVote(req.term, req.candidate)) {
qdb_warn("RaftState rejected " << req.describe(false) << " - probably benign race condition?");
qdb_warn("RaftState rejected " << reqDescr << " - probably benign race condition?");
return {snapshot->term, RaftVote::REFUSED};
}
heartbeatTracker.heartbeat(std::chrono::steady_clock::now());
qdb_event("Granted " << req.describe(false));
qdb_event("Granted " << reqDescr);
return {snapshot->term, RaftVote::GRANTED};
}
......
......@@ -60,7 +60,7 @@ public:
RaftHeartbeatResponse heartbeat(const RaftHeartbeatRequest &req);
RaftAppendEntriesResponse appendEntries(RaftAppendEntriesRequest &&req);
RaftVoteResponse requestVote(RaftVoteRequest &req);
RaftVoteResponse requestVote(const RaftVoteRequest &req);
//----------------------------------------------------------------------------
// Return health information
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment