diff --git a/arangod/Agency/Agent.cpp b/arangod/Agency/Agent.cpp index 9a72923d9f..6a2ebc850f 100644 --- a/arangod/Agency/Agent.cpp +++ b/arangod/Agency/Agent.cpp @@ -537,10 +537,7 @@ void Agent::sendAppendEntriesRPC() { // message if a timeout occurs. _lastSent[followerId] = system_clock::now(); - // _constituent.notifyHeartbeatSent(followerId); - // Do not notify constituent, because the AppendEntriesRPC here could - // take a very long time, so this must not disturb the empty ones - // being sent out. + _constituent.notifyHeartbeatSent(followerId); LOG_TOPIC(DEBUG, Logger::AGENCY) << "Appending (" << (uint64_t) (TRI_microtime() * 1000000000.0) << ") " @@ -594,13 +591,8 @@ void Agent::sendEmptyAppendEntriesRPC(std::string followerId) { 3 * _config.minPing() * _config.timeoutMult(), true); _constituent.notifyHeartbeatSent(followerId); - double now = TRI_microtime(); LOG_TOPIC(DEBUG, Logger::AGENCY) << "Sending empty appendEntriesRPC to follower " << followerId; - double diff = TRI_microtime() - now; - if (diff > 0.01) { - LOG_TOPIC(DEBUG, Logger::AGENCY) << "Logging of a line took more than 1/100 of a second, this is bad:" << diff; - } } void Agent::advanceCommitIndex() { diff --git a/arangod/Agency/Constituent.cpp b/arangod/Agency/Constituent.cpp index 264e9f0c25..469064162f 100644 --- a/arangod/Agency/Constituent.cpp +++ b/arangod/Agency/Constituent.cpp @@ -271,7 +271,7 @@ void Constituent::candidate() { if (_leaderID != NO_LEADER) { _leaderID = NO_LEADER; - LOG_TOPIC(DEBUG, Logger::AGENCY) << "Set _leaderID to NO_LEADER in Constituent::candidate"; + LOG_TOPIC(DEBUG, Logger::AGENCY) << "Set _leaderID to NO_LEADER"; } if (_role != CANDIDATE) { @@ -739,12 +739,17 @@ void Constituent::run() { } else if (role == CANDIDATE) { callElection(); // Run for office } else { - double interval = 0.25 * _agent->config().minPing() - * _agent->config().timeoutMult(); + // This is 1/4th of the minPing timeout (_cv.wait() below is in + // microseconds): + uint64_t timeout = + static_cast(250000.0 * _agent->config().minPing() * + _agent->config().timeoutMult()); + { + CONDITION_LOCKER(guardv, _cv); + _cv.wait(timeout); + } double now = TRI_microtime(); - double nextWakeup = interval; // might be lowered below - std::string const myid = _agent->id(); for (auto const& followerId : _agent->config().active()) { if (followerId != myid) { @@ -752,21 +757,10 @@ void Constituent::run() { { MUTEX_LOCKER(guard, _heartBeatMutex); auto it = _lastHeartbeatSent.find(followerId); - if (it == _lastHeartbeatSent.end()) { + if (it == _lastHeartbeatSent.end() || + now - it->second > _agent->config().minPing() + * _agent->config().timeoutMult() / 4.0) { needed = true; - } else { - double diff = now - it->second; - if (diff >= interval) { - needed = true; - } else { - // diff < interval, so only needed again in interval-diff s - double waitOnly = interval - diff; - if (nextWakeup > waitOnly) { - nextWakeup = waitOnly; - } - LOG_TOPIC(DEBUG, Logger::AGENCY) - << "No need for empty AppendEntriesRPC: " << diff; - } } } if (needed) { @@ -774,14 +768,6 @@ void Constituent::run() { } } } - - // This is the smallest time until any of the followers need a - // new empty heartbeat: - uint64_t timeout = static_cast(1000000.0 * nextWakeup); - { - CONDITION_LOCKER(guardv, _cv); - _cv.wait(timeout); - } } } }