mirror of https://gitee.com/bigwinds/arangodb
Revert "Send out empty heartbeats regardless of non-empty AppendEntriesRPC."
This reverts commit e974501446
.
This commit is contained in:
parent
2852f80b5a
commit
af3f977997
|
@ -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() {
|
||||
|
|
|
@ -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<uint64_t>(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<uint64_t>(1000000.0 * nextWakeup);
|
||||
{
|
||||
CONDITION_LOCKER(guardv, _cv);
|
||||
_cv.wait(timeout);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue