diff --git a/src/database/storage_gc_worker.hpp b/src/database/storage_gc_worker.hpp index a88b201f0..ab8db18f6 100644 --- a/src/database/storage_gc_worker.hpp +++ b/src/database/storage_gc_worker.hpp @@ -4,6 +4,7 @@ #include "database/storage_gc.hpp" #include "distributed/storage_gc_rpc_messages.hpp" +#include "transactions/engine_worker.hpp" #include "transactions/transaction.hpp" namespace database { @@ -19,6 +20,13 @@ class StorageGcWorker : public StorageGc { void CollectCommitLogGarbage(tx::transaction_id_t oldest_active) final { auto safe_to_delete = GetClogSafeTransaction(oldest_active); if (safe_to_delete) { + // We first need to delete transactions that we can delete to be sure that + // the locks are released as well. Otherwise some new transaction might + // try to aquire a lock which hasn't been released (if the transaction + // cache cleaner was not scheduled at this time), and take a look into the + // commit log which no longer contains that transaction id + dynamic_cast(tx_engine_) + .ClearTransactionalCache(*safe_to_delete); master_client_pool_.Call(*safe_to_delete, worker_id_); tx_engine_.GarbageCollectCommitLog(*safe_to_delete);