diff --git a/arangod/Cluster/HeartbeatThread.cpp b/arangod/Cluster/HeartbeatThread.cpp index 38bc456929..0669153553 100644 --- a/arangod/Cluster/HeartbeatThread.cpp +++ b/arangod/Cluster/HeartbeatThread.cpp @@ -75,7 +75,7 @@ HeartbeatThread::HeartbeatThread(AgencyCallbackRegistry* agencyCallbackRegistry, _ioService(ioService), _backgroundJobsPosted(0), _backgroundJobsLaunched(0), - _backgroundJobRunning(false), + _backgroundJobScheduledOrRunning(false), _launchAnotherBackgroundJob(false) { } @@ -106,35 +106,26 @@ void HeartbeatThread::run() { // jobs in JS: auto self = shared_from_this(); _backgroundJob = [self, this]() { - { - MUTEX_LOCKER(mutexLocker, *_statusLock); - _backgroundJobRunning = true; - _launchAnotherBackgroundJob = false; - } - - LOG_TOPIC(DEBUG, Logger::HEARTBEAT) << "sync callback started " - << ++_backgroundJobsLaunched; + uint64_t jobNr = ++_backgroundJobsLaunched; + LOG_TOPIC(DEBUG, Logger::HEARTBEAT) << "sync callback started " << jobNr; { DBServerAgencySync job(this); job.work(); } - LOG_TOPIC(DEBUG, Logger::HEARTBEAT) << "sync callback ended " - << _backgroundJobsLaunched.load(); + LOG_TOPIC(DEBUG, Logger::HEARTBEAT) << "sync callback ended " << jobNr; - bool startAnother = false; { MUTEX_LOCKER(mutexLocker, *_statusLock); - _backgroundJobRunning = false; if (_launchAnotherBackgroundJob) { - startAnother = true; + LOG_TOPIC(DEBUG, Logger::HEARTBEAT) << "dispatching sync tail " + << ++_backgroundJobsPosted; + _launchAnotherBackgroundJob = false; + _ioService->post(_backgroundJob); + } else { + _backgroundJobScheduledOrRunning = false; + _launchAnotherBackgroundJob = false; } } - if (startAnother) { - LOG_TOPIC(DEBUG, Logger::HEARTBEAT) << "dispatching sync tail " - << ++_backgroundJobsPosted; - - _ioService->post(_backgroundJob); - } }; runDBServer(); } @@ -251,7 +242,7 @@ void HeartbeatThread::runDBServer() { if (agentPool.isObject()) { _agency.updateEndpoints(agentPool); } else { - LOG(DEBUG) << "Cannot find an agency persisted in RAFT 8|"; + LOG(TRACE) << "Cannot find an agency persisted in RAFT 8|"; } VPackSlice shutdownSlice = @@ -347,15 +338,13 @@ void HeartbeatThread::runDBServer() { _agencyCallbackRegistry->unregisterCallback(planAgencyCallback); int count = 0; while (++count < 3000) { - bool isInPlanChange; { MUTEX_LOCKER(mutexLocker, *_statusLock); - isInPlanChange = _backgroundJobRunning; + if (!_backgroundJobScheduledOrRunning) { + break; + } } - if (!isInPlanChange) { - break; - } - usleep(1000); + usleep(100000); } LOG_TOPIC(TRACE, Logger::HEARTBEAT) << "stopped heartbeat thread (DBServer version)"; @@ -421,7 +410,7 @@ void HeartbeatThread::runCoordinator() { if (agentPool.isObject()) { _agency.updateEndpoints(agentPool); } else { - LOG(DEBUG) << "Cannot find an agency persisted in RAFT 8|"; + LOG(TRACE) << "Cannot find an agency persisted in RAFT 8|"; } VPackSlice shutdownSlice = result.slice()[0].get( @@ -763,7 +752,7 @@ void HeartbeatThread::syncDBServerStatusQuo() { ci->invalidateCurrent(); } - if (_backgroundJobRunning) { + if (_backgroundJobScheduledOrRunning) { _launchAnotherBackgroundJob = true; return; } diff --git a/arangod/Cluster/HeartbeatThread.h b/arangod/Cluster/HeartbeatThread.h index 9c2ae9ba55..9e17cf8c4c 100644 --- a/arangod/Cluster/HeartbeatThread.h +++ b/arangod/Cluster/HeartbeatThread.h @@ -238,12 +238,13 @@ class HeartbeatThread : public Thread, std::atomic _backgroundJobsLaunched; ////////////////////////////////////////////////////////////////////////////// - /// @brief flag indicates whether or not a background job is running, this - /// and the next one about having to start another background job when - /// the current one is finished are protected by the statusLock. + /// @brief flag indicates whether or not a background job is either + /// scheduled with boost::asio or is already running, this and the + /// next one about having to start another background job when the + /// current one is finished are protected by the statusLock. ////////////////////////////////////////////////////////////////////////////// - bool _backgroundJobRunning; + bool _backgroundJobScheduledOrRunning; ////////////////////////////////////////////////////////////////////////////// /// @brief flag indicates whether or not a new background job needs