Skip to content
Snippets Groups Projects
Commit 677d9ebe authored by Georgios Bitzes's avatar Georgios Bitzes
Browse files

raft: pre-format string description of vote request

parent c106e502
No related branches found
No related tags found
No related merge requests found
Pipeline #1507424 failed
...@@ -537,10 +537,12 @@ void RaftDispatcher::warnIfLagging(LogIndex leaderCommitIndex) { ...@@ -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); std::scoped_lock lock(raftCommand);
if(req.candidate == state.getMyself()) { 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)) { if(!contains(state.getNodes(), req.candidate)) {
...@@ -569,7 +571,7 @@ RaftVoteResponse RaftDispatcher::requestVote(RaftVoteRequest &req) { ...@@ -569,7 +571,7 @@ RaftVoteResponse RaftDispatcher::requestVote(RaftVoteRequest &req) {
if(req.lastIndex <= journal.getCommitIndex()) { if(req.lastIndex <= journal.getCommitIndex()) {
if(req.lastIndex < journal.getLogStart()) { 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}; return {snapshot->term, RaftVote::VETO};
} }
...@@ -585,25 +587,25 @@ RaftVoteResponse RaftDispatcher::requestVote(RaftVoteRequest &req) { ...@@ -585,25 +587,25 @@ RaftVoteResponse RaftDispatcher::requestVote(RaftVoteRequest &req) {
// If the node were to ascend, it'll try and remove my req.lastIndex entry // If the node were to ascend, it'll try and remove my req.lastIndex entry
// as inconsistent, which I consider committed already... Veto! // as inconsistent, which I consider committed already... Veto!
if(req.lastTerm != myLastIndexTerm) { 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}; return {snapshot->term, RaftVote::VETO};
} }
if(req.lastIndex+1 <= journal.getCommitIndex()) { if(req.lastIndex+1 <= journal.getCommitIndex()) {
// If the node were to ascend, it would add a leadership marker, and try // 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! // 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}; return {snapshot->term, RaftVote::VETO};
} }
} }
if(snapshot->term != req.term) { 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}; return {snapshot->term, RaftVote::REFUSED};
} }
if(!snapshot->votedFor.empty() && snapshot->votedFor != req.candidate) { 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}; return {snapshot->term, RaftVote::REFUSED};
} }
...@@ -615,12 +617,12 @@ RaftVoteResponse RaftDispatcher::requestVote(RaftVoteRequest &req) { ...@@ -615,12 +617,12 @@ RaftVoteResponse RaftDispatcher::requestVote(RaftVoteRequest &req) {
} }
if(req.lastTerm < myLastTerm) { 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}; return {snapshot->term, RaftVote::REFUSED};
} }
if(req.lastTerm == myLastTerm && req.lastIndex < myLastIndex) { 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}; return {snapshot->term, RaftVote::REFUSED};
} }
...@@ -637,12 +639,12 @@ RaftVoteResponse RaftDispatcher::requestVote(RaftVoteRequest &req) { ...@@ -637,12 +639,12 @@ RaftVoteResponse RaftDispatcher::requestVote(RaftVoteRequest &req) {
// Therefore, register the heartbeat twice just to be sure. // Therefore, register the heartbeat twice just to be sure.
heartbeatTracker.heartbeat(std::chrono::steady_clock::now()); heartbeatTracker.heartbeat(std::chrono::steady_clock::now());
if(!state.grantVote(req.term, req.candidate)) { 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}; return {snapshot->term, RaftVote::REFUSED};
} }
heartbeatTracker.heartbeat(std::chrono::steady_clock::now()); heartbeatTracker.heartbeat(std::chrono::steady_clock::now());
qdb_event("Granted " << req.describe(false)); qdb_event("Granted " << reqDescr);
return {snapshot->term, RaftVote::GRANTED}; return {snapshot->term, RaftVote::GRANTED};
} }
......
...@@ -60,7 +60,7 @@ public: ...@@ -60,7 +60,7 @@ public:
RaftHeartbeatResponse heartbeat(const RaftHeartbeatRequest &req); RaftHeartbeatResponse heartbeat(const RaftHeartbeatRequest &req);
RaftAppendEntriesResponse appendEntries(RaftAppendEntriesRequest &&req); RaftAppendEntriesResponse appendEntries(RaftAppendEntriesRequest &&req);
RaftVoteResponse requestVote(RaftVoteRequest &req); RaftVoteResponse requestVote(const RaftVoteRequest &req);
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// Return health information // Return health information
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment