diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/serve_api/serve_service/target.cpp | 8 | ||||
-rw-r--r-- | src/buildtool/storage/target_cache.hpp | 49 | ||||
-rw-r--r-- | src/buildtool/storage/target_cache.tpp | 3 | ||||
-rw-r--r-- | src/buildtool/storage/uplinker.cpp | 12 | ||||
-rw-r--r-- | src/buildtool/storage/uplinker.hpp | 6 |
5 files changed, 42 insertions, 36 deletions
diff --git a/src/buildtool/serve_api/serve_service/target.cpp b/src/buildtool/serve_api/serve_service/target.cpp index 9ced4b02..019a258b 100644 --- a/src/buildtool/serve_api/serve_service/target.cpp +++ b/src/buildtool/serve_api/serve_service/target.cpp @@ -224,11 +224,9 @@ auto TargetService::ServeTarget( } // get a target cache instance with the correct computed shard - auto shard = remote_config->remote_address - ? std::make_optional(execution_backend_dgst->hash()) - : std::nullopt; - auto const& tc = local_context_.storage->TargetCache().WithShard(shard); - auto const& tc_key = + auto const tc = local_context_.storage->TargetCache().WithShard( + execution_backend_dgst->hash()); + auto const tc_key = TargetCacheKey{{*target_cache_key_digest, ObjectType::File}}; // check if target-level cache entry has already been computed diff --git a/src/buildtool/storage/target_cache.hpp b/src/buildtool/storage/target_cache.hpp index 9dc30d11..5fadabec 100644 --- a/src/buildtool/storage/target_cache.hpp +++ b/src/buildtool/storage/target_cache.hpp @@ -56,21 +56,26 @@ class TargetCache { gsl::not_null<LocalCAS<kDoGlobalUplink> const*> const& cas, GenerationConfig const& config, gsl::not_null<Uplinker<kDoGlobalUplink> const*> const& uplinker) - : cas_{*cas}, - file_store_{config.target_cache / - config.storage_config->backend_description_id}, - uplinker_{*uplinker}, - explicit_shard_{std::nullopt} {} + : TargetCache(cas, + config.target_cache, + uplinker, + config.storage_config->backend_description_id) {} /// \brief Returns a new TargetCache backed by the same CAS, but the - /// FileStorage uses the given \p shard. This is particularly useful for the - /// just-serve server implementation, since the sharding must be performed - /// according to the client's request and not following the server - /// configuration. It is caller's responsibility to check that \p shard is a - /// valid path. - [[nodiscard]] auto WithShard(const std::optional<std::string>& shard) const + /// FileStorage uses the given \p backend_description 's hash. This is + /// particularly useful for the just-serve server implementation, since the + /// sharding must be performed according to the client's request and not + /// following the server configuration. + [[nodiscard]] auto WithShard(std::string backend_description) const -> TargetCache { - return shard ? TargetCache<kDoGlobalUplink>(*this, *shard) : *this; + if (backend_description_id_ == backend_description) { + return *this; + } + + return TargetCache(&cas_, + file_store_.StorageRoot().parent_path(), + &uplinker_, + std::move(backend_description)); } TargetCache(TargetCache const&) = default; @@ -131,15 +136,17 @@ class TargetCache { /*kSetEpochTime=*/false> file_store_; Uplinker<kDoGlobalUplink> const& uplinker_; - 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}, - uplinker_{other.uplinker_}, - explicit_shard_{explicit_shard} {} + std::string const backend_description_id_; + + explicit TargetCache( + gsl::not_null<LocalCAS<kDoGlobalUplink> const*> const& cas, + std::filesystem::path const& root, + gsl::not_null<Uplinker<kDoGlobalUplink> const*> const& uplinker, + std::string backend_description_id) + : cas_{*cas}, + file_store_{root / backend_description_id}, + uplinker_{*uplinker}, + backend_description_id_{std::move(backend_description_id)} {} template <bool kIsLocalGeneration = not kDoGlobalUplink> requires(kIsLocalGeneration) diff --git a/src/buildtool/storage/target_cache.tpp b/src/buildtool/storage/target_cache.tpp index 6ce20300..f867d181 100644 --- a/src/buildtool/storage/target_cache.tpp +++ b/src/buildtool/storage/target_cache.tpp @@ -78,7 +78,8 @@ auto TargetCache<kDoGlobalUplink>::Read( if constexpr (kDoGlobalUplink) { // Uplink any existing target cache entry in storage generations - std::ignore = uplinker_.UplinkTargetCacheEntry(key, explicit_shard_); + std::ignore = + uplinker_.UplinkTargetCacheEntry(key, backend_description_id_); } auto const entry = diff --git a/src/buildtool/storage/uplinker.cpp b/src/buildtool/storage/uplinker.cpp index 2b9a60b8..f5a291ae 100644 --- a/src/buildtool/storage/uplinker.cpp +++ b/src/buildtool/storage/uplinker.cpp @@ -100,16 +100,18 @@ auto GlobalUplinker::UplinkActionCacheEntry( auto GlobalUplinker::UplinkTargetCacheEntry( TargetCacheKey const& key, - std::optional<std::string> const& shard) const noexcept -> bool { + std::string const& backend_description) const noexcept -> bool { // Try to find target-cache entry in all generations. auto const& latest = - generations_[Generation::kYoungest].TargetCache().WithShard(shard); + generations_[Generation::kYoungest].TargetCache().WithShard( + backend_description); return std::any_of( generations_.begin(), generations_.end(), - [&latest, &key, &shard](Generation const& generation) { - return generation.TargetCache().WithShard(shard).LocalUplinkEntry( - latest, key); + [&latest, &key, &backend_description](Generation const& generation) { + return generation.TargetCache() + .WithShard(backend_description) + .LocalUplinkEntry(latest, key); }); } diff --git a/src/buildtool/storage/uplinker.hpp b/src/buildtool/storage/uplinker.hpp index 945ae337..56eaea43 100644 --- a/src/buildtool/storage/uplinker.hpp +++ b/src/buildtool/storage/uplinker.hpp @@ -15,7 +15,6 @@ #ifndef INCLUDED_SRC_BUILDTOOL_STORAGE_UPLINKER_HPP #define INCLUDED_SRC_BUILDTOOL_STORAGE_UPLINKER_HPP -#include <optional> #include <string> #include <type_traits> #include <vector> @@ -74,12 +73,11 @@ class GlobalUplinker final { /// \brief Uplink entry from target cache across all generations to latest. /// Note that the entry will be uplinked including all referenced items. /// \param key Target cache key to uplink entry for. - /// \param shard Optional explicit shard, if the default is not intended. + /// \param backend_description Explicit backend description. /// \returns true if cache entry was found and successfully uplinked. [[nodiscard]] auto UplinkTargetCacheEntry( TargetCacheKey const& key, - std::optional<std::string> const& shard = std::nullopt) const noexcept - -> bool; + std::string const& backend_description) const noexcept -> bool; private: StorageConfig const& storage_config_; |