summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-08-26 14:49:22 +0200
committerMaksim Denisov <denisov.maksim@huawei.com>2024-08-26 17:19:39 +0200
commitc7d30a299982178974b18a8088943cdd9f1c256f (patch)
tree330f0cc0c79a6ab56c64f8701fd7ed45531665bd /src
parente6a91bb733b0738cee0b3ae06ee640f70c1e787f (diff)
downloadjustbuild-c7d30a299982178974b18a8088943cdd9f1c256f.tar.gz
Store LocalAC keys as ArtifactDigests
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/storage/local_ac.hpp5
-rw-r--r--src/buildtool/storage/local_ac.tpp24
2 files changed, 19 insertions, 10 deletions
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 <string>
#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 <utility> // 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<kDoGlobalUplink>::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<ArtifactDigest>(action_id),
+ static_cast<ArtifactDigest>(*cas_key));
}
template <bool kDoGlobalUplink>
@@ -117,10 +120,10 @@ requires(kIsLocalGeneration) auto LocalAC<kDoGlobalUplink>::LocalUplinkEntry(
template <bool kDoGlobalUplink>
auto LocalAC<kDoGlobalUplink>::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 <bool kDoGlobalUplink>
@@ -141,13 +144,18 @@ auto LocalAC<kDoGlobalUplink>::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<bazel_re::Digest> action_key;
+ try {
+ nlohmann::json j = nlohmann::json::parse(*key_content);
+ action_key = ArtifactDigest{j[0].template get<std::string>(),
+ j[1].template get<std::size_t>(),
+ /*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 <bool kDoGlobalUplink>