summaryrefslogtreecommitdiff
path: root/src/other_tools/root_maps
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-10-24 11:25:08 +0200
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-10-25 13:00:43 +0200
commit56b367d4104b2476d9aa2027c8a28d0dc5ba4f2d (patch)
treecabeb4db76364d6678c7d55a9f1c3d2658fe3e13 /src/other_tools/root_maps
parentb98addc8f8e3e62e1213cd967f20aa631057f84e (diff)
downloadjustbuild-56b367d4104b2476d9aa2027c8a28d0dc5ba4f2d.tar.gz
serve service: Use digest when requesting serve to set up a tree
...instead of passing just the Git hash, which imposes the remote to always be native. The serve service proto file is updated accordingly.
Diffstat (limited to 'src/other_tools/root_maps')
-rw-r--r--src/other_tools/root_maps/TARGETS1
-rw-r--r--src/other_tools/root_maps/root_utils.cpp45
2 files changed, 37 insertions, 9 deletions
diff --git a/src/other_tools/root_maps/TARGETS b/src/other_tools/root_maps/TARGETS
index 61e16cb7..921dbf80 100644
--- a/src/other_tools/root_maps/TARGETS
+++ b/src/other_tools/root_maps/TARGETS
@@ -209,6 +209,7 @@
, ["src/buildtool/common", "config"]
, ["src/buildtool/crypto", "hash_function"]
, ["src/buildtool/execution_api/serve", "mr_git_api"]
+ , ["src/buildtool/execution_api/serve", "utils"]
, ["src/buildtool/file_system", "object_type"]
]
}
diff --git a/src/other_tools/root_maps/root_utils.cpp b/src/other_tools/root_maps/root_utils.cpp
index 0e61c548..89e71653 100644
--- a/src/other_tools/root_maps/root_utils.cpp
+++ b/src/other_tools/root_maps/root_utils.cpp
@@ -21,6 +21,7 @@
#include "src/buildtool/common/repository_config.hpp"
#include "src/buildtool/crypto/hash_function.hpp"
#include "src/buildtool/execution_api/serve/mr_git_api.hpp"
+#include "src/buildtool/execution_api/serve/utils.hpp"
#include "src/buildtool/file_system/object_type.hpp"
auto CheckServeHasAbsentRoot(ServeApi const& serve,
@@ -48,6 +49,14 @@ auto EnsureAbsentRootOnServe(
IExecutionApi const* remote_api,
AsyncMapConsumerLoggerPtr const& logger,
bool no_sync_is_fatal) -> bool {
+ auto const native_digest = ArtifactDigestFactory::Create(
+ HashFunction::Type::GitSHA1, tree_id, 0, /*is_tree=*/true);
+ if (not native_digest) {
+ (*logger)(fmt::format("Failed to create digest for {}", tree_id),
+ /*fatal=*/true);
+ return false;
+ }
+ // check if upload is required
if (remote_api != nullptr) {
// upload tree to remote CAS
auto repo = RepositoryConfig{};
@@ -57,18 +66,15 @@ auto EnsureAbsentRootOnServe(
/*fatal=*/true);
return false;
}
- auto const digest = ArtifactDigestFactory::Create(
- HashFunction::Type::GitSHA1, tree_id, 0, /*is_tree=*/true);
-
auto git_api = MRGitApi{&repo,
native_storage_config,
compat_storage_config,
compat_storage,
local_api};
- if (not digest or not git_api.RetrieveToCas(
- {Artifact::ObjectInfo{.digest = *digest,
- .type = ObjectType::Tree}},
- *remote_api)) {
+ if (not git_api.RetrieveToCas(
+ {Artifact::ObjectInfo{.digest = *native_digest,
+ .type = ObjectType::Tree}},
+ *remote_api)) {
(*logger)(fmt::format("Failed to sync tree {} from repository {}",
tree_id,
repo_path.string()),
@@ -76,8 +82,29 @@ auto EnsureAbsentRootOnServe(
return false;
}
}
- // ask serve endpoint to retrieve the uploaded tree
- if (not serve.GetTreeFromRemote(tree_id)) {
+ // ask serve endpoint to retrieve the uploaded tree; this can only happen if
+ // we have access to a digest that the remote knows
+ ArtifactDigest remote_digest = *native_digest;
+ if (compat_storage_config != nullptr) {
+ // in compatible mode, get compatible digest from mapping, if exists
+ auto cached_obj = MRApiUtils::ReadRehashedDigest(*native_digest,
+ *native_storage_config,
+ *compat_storage_config,
+ /*from_git=*/true);
+ if (not cached_obj) {
+ (*logger)(cached_obj.error(), /*fatal=*/true);
+ return false;
+ }
+ if (not *cached_obj) {
+ // digest is not known; respond based on no_sync_is_fatal flag
+ (*logger)(fmt::format("No digest provided to sync root tree {}.",
+ tree_id),
+ /*fatal=*/no_sync_is_fatal);
+ return not no_sync_is_fatal;
+ }
+ remote_digest = cached_obj->value().digest;
+ }
+ if (not serve.GetTreeFromRemote(remote_digest)) {
// respond based on no_sync_is_fatal flag
(*logger)(
fmt::format("Serve endpoint failed to sync root tree {}.", tree_id),