8000 Added comments and removed old code. · arangodb/arangodb@b665a06 · GitHub
[go: up one dir, main page]

Skip to content

Commit b665a06

Browse files
author
lamai93
committed
Added comments and removed old code.
1 parent 933641f commit b665a06

File tree

2 files changed

+32
-112
lines changed

2 files changed

+32
-112
lines changed

arangod/Cluster/HeartbeatThread.cpp

Lines changed: 28 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,19 @@ class HeartbeatBackgroundJobThread : public Thread {
8989

9090
~HeartbeatBackgroundJobThread() { shutdown(); }
9191

92+
//////////////////////////////////////////////////////////////////////////////
93+
/// @brief asks the thread to stop, but does not wait.
94+
//////////////////////////////////////////////////////////////////////////////
9295
void stop() {
9396
std::unique_lock<std::mutex> guard(_mutex);
9497
_stop = true;
9598
_condition.notify_one();
9699
}
97100

101+
//////////////////////////////////////////////////////////////////////////////
102+
/// @brief notifies the background thread: when the thread is sleeping, wakes
103+
/// it up. Otherwise sets a flag to start another round.
104+
//////////////////////////////////////////////////////////////////////////////
98105
void notify() {
99106
std::unique_lock<std::mutex> guard(_mutex);
100107
_anotherRun.store(true, std::memory_order_release);
@@ -146,11 +153,32 @@ class HeartbeatBackgroundJobThread : public Thread {
146153
HeartbeatThread *_heartbeatThread;
147154

148155
std::mutex _mutex;
156+
157+
//////////////////////////////////////////////////////////////////////////////
158+
/// @brief used to wake up the background thread
159+
/// guarded via _mutex.
160+
//////////////////////////////////////////////////////////////////////////////
149161
std::condition_variable _condition;
150162

163+
//////////////////////////////////////////////////////////////////////////////
164+
/// @brief Set by the HeartbeatThread when the BackgroundThread should stop
165+
/// guarded via _mutex.
166+
//////////////////////////////////////////////////////////////////////////////
151167
std::atomic<bool> _stop;
168+
169+
//////////////////////////////////////////////////////////////////////////////
170+
/// @brief wether the background thread sleeps or not
171+
/// guarded via _mutex.
172+
//////////////////////////////////////////////////////////////////////////////
152173
std::atomic<bool> _sleeping;
174+
175+
//////////////////////////////////////////////////////////////////////////////
176+
/// @brief when awake, the background thread will execute another round of
177+
/// phase 1 and phase 2, after resetting this to false
178+
/// guarded via _mutex.
179+
//////////////////////////////////////////////////////////////////////////////
153180
std::atomic<bool> _anotherRun;
181+
154182
uint64_t _backgroundJobsLaunched;
155183
};
156184
}
@@ -178,9 +206,6 @@ HeartbeatThread::HeartbeatThread(AgencyCallbackRegistry* agencyCallbackRegistry,
178206
_desiredVersions(std::make_shared<AgencyVersions>(0, 0)),
179207
_wasNotified(false),
180208
_backgroundJobsPosted(0),
181-
_backgroundJobsLaunched(0),
182-
_backgroundJobScheduledOrRunning(false),
183-
_launchAnotherBackgroundJob(false),
184209
_lastSyncTime(0),
185210
_maintenanceThread(nullptr) {
186211
}
@@ -196,81 +221,6 @@ HeartbeatThread::~HeartbeatThread() {
196221
shutdown();
197222
}
198223

199-
////////////////////////////////////////////////////////////////////////////////
200-
/// @brief running of heartbeat background jobs (in JavaScript), we run
201-
/// these by instantiating an object in class HeartbeatBackgroundJob,
202-
/// which is a std::function<void()> and holds a shared_ptr to the
203-
/// HeartbeatThread singleton itself. This instance is then posted to
204-
/// the io_service for execution in the thread pool. Should the heartbeat
205-
/// thread itself terminate during shutdown, then the HeartbeatThread
206-
/// singleton itself is still kept alive by the shared_ptr in the instance
207-
/// of HeartbeatBackgroundJob. The operator() method simply calls the
208-
/// runBackgroundJob() method of the heartbeat thread. Should this have
209-
/// to schedule another background job, then it can simply create a new
210-
/// HeartbeatBackgroundJob instance, again using shared_from_this() to
211-
/// create a new shared_ptr keeping the HeartbeatThread object alive.
212-
////////////////////////////////////////////////////////////////////////////////
213-
214-
/*class HeartbeatBackgroundJob {
215-
std::shared_ptr<HeartbeatThread> _heartbeatThread;
216-
double _startTime;
217-
std::string _schedulerInfo;
218-
public:
219-
explicit HeartbeatBackgroundJob(std::shared_ptr<HeartbeatThread> hbt,
220-
double startTime)
221-
: _heartbeatThread(hbt), _startTime(startTime),_schedulerInfo(SchedulerFeature::SCHEDULER->infoStatus()) {
222-
}
223-
224-
void operator()() {
225-
// first tell the scheduler that this thread is working:
226-
JobGuard guard(SchedulerFeature::SCHEDULER);
227-
guard.work();
228-
229-
double now = TRI_microtime();
230-
if (now > _startTime + 5.0) {
231-
LOG_TOPIC(ERR, Logger::HEARTBEAT) << "ALARM: Scheduling background job "
232-
"took " << now - _startTime
233-
<< " seconds, scheduler info at schedule time: " << _schedulerInfo
234-
<< ", scheduler info now: "
235-
<< SchedulerFeature::SCHEDULER->infoStatus();
236-
}
237-
//_heartbeatThread->runBackgroundJob();
238-
}
239-
};*/
240-
241-
242-
////////////////////////////////////////////////////////////////////////////////
243-
/// @brief method runBackgroundJob()
244-
////////////////////////////////////////////////////////////////////////////////
245-
246-
/*void HeartbeatThread::runBackgroundJob() {
247-
uint64_t jobNr = ++_backgroundJobsLaunched;
248-
LOG_TOPIC(DEBUG, Logger::HEARTBEAT) << "sync callback started " << jobNr;
249-
{
250-
DBServerAgencySync job(this);
251-
job.work();
252-
}
253-
LOG_TOPIC(DEBUG, Logger::HEARTBEAT) << "sync callback ended " << jobNr;
254-
255-
{
256-
MUTEX_LOCKER(mutexLocker, *_statusLock);
257-
TRI_ASSERT(_backgroundJobScheduledOrRunning);
258-
259-
if (_launchAnotherBackgroundJob) {
260-
jobNr = ++_backgroundJobsPosted;
261-
LOG_TOPIC(DEBUG, Logger::HEARTBEAT) << "dispatching sync tail " << jobNr;
262-
_launchAnotherBackgroundJob = false;
263-
264-
// the JobGuard is in the operator() of HeartbeatBackgroundJob
265-
_lastSyncTime = TRI_microtime();
266-
SchedulerFeature::SCHEDULER->post(
267-
HeartbeatBackgroundJob(shared_from_this(), _lastSyncTime), false);
268-
} else {
269-
_backgroundJobScheduledOrRunning = false;
270-
_launchAnotherBackgroundJob = false;
271-
}
272-
}
273-
}*/
274224

275225
////////////////////////////////////////////////////////////////////////////////
276226
/// @brief heartbeat main loop
@@ -1297,20 +1247,11 @@ void HeartbeatThread::syncDBServerStatusQuo(bool asyncPush) {
12971247
ci->invalidateCurrent();
12981248
}
12991249

1300-
/*if (_backgroundJobScheduledOrRunning) {
1301-
_launchAnotherBackgroundJob = true;
1302-
return;
1303-
}*/
1304-
13051250
// schedule a job for the change:
13061251
uint64_t jobNr = ++_backgroundJobsPosted;
13071252
LOG_TOPIC(DEBUG, Logger::HEARTBEAT) << "dispatching sync " << jobNr;
1308-
_backgroundJobScheduledOrRunning = true;
13091253

1310-
// the JobGuard is in the operator() of HeartbeatBackgroundJob
13111254
_lastSyncTime = TRI_microtime();
1312-
//SchedulerFeature::SCHEDULER->post(
1313-
// HeartbeatBackgroundJob(shared_from_this(), _lastSyncTime), false);
13141255
TRI_ASSERT(_maintenanceThread != nullptr);
13151256
_maintenanceThread->notify();
13161257

arangod/Cluster/HeartbeatThread.h

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -270,34 +270,13 @@ class HeartbeatThread : public CriticalThread,
270270

271271
std::atomic<uint64_t> _backgroundJobsPosted;
272272

273-
//////////////////////////////////////////////////////////////////////////////
274-
/// @brief number of background jobs that have been launched by the scheduler
275-
//////////////////////////////////////////////////////////////////////////////
276-
277-
std::atomic<uint64_t> _backgroundJobsLaunched;
278-
279-
//////////////////////////////////////////////////////////////////////////////
280-
/// @brief flag indicates whether or not a background job is either
281-
/// scheduled with boost::asio or is already running, this and the
282-
/// next one about having to start another background job when the
283-
/// current one is finished are protected by the statusLock.
284-
//////////////////////////////////////////////////////////////////////////////
285-
286-
bool _backgroundJobScheduledOrRunning;
273+
// when was the sync routine last run?
274+
double _lastSyncTime;
287275

288276
//////////////////////////////////////////////////////////////////////////////
289-
/// @brief flag indicates whether or not a new background job needs
290-
/// to be started when the current one has terminated. This and the
291-
/// previous one are protected by the statusLock.
277+
/// @brief handle of the dedicated thread to execute the phase 1 and phase 2
278+
/// code. Only created on dbservers.
292279
//////////////////////////////////////////////////////////////////////////////
293-
294-
bool _launchAnotherBackgroundJob;
295-
296-
// when was the javascript sync routine last run?
297-
double _lastSyncTime;
298-
299-
300-
301280
std::unique_ptr<HeartbeatBackgroundJobThread> _maintenanceThread;
302281
};
303282
}

0 commit comments

Comments
 (0)
0