Remove non-forcing package updates

This was only used in tests but was otherwise not very useful as we
normally need to ensure the persistent database is updated as well.
This commit is contained in:
Martchus 2023-12-19 21:34:18 +01:00
parent f0761ed70e
commit 8deeb0a82b
6 changed files with 12 additions and 36 deletions

View File

@ -510,26 +510,7 @@ StorageID Database::updatePackage(const std::shared_ptr<Package> &package)
} }
const auto lock = std::unique_lock(m_storage->updateMutex); const auto lock = std::unique_lock(m_storage->updateMutex);
auto txn = m_storage->packages.getRWTransaction(); auto txn = m_storage->packages.getRWTransaction();
const auto res = m_storage->packageCache.store(*m_storage, txn, package, false); const auto res = m_storage->packageCache.store(*m_storage, txn, package);
if (!res.updated) {
return res.id;
}
if (res.oldEntry) {
removePackageDependencies(*m_storage, txn.getTransactionHandle(), res.id, res.oldEntry);
}
addPackageDependencies(*m_storage, txn.getTransactionHandle(), res.id, package);
txn.commit();
return res.id;
}
StorageID Database::forceUpdatePackage(const std::shared_ptr<Package> &package)
{
if (package->name.empty()) {
return 0;
}
const auto lock = std::unique_lock(m_storage->updateMutex);
auto txn = m_storage->packages.getRWTransaction();
const auto res = m_storage->packageCache.store(*m_storage, txn, package, true);
if (res.oldEntry) { if (res.oldEntry) {
removePackageDependencies(*m_storage, txn.getTransactionHandle(), res.id, res.oldEntry); removePackageDependencies(*m_storage, txn.getTransactionHandle(), res.id, res.oldEntry);
} }
@ -913,7 +894,7 @@ PackageSpec LibPkg::PackageUpdater::findPackageWithID(const std::string &package
StorageID PackageUpdater::update(const std::shared_ptr<Package> &package) StorageID PackageUpdater::update(const std::shared_ptr<Package> &package)
{ {
const auto &storage = m_database.m_storage; const auto &storage = m_database.m_storage;
const auto res = storage->packageCache.store(*m_database.m_storage, m_d->packagesTxn, package, true); const auto res = storage->packageCache.store(*m_database.m_storage, m_d->packagesTxn, package);
m_d->update(res, package); m_d->update(res, package);
return res.id; return res.id;
} }

View File

@ -187,7 +187,6 @@ struct LIBPKG_EXPORT Database : public ReflectiveRapidJSON::JsonSerializable<Dat
StorageID findBasePackageWithID(const std::string &packageName, PackageBase &basePackage); StorageID findBasePackageWithID(const std::string &packageName, PackageBase &basePackage);
void removePackage(const std::string &packageName); void removePackage(const std::string &packageName);
StorageID updatePackage(const std::shared_ptr<Package> &package); StorageID updatePackage(const std::shared_ptr<Package> &package);
StorageID forceUpdatePackage(const std::shared_ptr<Package> &package);
std::unordered_map<PackageSpec, UnresolvedDependencies> detectUnresolvedPackages(Config &config, std::unordered_map<PackageSpec, UnresolvedDependencies> detectUnresolvedPackages(Config &config,
const std::vector<std::shared_ptr<Package>> &newPackages, const DependencySet &removedPackages, const std::vector<std::shared_ptr<Package>> &newPackages, const DependencySet &removedPackages,
const std::unordered_set<std::string_view> &depsToIgnore = std::unordered_set<std::string_view>(), const std::unordered_set<std::string_view> &depsToIgnore = std::unordered_set<std::string_view>(),

View File

@ -130,8 +130,7 @@ auto StorageCache<StorageEntriesType, StorageType, SpecType>::retrieve(Storage &
} }
template <typename StorageEntriesType, typename StorageType, typename SpecType> template <typename StorageEntriesType, typename StorageType, typename SpecType>
auto StorageCache<StorageEntriesType, StorageType, SpecType>::store(Storage &storage, RWTxn &txn, const std::shared_ptr<Entry> &entry, bool force) auto StorageCache<StorageEntriesType, StorageType, SpecType>::store(Storage &storage, RWTxn &txn, const std::shared_ptr<Entry> &entry) -> StoreResult
-> StoreResult
{ {
// check for package in cache // check for package in cache
using CacheEntry = typename Entries::StorageEntry; using CacheEntry = typename Entries::StorageEntry;
@ -144,13 +143,10 @@ auto StorageCache<StorageEntriesType, StorageType, SpecType>::store(Storage &sto
auto lock = std::unique_lock(m_mutex); auto lock = std::unique_lock(m_mutex);
auto *cacheEntry = m_entries.find(ref); auto *cacheEntry = m_entries.find(ref);
if (cacheEntry) { if (cacheEntry) {
if (cacheEntry->entry == entry && !force) {
// do nothing if cached package is the same as specified one
return res;
}
// retain certain information obtained from package contents if this is actually the same package as before // retain certain information obtained from package contents if this is actually the same package as before
res.id = cacheEntry->id; res.id = cacheEntry->id;
entry->addDepsAndProvidesFromOtherPackage(*(res.oldEntry = cacheEntry->entry)); res.oldEntry = cacheEntry->entry;
entry->addDepsAndProvidesFromOtherPackage(*res.oldEntry);
} }
lock.unlock(); lock.unlock();
// check for package in storage // check for package in storage

View File

@ -151,7 +151,7 @@ template <typename StorageEntriesType, typename StorageType, typename SpecType>
SpecType retrieve(Storage &storage, StorageID storageID); SpecType retrieve(Storage &storage, StorageID storageID);
SpecType retrieve(Storage &storage, RWTxn *, const std::string &entryName); SpecType retrieve(Storage &storage, RWTxn *, const std::string &entryName);
SpecType retrieve(Storage &storage, const std::string &entryName); SpecType retrieve(Storage &storage, const std::string &entryName);
StoreResult store(Storage &storage, RWTxn &txn, const std::shared_ptr<Entry> &entry, bool force); StoreResult store(Storage &storage, RWTxn &txn, const std::shared_ptr<Entry> &entry);
bool invalidate(Storage &storage, const std::string &entryName); bool invalidate(Storage &storage, const std::string &entryName);
bool invalidateCacheOnly(Storage &storage, const std::string &entryName); bool invalidateCacheOnly(Storage &storage, const std::string &entryName);
void clear(Storage &storage); void clear(Storage &storage);

View File

@ -326,8 +326,8 @@ void DataTests::testComputingBuildOrder()
tar->version = "5.6-6"; tar->version = "5.6-6";
tar->dependencies.emplace_back("foo"); tar->dependencies.emplace_back("foo");
m_pkg2->dependencies.emplace_back("tar"); // let bar depend on tar m_pkg2->dependencies.emplace_back("tar"); // let bar depend on tar
db.forceUpdatePackage(tar); db.updatePackage(tar);
db.forceUpdatePackage(m_pkg2); db.updatePackage(m_pkg2);
// fail due to cycle // fail due to cycle
res = m_config.computeBuildOrder({ "foo", "bar", "tar" }, BuildOrderOptions::None); res = m_config.computeBuildOrder({ "foo", "bar", "tar" }, BuildOrderOptions::None);
@ -354,8 +354,8 @@ void DataTests::testComputingBuildOrder()
tar->packageInfo = std::make_optional<PackageInfo>(); tar->packageInfo = std::make_optional<PackageInfo>();
tar->dependencies.clear(); tar->dependencies.clear();
tar->dependencies.emplace_back("bar"); tar->dependencies.emplace_back("bar");
db.forceUpdatePackage(tar); db.updatePackage(tar);
db.forceUpdatePackage(m_pkg2); db.updatePackage(m_pkg2);
res = m_config.computeBuildOrder({ "foo" }, BuildOrderOptions::None); res = m_config.computeBuildOrder({ "foo" }, BuildOrderOptions::None);
CPPUNIT_ASSERT_EQUAL(true, res.success); CPPUNIT_ASSERT_EQUAL(true, res.success);
CPPUNIT_ASSERT_EQUAL(0_st, res.cycle.size()); CPPUNIT_ASSERT_EQUAL(0_st, res.cycle.size());

View File

@ -602,13 +602,13 @@ void BuildActionsTests::testConductingBuild()
CPPUNIT_ASSERT_MESSAGE("boost-libs package present", boostLibsPackage); CPPUNIT_ASSERT_MESSAGE("boost-libs package present", boostLibsPackage);
boostLibsPackage->libprovides = { "elf-x86_64::libboost_regex.so.1.72.0" }; boostLibsPackage->libprovides = { "elf-x86_64::libboost_regex.so.1.72.0" };
boostLibsPackage->libdepends = { "elf-x86_64::libstdc++.so.6" }; boostLibsPackage->libdepends = { "elf-x86_64::libstdc++.so.6" };
boostDb->forceUpdatePackage(boostLibsPackage); boostDb->updatePackage(boostLibsPackage);
auto sourceHighlightPackage = miscDb->findPackage("source-highlight"); auto sourceHighlightPackage = miscDb->findPackage("source-highlight");
CPPUNIT_ASSERT_MESSAGE("source-highlight package present", sourceHighlightPackage); CPPUNIT_ASSERT_MESSAGE("source-highlight package present", sourceHighlightPackage);
sourceHighlightPackage->libprovides = { "elf-x86_64::libsource-highlight.so.4" }; sourceHighlightPackage->libprovides = { "elf-x86_64::libsource-highlight.so.4" };
sourceHighlightPackage->libdepends sourceHighlightPackage->libdepends
= { "elf-x86_64::libboost_regex.so.1.72.0", "elf-x86_64::libsource-highlight.so.4", "elf-x86_64::libstdc++.so.6" }; = { "elf-x86_64::libboost_regex.so.1.72.0", "elf-x86_64::libsource-highlight.so.4", "elf-x86_64::libstdc++.so.6" };
miscDb->forceUpdatePackage(sourceHighlightPackage); miscDb->updatePackage(sourceHighlightPackage);
m_setup.printDatabases(); m_setup.printDatabases();
logTestSetup(); logTestSetup();