diff options
-rw-r--r-- | src/buildtool/storage/config.hpp | 14 | ||||
-rw-r--r-- | src/buildtool/storage/garbage_collector.cpp | 39 | ||||
-rw-r--r-- | src/buildtool/storage/large_object_cas.tpp | 9 | ||||
-rw-r--r-- | src/buildtool/storage/local_cas.hpp | 14 | ||||
-rw-r--r-- | src/buildtool/storage/local_cas.tpp | 6 |
5 files changed, 37 insertions, 45 deletions
diff --git a/src/buildtool/storage/config.hpp b/src/buildtool/storage/config.hpp index da0e72d4..598d9350 100644 --- a/src/buildtool/storage/config.hpp +++ b/src/buildtool/storage/config.hpp @@ -132,19 +132,17 @@ struct StorageConfig final { [[nodiscard]] auto CreateGenerationConfig( std::size_t generation) const noexcept -> GenerationConfig { - bool const compatible = ProtocolTraits::Instance().IsCompatible(); + bool const native = ProtocolTraits::IsNative(hash_function.GetType()); auto const cache_root = GenerationCacheRoot(generation); - auto const cache_dir = - UpdatePathForCompatibility(cache_root, compatible); + auto const cache_dir = UpdatePathForCompatibility(cache_root, native); return GenerationConfig{ .storage_config = this, .cas_f = cache_dir / "casf", .cas_x = cache_dir / "casx", - .cas_t = cache_dir / (compatible ? "casf" : "cast"), + .cas_t = cache_dir / (native ? "cast" : "casf"), .cas_large_f = cache_dir / "cas-large-f", - .cas_large_t = - cache_dir / (compatible ? "cas-large-f" : "cas-large-t"), + .cas_large_t = cache_dir / (native ? "cas-large-t" : "cas-large-f"), .action_cache = cache_dir / "ac", .target_cache = cache_dir / "tc"}; }; @@ -153,8 +151,8 @@ struct StorageConfig final { // different folder for different caching protocol [[nodiscard]] static auto UpdatePathForCompatibility( std::filesystem::path const& dir, - bool is_compatible) -> std::filesystem::path { - return dir / (is_compatible ? "compatible-sha256" : "git-sha1"); + bool is_native) -> std::filesystem::path { + return dir / (is_native ? "git-sha1" : "compatible-sha256"); }; [[nodiscard]] auto DefaultBackendDescriptionId() noexcept -> std::string { 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 diff --git a/src/buildtool/storage/large_object_cas.tpp b/src/buildtool/storage/large_object_cas.tpp index b790140a..e77f6355 100644 --- a/src/buildtool/storage/large_object_cas.tpp +++ b/src/buildtool/storage/large_object_cas.tpp @@ -47,10 +47,11 @@ auto LargeObjectCAS<kDoGlobalUplink, kType>::GetEntryPath( if constexpr (kDoGlobalUplink) { // To promote parts of the tree properly, regular uplinking logic for // trees is used: - bool uplinked = IsTreeObject(kType) and - not ProtocolTraits::Instance().IsCompatible() - ? uplinker_.UplinkTree(digest) - : uplinker_.UplinkLargeBlob(digest); + auto const hash_type = storage_config_.hash_function.GetType(); + bool const uplinked = + IsTreeObject(kType) and not ProtocolTraits::IsTreeAllowed(hash_type) + ? uplinker_.UplinkTree(digest) + : uplinker_.UplinkLargeBlob(digest); if (uplinked and FileSystemManager::IsFile(file_path)) { return file_path; } diff --git a/src/buildtool/storage/local_cas.hpp b/src/buildtool/storage/local_cas.hpp index e6dc9ee4..ee5a6ea2 100644 --- a/src/buildtool/storage/local_cas.hpp +++ b/src/buildtool/storage/local_cas.hpp @@ -54,13 +54,13 @@ class LocalCAS { gsl::not_null<Uplinker<kDoGlobalUplink> const*> const& uplinker) : cas_file_{config.storage_config->hash_function, config.cas_f, - MakeUplinker<ObjectType::File>(uplinker)}, + MakeUplinker<ObjectType::File>(config, uplinker)}, cas_exec_{config.storage_config->hash_function, config.cas_x, - MakeUplinker<ObjectType::Executable>(uplinker)}, + MakeUplinker<ObjectType::Executable>(config, uplinker)}, cas_tree_{config.storage_config->hash_function, config.cas_t, - MakeUplinker<ObjectType::Tree>(uplinker)}, + MakeUplinker<ObjectType::Tree>(config, uplinker)}, cas_file_large_{this, config, uplinker}, cas_tree_large_{this, config, uplinker}, hash_function_{config.storage_config->hash_function} {} @@ -281,13 +281,17 @@ class LocalCAS { /// \brief Provides uplink via "exists callback" for physical object CAS. template <ObjectType kType> [[nodiscard]] static auto MakeUplinker( + GenerationConfig const& config, gsl::not_null<Uplinker<kDoGlobalUplink> const*> const& uplinker) { if constexpr (kDoGlobalUplink) { - return [uplinker](auto const& digest, auto const& /*path*/) { + bool const native = ProtocolTraits::IsNative( + config.storage_config->hash_function.GetType()); + return [native, uplinker](auto const& digest, + auto const& /*path*/) { if constexpr (IsTreeObject(kType)) { // in non-compatible mode, do explicit deep tree uplink // in compatible mode, treat all trees as blobs - if (not ProtocolTraits::Instance().IsCompatible()) { + if (native) { return uplinker->UplinkTree(digest); } } diff --git a/src/buildtool/storage/local_cas.tpp b/src/buildtool/storage/local_cas.tpp index 39433b81..7db6be3d 100644 --- a/src/buildtool/storage/local_cas.tpp +++ b/src/buildtool/storage/local_cas.tpp @@ -83,7 +83,7 @@ auto LocalCAS<kDoGlobalUplink>::LocalUplinkTree( LocalGenerationCAS const& latest, ArtifactDigest const& digest, bool splice_result) const noexcept -> bool { - if (ProtocolTraits::Instance().IsCompatible()) { + if (not ProtocolTraits::IsNative(hash_function_.GetType())) { std::unordered_set<ArtifactDigest> seen{}; return LocalUplinkBazelDirectory(latest, digest, &seen, splice_result); } @@ -303,7 +303,7 @@ auto LocalCAS<kDoGlobalUplink>::CheckTreeInvariant( ArtifactDigest const& tree_digest, std::string const& tree_data) const noexcept -> std::optional<LargeObjectError> { - if (ProtocolTraits::Instance().IsCompatible()) { + if (not ProtocolTraits::IsNative(hash_function_.GetType())) { return std::nullopt; } @@ -399,7 +399,7 @@ auto LocalCAS<kDoGlobalUplink>::Splice(ArtifactDigest const& digest, // Check tree invariants: if constexpr (kIsTree) { - if (not ProtocolTraits::Instance().IsCompatible()) { + if (ProtocolTraits::IsNative(hash_function_.GetType())) { // Read tree entries: auto const tree_data = FileSystemManager::ReadFile(file_path); if (not tree_data) { |