From 84ef92aaa214383e6e763e87f0c210d03d05331d Mon Sep 17 00:00:00 2001 From: Martchus Date: Tue, 1 Nov 2022 15:11:49 +0100 Subject: [PATCH] Use one transaction when updating packages via `PackageUpdater` This should likely be done in the other updating functions of the `Database` class as well to avoid indexes and actual data appearing inconsistent during the write operations. --- libpkg/data/database.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/libpkg/data/database.cpp b/libpkg/data/database.cpp index 218b6ab..fff1563 100644 --- a/libpkg/data/database.cpp +++ b/libpkg/data/database.cpp @@ -906,6 +906,7 @@ void PackageUpdater::commit() { const auto &storage = m_database.m_storage; auto &pkgTxn = m_d->packagesTxn; + auto txnHandle = pkgTxn.getTransactionHandle(); if (m_d->clear) { const auto &toPreserve = m_d->handledIds; for (auto i = pkgTxn.begin(); i != pkgTxn.end(); ++i) { @@ -914,47 +915,43 @@ void PackageUpdater::commit() } } } - pkgTxn.commit(); { - auto txn = storage->providedDeps.getRWTransaction(); + auto txn = storage->providedDeps.getRWTransaction(txnHandle); if (m_d->clear) { txn.clear(); } for (auto &[dependencyName, affected] : m_d->affectedProvidedDeps) { m_d->submit(dependencyName, affected, txn); } - txn.commit(); } { - auto txn = storage->requiredDeps.getRWTransaction(); + auto txn = storage->requiredDeps.getRWTransaction(txnHandle); if (m_d->clear) { txn.clear(); } for (auto &[dependencyName, affected] : m_d->affectedRequiredDeps) { m_d->submit(dependencyName, affected, txn); } - txn.commit(); } { - auto txn = storage->providedLibs.getRWTransaction(); + auto txn = storage->providedLibs.getRWTransaction(txnHandle); if (m_d->clear) { txn.clear(); } for (auto &[libraryName, affected] : m_d->affectedProvidedLibs) { m_d->submit(libraryName, affected, txn); } - txn.commit(); } { - auto txn = storage->requiredLibs.getRWTransaction(); + auto txn = storage->requiredLibs.getRWTransaction(txnHandle); if (m_d->clear) { txn.clear(); } for (auto &[libraryName, affected] : m_d->affectedRequiredLibs) { m_d->submit(libraryName, affected, txn); } - txn.commit(); } + pkgTxn.commit(); m_d->lock.unlock(); }