1
0
Fork 0

leader check needs to sit inside waitfor loop (#8445)

* leader check needs to sit inside waitfor loop
* Do not wait in Supervision for commits of new writes.
* CHANGELOG.
This commit is contained in:
Kaveh Vahedipour 2019-03-20 16:34:54 +01:00 committed by Max Neunhöffer
parent 6d107beeda
commit 237e079614
2 changed files with 19 additions and 16 deletions

View File

@ -340,6 +340,8 @@ devel
* fix crash in agency supervision when leadership is lost
* fix log spam in agency supervision when leader resigned
v3.4.1 (XXXX-XX-XX)
-------------------

View File

@ -850,23 +850,24 @@ void Supervision::run() {
}
}
// If anything was rafted, we need to
index_t leaderIndex = _agent->index();
if (leaderIndex != 0) {
// No point in progressing, if indexes cannot be advanced
while (!this->isStopping() && _agent->leading()) {
auto result = _agent->waitFor(leaderIndex);
if (result == Agent::raft_commit_t::TIMEOUT) { // Oh snap
// Note that we can get UNKNOWN if we have lost leadership or
// if we are shutting down. In both cases we just leave the loop.
LOG_TOPIC(WARN, Logger::SUPERVISION) << "Waiting for commits to be done ... ";
continue;
} else { // Good we can continue
break;
// If anything was rafted, we need to wait until it is replicated,
// otherwise it is not "committed" in the Raft sense. However, let's
// only wait for our changes not for new ones coming in during the wait.
if (_agent->leading()) {
index_t leaderIndex = _agent->index();
if (leaderIndex != 0) {
while (!this->isStopping() && _agent->leading()) {
auto result = _agent->waitFor(leaderIndex);
if (result == Agent::raft_commit_t::TIMEOUT) { // Oh snap
// Note that we can get UNKNOWN if we have lost leadership or
// if we are shutting down. In both cases we just leave the loop.
LOG_TOPIC(WARN, Logger::SUPERVISION)
<< "Waiting for commits to be done ... ";
continue;
} else { // Good we can continue
break;
}
}
}
}