8000 Bug fix/agency compactor deadlock by neunhoef · Pull Request #3335 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

Bug fix/agency compactor deadlock #3335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions arangod/Agency/Agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,21 @@ bool Agent::mergeConfiguration(VPackSlice const& persisted) {
/// Dtor shuts down thread
Agent::~Agent() {

// Give up if constituent breaks shutdown
// Give up if some subthread breaks shutdown
int counter = 0;
while (_constituent.isRunning()) {
while (_constituent.isRunning() || _compactor.isRunning() ||
(_config.supervision() && _supervision.isRunning()) ||
(_inception != nullptr && _inception->isRunning())) {
usleep(100000);

// emit warning after 5 seconds
if (++counter == 10 * 5) {
LOG_TOPIC(FATAL, Logger::AGENCY) << "constituent thread did not finish";
// emit warning after 15 seconds
if (++counter == 10 * 15) {
LOG_TOPIC(FATAL, Logger::AGENCY) << "some agency thread did not finish";
FATAL_ERROR_EXIT();
}
}

shutdown();

}

/// State machine
Expand Down
22 changes: 12 additions & 10 deletions arangod/Agency/Compactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ using namespace arangodb::consensus;

// @brief Construct with agent
Compactor::Compactor(Agent* agent) :
Thread("Compactor"), _agent(agent), _waitInterval(1000000) {
Thread("Compactor"), _agent(agent), _wakeupCompactor(false), _waitInterval(1000000) {
}


Expand All @@ -49,10 +49,14 @@ void Compactor::run() {

LOG_TOPIC(DEBUG, Logger::AGENCY) << "Starting compactor personality";

CONDITION_LOCKER(guard, _cv);

while (true) {
_cv.wait();
{
CONDITION_LOCKER(guard, _cv);
if (!_wakeupCompactor) {
_cv.wait();
}
}
_wakeupCompactor = false;

if (this->isStopping()) {
break;
Expand All @@ -74,8 +78,9 @@ void Compactor::run() {
void Compactor::wakeUp () {
{
CONDITION_LOCKER(guard, _cv);
guard.broadcast();
_wakeupCompactor = true;
}
_cv.broadcast();
}


Expand All @@ -86,9 +91,6 @@ void Compactor::beginShutdown() {

Thread::beginShutdown();

{
CONDITION_LOCKER(guard, _cv);
guard.broadcast();
}

wakeUp();

}
5 changes: 5 additions & 0 deletions arangod/Agency/Compactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ class Compactor : public arangodb::Thread {
private:

Agent* _agent; //< @brief Agent
// This condition variable is used for the compactor thread to go to
// sleep. One has to set _wakeupCompactor to true under the Mutex of _cv
// and then broadcast on the _cv to wake up the compactor thread.
// Note that the Mutex is not held during the actual compaction!
basics::ConditionVariable _cv;
bool _wakeupCompactor;
long _waitInterval; //< @brief Wait interval

};
Expand Down
0