8000 Move async task cleanup before transaction destruction by jbajic · Pull Request #21734 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

Move async task cleanup before transaction destruction #21734

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 10 commits into from
Jun 3, 2025
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
Next Next commit
Move async task cleanup before transaction destruction
  • Loading branch information
jbajic committed Apr 28, 2025
commit 4cc6436dae3f17873639d8b8a2004cca7c6ad6ad
25 changes: 17 additions & 8 deletions arangod/Aql/ExecutionEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,7 @@ ExecutionEngine::~ExecutionEngine() {
std::this_thread::sleep_for(10ms);
}

// We need to stop prefetch tasks in topological order so
// that after stopping tasks on a certain node there is no prefetch
// tasks running on any dependent which could start another on the
// current block.
// The blocks are pushed in a reversed topological order.
for (auto it = _blocks.rbegin(); it != _blocks.rend(); ++it) {
(*it)->stopAsyncTasks();
}
stopAsyncTasks();

if (_sharedState) { // ensure no async task is working anymore
_sharedState->invalidate();
Expand Down Expand Up @@ -971,6 +964,22 @@ ExecutionEngine::rebootTrackers() {
return _rebootTrackers;
}

void ExecutionEngine::stopAsyncTasks() {
TRI_IF_FAILURE("AsyncPrefetch::blocksDestroyedOutOfOrder") {
using namespace std::chrono_literals;
std::this_thread::sleep_for(10ms);
}

// We need to stop prefetch tasks in topological order so
// that after stopping tasks on a certain node there is no prefetch
// tasks running on any dependent which could start another on the
// current block.
// The blocks are pushed in a reversed topological order.
for (auto it = _blocks.rbegin(); it != _blocks.rend(); ++it) {
(*it)->stopAsyncTasks();
}
}

std::shared_ptr<SharedQueryState> const& ExecutionEngine::sharedState() const {
return _sharedState;
}
Expand Down
2 changes: 2 additions & 0 deletions arangod/Aql/ExecutionEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ class ExecutionEngine {

std::vector<arangodb::cluster::CallbackGuard>& rebootTrackers();

void stopAsyncTasks();

#ifdef USE_ENTERPRISE
static bool parallelizeGraphNode(
aql::Query& query, ExecutionPlan& plan, aql::GraphNode* graphNode,
Expand Down
5 changes: 5 additions & 0 deletions arangod/Aql/Query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1852,6 +1852,11 @@ void Query::enterState(QueryExecutionState::ValueType state) {
/// @brief cleanup plan and engine for current query
ExecutionState Query::cleanupPlanAndEngine(bool sync) {
ensureExecutionTime();
// Before transaction is destroyed we should wait for all async tasks to
// finish so they don't use trx object
for (auto const& 4C5D snippet : _snippets) {
snippet->stopAsyncTasks();
}

{
std::unique_lock<std::mutex> guard{_resultMutex};
Expand Down
0