@@ -233,6 +233,25 @@ transaction_t DuckTransactionManager::GetCommitTimestamp() {
233233 return commit_ts;
234234}
235235
236+ void DuckTransactionManager::CleanupTransactions () {
237+ lock_guard<mutex> c_lock (cleanup_lock);
238+ while (true ) {
239+ unique_ptr<DuckCleanupInfo> top_cleanup_info;
240+ {
241+ lock_guard<mutex> q_lock (cleanup_queue_lock);
242+ if (cleanup_queue.empty ()) {
243+ // all transactions have been cleaned up - done
244+ return ;
245+ }
246+ top_cleanup_info = std::move (cleanup_queue.front ());
247+ cleanup_queue.pop ();
248+ }
249+ if (top_cleanup_info) {
250+ top_cleanup_info->Cleanup ();
251+ }
252+ }
253+ }
254+
236255ErrorData DuckTransactionManager::CommitTransaction (ClientContext &context, Transaction &transaction_p) {
237256 auto &transaction = transaction_p.Cast <DuckTransaction>();
238257 unique_lock<mutex> t_lock (transaction_lock);
@@ -327,20 +346,7 @@ ErrorData DuckTransactionManager::CommitTransaction(ClientContext &context, Tran
327346 // as they (1) have been removed, or (2) exited old_transactions.
328347 t_lock.unlock ();
329348
330- {
331- lock_guard<mutex> c_lock (cleanup_lock);
332- unique_ptr<DuckCleanupInfo> top_cleanup_info;
333- {
334- lock_guard<mutex> q_lock (cleanup_queue_lock);
335- if (!cleanup_queue.empty ()) {
336- top_cleanup_info = std::move (cleanup_queue.front ());
337- cleanup_queue.pop ();
338- }
339- }
340- if (top_cleanup_info) {
341- top_cleanup_info->Cleanup ();
342- }
343- }
349+ CleanupTransactions ();
344350
345351 // now perform a checkpoint if (1) we are able to checkpoint, and (2) the WAL has reached sufficient size to
346352 // checkpoint
@@ -379,20 +385,7 @@ void DuckTransactionManager::RollbackTransaction(Transaction &transaction_p) {
379385 }
380386 }
381387
382- {
383- lock_guard<mutex> c_lock (cleanup_lock);
384- unique_ptr<DuckCleanupInfo> top_cleanup_info;
385- {
386- lock_guard<mutex> q_lock (cleanup_queue_lock);
387- if (!cleanup_queue.empty ()) {
388- top_cleanup_info = std::move (cleanup_queue.front ());
389- cleanup_queue.pop ();
390- }
391- }
392- if (top_cleanup_info) {
393- top_cleanup_info->Cleanup ();
394- }
395- }
388+ CleanupTransactions ();
396389
397390 if (error.HasError ()) {
398391 throw FatalException (" Failed to rollback transaction. Cannot continue operation.\n Error: %s" , error.Message ());
0 commit comments