diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-11 16:35:59 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-13 14:41:00 +0200 |
commit | 514b0f1b7a731e90a1be46f14fa12130e31246dc (patch) | |
tree | a074f3b2084934e959e13dfd4b3cc67e9da1c791 /src/buildtool/storage/garbage_collector.cpp | |
parent | 0b3c77edde2b3497e3d943d1433d704453eabd19 (diff) | |
download | justbuild-514b0f1b7a731e90a1be46f14fa12130e31246dc.tar.gz |
Check compatibility in Storage based on the hash type
Diffstat (limited to 'src/buildtool/storage/garbage_collector.cpp')
-rw-r--r-- | src/buildtool/storage/garbage_collector.cpp | 39 |
1 files changed, 14 insertions, 25 deletions
diff --git a/src/buildtool/storage/garbage_collector.cpp b/src/buildtool/storage/garbage_collector.cpp index 97a0f96c..817e5240 100644 --- a/src/buildtool/storage/garbage_collector.cpp +++ b/src/buildtool/storage/garbage_collector.cpp @@ -20,9 +20,7 @@ #include <filesystem> #include <vector> -#include "gsl/gsl" #include "src/buildtool/common/artifact.hpp" -#include "src/buildtool/common/protocol_traits.hpp" #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/common/message_limits.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" @@ -214,22 +212,6 @@ auto GarbageCollector::TriggerGarbageCollection( auto GarbageCollector::Compactify(StorageConfig const& storage_config, size_t threshold) noexcept -> bool { - // Return to the initial compatibility mode once done: - auto const guard = - gsl::finally([mode = ProtocolTraits::Instance().IsCompatible()] { - ProtocolTraits::Instance().SetCompatible(mode); - }); - - auto compactify = [threshold](StorageConfig const& config) -> bool { - ProtocolTraits::Instance().SetCompatible( - config.hash_function.GetType() == HashFunction::Type::PlainSHA256); - auto const storage = ::Generation::Create(&config); - - return Compactifier::RemoveInvalid(storage.CAS()) and - Compactifier::RemoveSpliced(storage.CAS()) and - Compactifier::SplitLarge(storage.CAS(), threshold); - }; - // Compactification must be done for both native and compatible storages. static constexpr std::array kHashes = {HashFunction::Type::GitSHA1, HashFunction::Type::PlainSHA256}; @@ -237,13 +219,20 @@ auto GarbageCollector::Compactify(StorageConfig const& storage_config, .SetBuildRoot(storage_config.build_root) .SetNumGenerations(storage_config.num_generations); - return std::all_of(kHashes.begin(), - kHashes.end(), - [&builder, &compactify](HashFunction::Type hash_type) { - auto const config = - builder.SetHashType(hash_type).Build(); - return config.has_value() and compactify(*config); - }); + return std::all_of( + kHashes.begin(), + kHashes.end(), + [threshold, &builder](HashFunction::Type hash_type) { + auto const config = builder.SetHashType(hash_type).Build(); + if (not config) { + return false; + } + + auto const storage = ::Generation::Create(&*config); + return Compactifier::RemoveInvalid(storage.CAS()) and + Compactifier::RemoveSpliced(storage.CAS()) and + Compactifier::SplitLarge(storage.CAS(), threshold); + }); } #endif // BOOTSTRAP_BUILD_TOOL |