8000 BTS-519: avoid holding 2 mutexes at the same time by jsteemann · Pull Request #14511 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

BTS-519: avoid holding 2 mutexes at the same time #14511

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 2 commits into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
one more change to reduce holding the global _mutex
  • Loading branch information
jsteemann committed Jul 16, 2021
commit eba5b34f94c36e05719eb75567aee7a7e529001c
2 changes: 2 additions & 0 deletions arangod/Pregel/Conductor.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ class Conductor : public std::enable_shared_from_this<Conductor> {
}

bool canBeGarbageCollected() const;

uint64_t executionNumber() const { return _executionNumber; }

private:
void cancelNoLock();
Expand Down
37 changes: 26 additions & 11 deletions arangod/Pregel/PregelFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,19 +335,34 @@ std::shared_ptr<Conductor> PregelFeature::conductor(uint64_t executionNumber) {

void PregelFeature::garbageCollectConductors() try {
// iterate over all conductors and remove the ones which can be garbage-collected
MUTEX_LOCKER(guard, _mutex);
for (auto it = _conductors.begin(); it != _conductors.end(); /*no hoisting*/) {
if (it->second.conductor->canBeGarbageCollected()) {
uint64_t executionNumber = it->first;

it->second.conductor->cancel();
it = _conductors.erase(it);

_workers.erase(executionNumber);
} else {
++it;
std::vector<std::shared_ptr<Conductor>> conductors;

// copy out shared-ptrs of Conductors under the mutex
{
MUTEX_LOCKER(guard, _mutex);
for (auto const& it : _conductors) {
if (it.second.conductor->canBeGarbageCollected()) {
if (conductors.empty()) {
conductors.reserve(8);
}
conductors.emplace_back(it.second.conductor);
}
}
}

// cancel and kill conductors without holding the mutex
// permanently
for (auto& c : conductors) {
c->cancel();
}

MUTEX_LOCKER(guard, _mutex);
for (auto& c : conductors) {
uint64_t executionNumber = c->executionNumber();

_conductors.erase(executionNumber);
_workers.erase(executionNumber);
}
} catch (...) {}

void PregelFeature::addWorker(std::shared_ptr<IWorker>&& w, uint64_t executionNumber) {
Expand Down
0