diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-11 12:19:15 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-11 14:52:07 +0200 |
commit | 09a400e7a6ae4882ef770bf7eba3887050601ee8 (patch) | |
tree | 2d54d6ff3985619d47ce8ae423853afc51f4ca3f /src/other_tools/ops_maps | |
parent | c34e0b72616c99a4704efc3950351c84487903ca (diff) | |
download | justbuild-09a400e7a6ae4882ef770bf7eba3887050601ee8.tar.gz |
Store HashInfo in just-mr's ArchiveContent as content hash
...and use it to create ArtifactDigests.
Diffstat (limited to 'src/other_tools/ops_maps')
-rw-r--r-- | src/other_tools/ops_maps/TARGETS | 2 | ||||
-rw-r--r-- | src/other_tools/ops_maps/archive_fetch_map.cpp | 31 | ||||
-rw-r--r-- | src/other_tools/ops_maps/archive_fetch_map.hpp | 6 | ||||
-rw-r--r-- | src/other_tools/ops_maps/content_cas_map.cpp | 27 | ||||
-rw-r--r-- | src/other_tools/ops_maps/content_cas_map.hpp | 7 |
5 files changed, 39 insertions, 34 deletions
diff --git a/src/other_tools/ops_maps/TARGETS b/src/other_tools/ops_maps/TARGETS index 548db656..0b7ac74f 100644 --- a/src/other_tools/ops_maps/TARGETS +++ b/src/other_tools/ops_maps/TARGETS @@ -72,6 +72,7 @@ , ["src/buildtool/serve_api/remote", "serve_api"] , ["src/buildtool/storage", "config"] , ["src/buildtool/storage", "storage"] + , ["src/buildtool/crypto", "hash_info"] ] , "stage": ["src", "other_tools", "ops_maps"] , "private-deps": @@ -93,6 +94,7 @@ , ["src/buildtool/execution_api/common", "common"] , ["src/buildtool/storage", "storage"] , ["src/other_tools/just_mr/progress_reporting", "statistics"] + , ["src/buildtool/crypto", "hash_info"] ] , "stage": ["src", "other_tools", "ops_maps"] , "private-deps": diff --git a/src/other_tools/ops_maps/archive_fetch_map.cpp b/src/other_tools/ops_maps/archive_fetch_map.cpp index 17b33092..91d71ce6 100644 --- a/src/other_tools/ops_maps/archive_fetch_map.cpp +++ b/src/other_tools/ops_maps/archive_fetch_map.cpp @@ -27,21 +27,20 @@ void ProcessContent(std::filesystem::path const& content_path, std::filesystem::path const& target_name, gsl::not_null<IExecutionApi const*> const& local_api, IExecutionApi const* remote_api, - std::string const& content, + ArtifactDigest const& content_digest, gsl::not_null<JustMRStatistics*> const& stats, ArchiveFetchMap::SetterPtr const& setter, ArchiveFetchMap::LoggerPtr const& logger) { // try to back up to remote CAS if (remote_api != nullptr) { if (not local_api->RetrieveToCas( - {Artifact::ObjectInfo{ - .digest = ArtifactDigest{content, 0, /*is_tree=*/false}, - .type = ObjectType::File}}, + {Artifact::ObjectInfo{.digest = content_digest, + .type = ObjectType::File}}, *remote_api)) { // give a warning (*logger)(fmt::format("Failed to back up content {} from local CAS " "to remote", - content), + content_digest.hash()), /*fatal=*/false); } } @@ -53,7 +52,7 @@ void ProcessContent(std::filesystem::path const& content_path, } if (not FileSystemManager::CopyFile(content_path, target_name)) { (*logger)(fmt::format("Failed to copy content {} from CAS to {}", - content, + content_digest.hash(), target_name.string()), /*fatal=*/true); return; @@ -96,30 +95,30 @@ auto CreateArchiveFetchMap(gsl::not_null<ContentCASMap*> const& content_cas_map, storage, local_api, remote_api, - content = key.content, + hash_info = key.content_hash, stats, setter, logger]([[maybe_unused]] auto const& values) { // content is in local CAS now auto const& cas = storage->CAS(); - auto content_path = - cas.BlobPath(ArtifactDigest{content, 0, /*is_tree=*/false}, - /*is_executable=*/false) - .value(); + ArtifactDigest const digest{hash_info, 0}; + auto content_path = cas.BlobPath(digest, + /*is_executable=*/false) + .value(); ProcessContent(content_path, target_name, local_api, remote_api, - content, + digest, stats, setter, logger); }, - [logger, content = key.content](auto const& msg, bool fatal) { + [logger, hash = key.content_hash.Hash()](auto const& msg, + bool fatal) { (*logger)( - fmt::format("While ensuring content {} is in CAS:\n{}", - content, - msg), + fmt::format( + "While ensuring content {} is in CAS:\n{}", hash, msg), fatal); }); }; diff --git a/src/other_tools/ops_maps/archive_fetch_map.hpp b/src/other_tools/ops_maps/archive_fetch_map.hpp index 3c4ed82c..e1c26b45 100644 --- a/src/other_tools/ops_maps/archive_fetch_map.hpp +++ b/src/other_tools/ops_maps/archive_fetch_map.hpp @@ -22,6 +22,7 @@ #include <string> #include "gsl/gsl" +#include "src/buildtool/crypto/hash_info.hpp" #include "src/buildtool/execution_api/common/execution_api.hpp" #include "src/buildtool/storage/storage.hpp" #include "src/other_tools/just_mr/progress_reporting/statistics.hpp" @@ -41,7 +42,8 @@ using ArchiveFetchMap = AsyncMapConsumer<ArchiveContent, bool>; // use explicit cast to std::function to allow template deduction when used static const std::function<std::string(ArchiveContent const&)> - kArchiveContentPrinter = - [](ArchiveContent const& x) -> std::string { return x.content; }; + kArchiveContentPrinter = [](ArchiveContent const& x) -> std::string { + return x.content_hash.Hash(); +}; #endif // INCLUDED_SRC_OTHER_TOOLS_OPS_MAPS_ARCHIVE_FETCH_MAP_HPP diff --git a/src/other_tools/ops_maps/content_cas_map.cpp b/src/other_tools/ops_maps/content_cas_map.cpp index 95518326..0e13cd8e 100644 --- a/src/other_tools/ops_maps/content_cas_map.cpp +++ b/src/other_tools/ops_maps/content_cas_map.cpp @@ -44,7 +44,7 @@ void FetchFromNetwork(ArchiveContent const& key, if (not data) { (*logger)(fmt::format("Failed to fetch a file with id {} from provided " "remotes:{}", - key.content, + key.content_hash.Hash(), data.error()), /*fatal=*/true); return; @@ -83,11 +83,11 @@ void FetchFromNetwork(ArchiveContent const& key, } // check that the data we stored actually produces the requested digest auto const& cas = storage.CAS(); - if (not cas.BlobPath(ArtifactDigest{key.content, 0, /*is_tree=*/false}, + if (not cas.BlobPath(ArtifactDigest{key.content_hash, 0}, /*is_executable=*/false)) { (*logger)( fmt::format("Content {} was not found at given fetch location {}", - key.content, + key.content_hash.Hash(), key.fetch_url), /*fatal=*/true); return; @@ -125,7 +125,7 @@ auto CreateContentCASMap( auto logger, auto /*unused*/, auto const& key) { - auto digest = ArtifactDigest(key.content, 0, false); + auto const digest = ArtifactDigest{key.content_hash, 0}; // check local CAS if (local_api->IsAvailable(digest)) { (*setter)(nullptr); @@ -175,15 +175,16 @@ auto CreateContentCASMap( } // verify if local Git knows content blob auto wrapped_logger = std::make_shared<AsyncMapConsumerLogger>( - [&logger, blob = key.content](auto const& msg, bool fatal) { + [&logger, hash = key.content_hash.Hash()](auto const& msg, + bool fatal) { (*logger)(fmt::format("While verifying presence of " "blob {}:\n{}", - blob, + hash, msg), fatal); }); - auto res = - just_git_repo->TryReadBlob(key.content, wrapped_logger); + auto res = just_git_repo->TryReadBlob(key.content_hash.Hash(), + wrapped_logger); if (not res.first) { // blob check failed return; @@ -195,7 +196,7 @@ auto CreateContentCASMap( /*is_executable=*/false)) { (*logger)(fmt::format("Failed to store content {} " "to local CAS", - key.content), + key.content_hash.Hash()), /*fatal=*/true); return; } @@ -214,8 +215,8 @@ auto CreateContentCASMap( std::make_shared<AsyncMapConsumerLogger>( [](auto /*unused*/, auto /*unused*/) {}); if (old_repo) { - auto res = - old_repo->TryReadBlob(key.content, no_logging); + auto res = old_repo->TryReadBlob( + key.content_hash.Hash(), no_logging); if (res.first and res.second) { // read blob from older generation auto const& cas = storage->CAS(); @@ -224,7 +225,7 @@ auto CreateContentCASMap( (*logger)(fmt::format( "Failed to store content {} " "to local CAS", - key.content), + key.content_hash.Hash()), /*fatal=*/true); } // content stored in CAS @@ -253,7 +254,7 @@ auto CreateContentCASMap( } // check if content is known to remote serve service if (serve != nullptr and remote_api != nullptr and - serve->ContentInRemoteCAS(key.content)) { + serve->ContentInRemoteCAS(key.content_hash.Hash())) { // try to get content from remote CAS if (remote_api->RetrieveToCas( {Artifact::ObjectInfo{.digest = digest, diff --git a/src/other_tools/ops_maps/content_cas_map.hpp b/src/other_tools/ops_maps/content_cas_map.hpp index ccfb6dad..69f10dbc 100644 --- a/src/other_tools/ops_maps/content_cas_map.hpp +++ b/src/other_tools/ops_maps/content_cas_map.hpp @@ -22,6 +22,7 @@ #include "gsl/gsl" #include "src/buildtool/common/user_structs.hpp" +#include "src/buildtool/crypto/hash_info.hpp" #include "src/buildtool/execution_api/common/execution_api.hpp" #include "src/buildtool/file_system/symlinks_map/pragma_special.hpp" #include "src/buildtool/multithreading/async_map_consumer.hpp" @@ -34,7 +35,7 @@ #include "src/utils/cpp/hash_combine.hpp" struct ArchiveContent { - std::string content{}; /* key */ + HashInfo content_hash{}; /* key */ std::optional<std::string> distfile{std::nullopt}; std::string fetch_url{}; std::vector<std::string> mirrors{}; @@ -44,7 +45,7 @@ struct ArchiveContent { std::string origin{}; [[nodiscard]] auto operator==(const ArchiveContent& other) const -> bool { - return content == other.content; + return content_hash.Hash() == other.content_hash.Hash(); } }; @@ -100,7 +101,7 @@ template <> struct hash<ArchiveContent> { [[nodiscard]] auto operator()(const ArchiveContent& ct) const noexcept -> std::size_t { - return std::hash<std::string>{}(ct.content); + return std::hash<std::string>{}(ct.content_hash.Hash()); } }; |