8000 small cleanup w.r.t. HeartbeatThread (#17979) · cloudhub-js/arangodb@11894ba · GitHub
[go: up one dir, main page]

Skip to content

Commit 11894ba

Browse files
authored
small cleanup w.r.t. HeartbeatThread (arangodb#17979)
1 parent cda4173 commit 11894ba

File tree

7 files changed

+37
-28
lines changed

7 files changed

+37
-28
lines changed

arangod/Cluster/ActionBase.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "ApplicationFeatures/ApplicationServer.h"
2828
#include "Basics/TimeString.h"
2929
#include "Cluster/ClusterFeature.h"
30-
#include "Cluster/HeartbeatThread.h"
3130
#include "Cluster/MaintenanceFeature.h"
3231
#include "Logger/LogMacros.h"
3332
#include "Logger/Logger.h"
@@ -96,8 +95,8 @@ bool ActionBase::matches(std::unordered_set<std::string> const& labels) const {
9695
return true;
9796
}
9897

99-
bool ActionBase::fastTrack() const {
100-
return _labels.find(FAST_TRACK) != _labels.end();
98+
bool ActionBase::fastTrack() const noexcept {
99+
return _labels.contains(FAST_TRACK);
101100
}
102101

103102
/// @brief execution finished successfully or failed ... and race timer expired

arangod/Cluster/ActionBase.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ class ActionBase {
7575
virtual bool done() const;
7676

7777
/// @brief waiting for a worker to grab it and go!
78-
bool runnable() const { return READY == _state; }
78+
bool runnable() const noexcept { return READY == _state; }
7979

8080
/// @brief did initialization have issues?
81-
bool ok() const { return FAILED != _state; }
81+
bool ok() const noexcept { return FAILED != _state; }
8282

8383
/// @brief adjust state of object, assumes WRITE lock on _actionRegistryLock
84-
ActionState state() const { return _state; }
84+
ActionState state() const noexcept { return _state; }
8585

86-
bool fastTrack() const;
86+
bool fastTrack() const noexcept;
8787

8888
void notify();
8989

arangod/Cluster/HeartbeatThread.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ using namespace arangodb;
7171
using namespace arangodb::application_features;
7272
using namespace arangodb::rest;
7373

74-
std::atomic<bool> HeartbeatThread::HasRunOnce(false);
75-
7674
namespace arangodb {
7775

7876
class HeartbeatBackgroundJobThread : public Thread {
@@ -224,6 +222,7 @@ HeartbeatThread::HeartbeatThread(Server& server,
224222
_lastSuccessfulVersion(0),
225223
_currentPlanVersion(0),
226224
_ready(false),
225+
_hasRunOnce(false),
227226
_currentVersions(0, 0),
228227
_desiredVersions(std::make_shared<AgencyVersions>(0, 0)),
229228
_backgroundJobsPosted(0),
@@ -1401,14 +1400,14 @@ bool HeartbeatThread::handlePlanChangeCoordinator(uint64_t currentPlanVersion) {
14011400
<< "creating local database '" << dbName
14021401
<< "' failed: " << res.errorMessage();
14031402
} else {
1404-
HasRunOnce.store(true, std::memory_order_release);
1403+
_hasRunOnce.store(true, std::memory_order_release);
14051404
}
14061405
} else {
14071406
if (vocbase->isSystem()) {
14081407
// workaround: _system collection already exists now on every
1409-
// coordinator setting HasRunOnce lets coordinator startup continue
1408+
// coordinator setting _hasRunOnce lets coordinator startup continue
14101409
TRI_ASSERT(vocbase->id() == 1);
1411-
HasRunOnce.store(true, std::memory_order_release);
1410+
_hasRunOnce.store(true, std::memory_order_release);
14121411
}
14131412
}
14141413
}

arangod/Cluster/HeartbeatThread.h

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@
3434
#include "Metrics/Fwd.h"
3535

3636
#include <velocypack/Slice.h>
37+
38+
#include <atomic>
3739
#include <chrono>
40+
#include <cstdint>
41+
#include <memory>
42+
#include <string>
3843

3944
namespace arangodb {
4045
namespace application_features {
@@ -48,7 +53,7 @@ struct AgencyVersions {
4853
AgencyVersions(uint64_t _plan, uint64_t _current)
4954
: plan(_plan), current(_plan) {}
5055

51-
explicit AgencyVersions(const DBServerAgencySyncResult& result)
56+
explicit AgencyVersions(DBServerAgencySyncResult const& result)
5257
: plan(result.planIndex), current(result.currentIndex) {}
5358
};
5459

@@ -62,7 +67,6 @@ class HeartbeatThread : public ServerThread<ArangodServer>,
6267
uint64_t maxFailsBeforeWarning);
6368
~HeartbeatThread();
6469

65-
public:
6670
//////////////////////////////////////////////////////////////////////////////
6771
/// @brief initializes the heartbeat
6872
//////////////////////////////////////////////////////////////////////////////
@@ -90,8 +94,8 @@ class HeartbeatThread : public ServerThread<ArangodServer>,
9094
/// this is used on the coordinator only
9195
//////////////////////////////////////////////////////////////////////////////
9296

93-
static bool hasRunOnce() {
94-
return HasRunOnce.load(std::memory_order_acquire);
97+
bool hasRunOnce() const noexcept {
98+
return _hasRunOnce.load(std::memory_order_acquire);
9599
}
96100

97101
//////////////////////////////////////////////////////////////////////////////
@@ -103,6 +107,12 @@ class HeartbeatThread : public ServerThread<ArangodServer>,
103107
/// @brief Reference to agency sync job
104108
DBServerAgencySync& agencySync();
105109

110+
//////////////////////////////////////////////////////////////////////////////
111+
/// @brief bring the db server in sync with the desired state
112+
//////////////////////////////////////////////////////////////////////////////
113+
114+
void notify();
115+
106116
protected:
107117
//////////////////////////////////////////////////////////////////////////////
108118
/// @brief heartbeat main loop
@@ -182,13 +192,6 @@ class HeartbeatThread : public ServerThread<ArangodServer>,
182192
void handleFoxxQueueVersionChange(
183193
arangodb::velocypack::Slice foxxQueueVersion);
184194

185-
public:
186-
//////////////////////////////////////////////////////////////////////////////
187-
/// @brief bring the db server in sync with the desired state
188-
//////////////////////////////////////////////////////////////////////////////
189-
190-
void notify();
191-
192195
private:
193196
//////////////////////////////////////////////////////////////////////////////
194197
/// @brief update the local agent pool from the slice
@@ -273,7 +276,7 @@ class HeartbeatThread : public ServerThread<ArangodServer>,
273276
/// this is used on the coordinator only
274277
//////////////////////////////////////////////////////////////////////////////
275278

276-
static std::atomic<bool> HasRunOnce;
279+
std::atomic<bool> _hasRunOnce;
277280

278281
//////////////////////////////////////////////////////////////////////////////
279282
/// @brief keeps track of the currently installed versions

arangod/Cluster/MaintenanceRestHandler.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include "Basics/conversions.h"
3030
#include "Cluster/ClusterFeature.h"
3131
#include "Cluster/DBServerAgencySync.h"
32-
#include "Cluster/HeartbeatThread.h"
3332
#include "Cluster/MaintenanceFeature.h"
3433
#include "Logger/LogMacros.h"
3534
#include "Logger/Logger.h"

arangod/Cluster/RestClusterHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ void RestClusterHandler::handleCommandEndpoints() {
229229
}
230230
}
231231

232-
// master always in front
232+
// leader always in front
233233
endpoints.insert(endpoints.begin(), leaderId);
234234

235235
} else {

arangod/RestServer/ServerFeature.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "Basics/ArangoGlobalContext.h"
2929
#include "Basics/application-exit.h"
3030
#include "Basics/process-utils.h"
31+
#include "Cluster/ClusterFeature.h"
3132
#include "Cluster/HeartbeatThread.h"
3233
#include "Cluster/ServerState.h"
3334
#include "Logger/LogMacros.h"
@@ -300,11 +301,19 @@ void ServerFeature::waitForHeartbeat() {
300301
return;
301302
}
302303

304+
if (!server().hasFeature<ClusterFeature>()) {
305+
return;
306+
}
307+
308+
auto& cf = server().getFeature<ClusterFeature>();
309+
303310
while (true) {
304-
if (HeartbeatThread::hasRunOnce()) {
311+
auto heartbeatThread = cf.heartbeatThread();
312+
TRI_ASSERT(heartbeatThread != nullptr);
313+
if (heartbeatThread == nullptr || heartbeatThread->hasRunOnce()) {
305314
break;
306315
}
307-
std::this_thread::sleep_for(std::chrono::milliseconds(100));
316+
std::this_thread::sleep_for(std::chrono::milliseconds(10));
308317
}
309318
}
310319

0 commit comments

Comments
 (0)
0