From 1fe09bf6b97eb03872b54d16035de7cbf604d142 Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Fri, 28 Jun 2024 15:16:26 +0200 Subject: Use a separate constructor for sharded TargetCache --- src/buildtool/storage/target_cache.hpp | 29 ++++++++++++++++------------- src/buildtool/storage/target_cache.tpp | 4 ++++ 2 files changed, 20 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/buildtool/storage/target_cache.hpp b/src/buildtool/storage/target_cache.hpp index b20b71e3..6bb5a234 100644 --- a/src/buildtool/storage/target_cache.hpp +++ b/src/buildtool/storage/target_cache.hpp @@ -17,11 +17,13 @@ #include #include +#include #include +#include #include +#include #include "gsl/gsl" -#include "nlohmann/json.hpp" #include "src/buildtool/build_engine/base_maps/entity_name_data.hpp" #include "src/buildtool/build_engine/expression/configuration.hpp" #include "src/buildtool/common/artifact.hpp" @@ -29,7 +31,6 @@ #include "src/buildtool/file_system/object_type.hpp" #include "src/buildtool/logging/logger.hpp" #include "src/buildtool/storage/config.hpp" -#include "src/buildtool/storage/garbage_collector.hpp" #include "src/buildtool/storage/local_cas.hpp" #include "src/buildtool/storage/target_cache_entry.hpp" #include "src/buildtool/storage/target_cache_key.hpp" @@ -50,14 +51,12 @@ class TargetCache { using ArtifactDownloader = std::function const&)>; - TargetCache(std::shared_ptr> cas, - std::filesystem::path const& store_path, - std::optional const& explicit_shard = std::nullopt) + explicit TargetCache(std::shared_ptr> cas, + std::filesystem::path const& store_path) : cas_{std::move(cas)}, - file_store_{explicit_shard ? store_path / *explicit_shard - : store_path / ComputeShard()}, - explicit_shard_{explicit_shard} { - if (kDoGlobalUplink && not explicit_shard) { + file_store_{store_path / ComputeShard()}, + explicit_shard_{std::nullopt} { + if constexpr (kDoGlobalUplink) { // write backend description (shard) to CAS [[maybe_unused]] auto id = cas_->StoreBlob(StorageConfig::ExecutionBackendDescription()); @@ -73,10 +72,7 @@ class TargetCache { /// valid path. [[nodiscard]] auto WithShard(const std::optional& shard) const -> TargetCache { - return shard - ? TargetCache( - cas_, file_store_.StorageRoot().parent_path(), *shard) - : *this; + return shard ? TargetCache(*this, *shard) : *this; } TargetCache(TargetCache const&) = default; @@ -137,6 +133,13 @@ class TargetCache { file_store_; std::optional explicit_shard_{std::nullopt}; + explicit TargetCache(TargetCache const& other, + std::string const& explicit_shard) + : cas_{other.cas_}, + file_store_{other.file_store_.StorageRoot().parent_path() / + explicit_shard}, + explicit_shard_{explicit_shard} {} + template requires(kIsLocalGeneration) [[nodiscard]] auto LocalUplinkEntry( LocalGenerationTC const& latest, diff --git a/src/buildtool/storage/target_cache.tpp b/src/buildtool/storage/target_cache.tpp index 10e1784f..7579d562 100644 --- a/src/buildtool/storage/target_cache.tpp +++ b/src/buildtool/storage/target_cache.tpp @@ -15,7 +15,11 @@ #ifndef INCLUDED_SRC_BUILDTOOL_STORAGE_TARGET_CACHE_TPP #define INCLUDED_SRC_BUILDTOOL_STORAGE_TARGET_CACHE_TPP +#include + +#include "nlohmann/json.hpp" #include "src/buildtool/logging/log_level.hpp" +#include "src/buildtool/storage/garbage_collector.hpp" #include "src/buildtool/storage/target_cache.hpp" template -- cgit v1.2.3