8000 Fix a rare shutdown race in RocksDBShaCalculatorThread by jsteemann · Pull Request #14709 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

Fix a rare shutdown race in RocksDBShaCalculatorThread #14709

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 7 commits into from
Sep 3, 2021
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
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
v3.8.2 (XXXX-XX-XX)
-------------------

* Fix a rare shutdown race in RocksDBShaCalculatorThread.

* Reduce internal priority of AQL execution. This prevents possible deadlocks
with modification operations in a cluster and replicationFactor >= 2, and can
also improve responsiveness under high load of AQL queries.
Expand Down
11 changes: 11 additions & 0 deletions arangod/RocksDBEngine/Listeners/RocksDBShaCalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,22 @@ RocksDBShaCalculator::RocksDBShaCalculator(application_features::ApplicationServ

/// @brief Shutdown the background thread only if it was ever started
RocksDBShaCalculator::~RocksDBShaCalculator() {
// when we get here the background thread should have been stopped
// already.
TRI_ASSERT(!_shaThread.isRunning());
waitForShutdown();
}

void RocksDBShaCalculator::waitForShutdown() {
// send shutdown signal to SHA thread
_shaThread.beginShutdown();

_shaThread.signalLoop();
CONDITION_LOCKER(locker, _threadDone);
if (_shaThread.isRunning()) {
_threadDone.wait();
}
// now we are sure the SHA thread is not running anymore
}

void RocksDBShaCalculator::OnFlushCompleted(rocksdb::DB* db,
Expand Down
4 changes: 3 additions & 1 deletion arangod/RocksDBEngine/Listeners/RocksDBShaCalculator.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ class RocksDBShaCalculator : public rocksdb::EventListener {

void OnCompactionCompleted(rocksdb::DB* db, const rocksdb::CompactionJobInfo& ci) override;

void beginShutdown() { _shaThread.beginShutdown(); };
void beginShutdown() { _shaThread.beginShutdown(); }

void waitForShutdown();

protected:
/// thread to perform sha256 and file deletes in background
Expand Down
6 changes: 5 additions & 1 deletion arangod/RocksDBEngine/RocksDBEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ void RocksDBEngine::beginShutdown() {
// signal the event listener that we are going to shut down soon
if (_shaListener != nullptr) {
_shaListener->beginShutdown();
} // if
}
}

void RocksDBEngine::stop() {
Expand All @@ -924,6 +924,10 @@ void RocksDBEngine::stop() {
// in case we missed the beginShutdown somehow, call it again
replicationManager()->beginShutdown();
replicationManager()->dropAll();

if (_shaListener != nullptr) {
_shaListener->waitForShutdown();
}

if (_backgroundThread) {
// stop the press
Expand Down
0