diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-06-28 15:16:26 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-07-05 12:53:57 +0200 |
commit | 1fe09bf6b97eb03872b54d16035de7cbf604d142 (patch) | |
tree | e85db5277a88d3e5e28a1a2683db6e6cdb559650 | |
parent | ef1e4be2b749dc62c7823bc7cdc5dbc2bd66dd31 (diff) | |
download | justbuild-1fe09bf6b97eb03872b54d16035de7cbf604d142.tar.gz |
Use a separate constructor for sharded TargetCache
-rw-r--r-- | src/buildtool/storage/target_cache.hpp | 29 | ||||
-rw-r--r-- | src/buildtool/storage/target_cache.tpp | 4 |
2 files changed, 20 insertions, 13 deletions
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 <filesystem> #include <functional> +#include <memory> #include <optional> +#include <string> #include <utility> +#include <vector> #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<bool(std::vector<Artifact::ObjectInfo> const&)>; - TargetCache(std::shared_ptr<LocalCAS<kDoGlobalUplink>> cas, - std::filesystem::path const& store_path, - std::optional<std::string> const& explicit_shard = std::nullopt) + explicit TargetCache(std::shared_ptr<LocalCAS<kDoGlobalUplink>> 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<std::string>& shard) const -> TargetCache { - return shard - ? TargetCache<kDoGlobalUplink>( - cas_, file_store_.StorageRoot().parent_path(), *shard) - : *this; + return shard ? TargetCache<kDoGlobalUplink>(*this, *shard) : *this; } TargetCache(TargetCache const&) = default; @@ -137,6 +133,13 @@ class TargetCache { file_store_; std::optional<std::string> 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 <bool kIsLocalGeneration = not kDoGlobalUplink> 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 <exception> + +#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 <bool kDoGlobalUplink> |