From c7d30a299982178974b18a8088943cdd9f1c256f Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Mon, 26 Aug 2024 14:49:22 +0200 Subject: Store LocalAC keys as ArtifactDigests --- src/buildtool/storage/local_ac.hpp | 5 +++-- src/buildtool/storage/local_ac.tpp | 24 ++++++++++++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/buildtool/storage/local_ac.hpp b/src/buildtool/storage/local_ac.hpp index cb4aa171..a93130a5 100644 --- a/src/buildtool/storage/local_ac.hpp +++ b/src/buildtool/storage/local_ac.hpp @@ -20,6 +20,7 @@ #include #include "gsl/gsl" +#include "src/buildtool/common/artifact_digest.hpp" #include "src/buildtool/file_system/file_storage.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/file_system/object_type.hpp" @@ -104,8 +105,8 @@ class LocalAC { /// \param cas_key The key pointing at an ActionResult in the LocalCAS. /// \return True if an entry was successfully added to the storage. [[nodiscard]] auto WriteActionKey( - bazel_re::Digest const& action_id, - bazel_re::Digest const& cas_key) const noexcept -> bool; + ArtifactDigest const& action_id, + ArtifactDigest const& cas_key) const noexcept -> bool; /// \brief Get the key pointing at an ActionResult in the LocalCAS. /// \param action_id The id of the action that produced the result. diff --git a/src/buildtool/storage/local_ac.tpp b/src/buildtool/storage/local_ac.tpp index 835027ac..5fee10ff 100644 --- a/src/buildtool/storage/local_ac.tpp +++ b/src/buildtool/storage/local_ac.tpp @@ -19,6 +19,7 @@ #include // std::move #include "fmt/core.h" +#include "nlohmann/json.hpp" #include "src/buildtool/common/bazel_types.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/storage/local_ac.hpp" @@ -28,7 +29,9 @@ auto LocalAC::StoreResult( bazel_re::Digest const& action_id, bazel_re::ActionResult const& result) const noexcept -> bool { auto const cas_key = WriteAction(result); - return cas_key.has_value() and WriteActionKey(action_id, *cas_key); + return cas_key.has_value() and + WriteActionKey(static_cast(action_id), + static_cast(*cas_key)); } template @@ -117,10 +120,10 @@ requires(kIsLocalGeneration) auto LocalAC::LocalUplinkEntry( template auto LocalAC::WriteActionKey( - bazel_re::Digest const& action_id, - bazel_re::Digest const& cas_key) const noexcept -> bool { - return file_store_.AddFromBytes(NativeSupport::Unprefix(action_id.hash()), - cas_key.SerializeAsString()); + ArtifactDigest const& action_id, + ArtifactDigest const& cas_key) const noexcept -> bool { + nlohmann::json const content = {cas_key.hash(), cas_key.size()}; + return file_store_.AddFromBytes(action_id.hash(), content.dump()); } template @@ -141,13 +144,18 @@ auto LocalAC::ReadActionKey(bazel_re::Digest const& action_id) fmt::format("Cache miss, entry not found {}", key_path.string())}; } - bazel_re::Digest action_key{}; - if (not action_key.ParseFromString(*key_content)) { + std::optional action_key; + try { + nlohmann::json j = nlohmann::json::parse(*key_content); + action_key = ArtifactDigest{j[0].template get(), + j[1].template get(), + /*is_tree=*/false}; + } catch (...) { return unexpected{ fmt::format("Parsing cache entry failed for action {}", NativeSupport::Unprefix(action_id.hash()))}; } - return std::move(action_key); + return *std::move(action_key); } template -- cgit v1.2.3