summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-11-30 12:26:10 +0100
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-12-05 10:52:23 +0100
commitbe353baa567da5de46b257a4f73b48dc301aacf0 (patch)
treeeba44501f3e3087b04e6ecc0f5eb5fb0204f8d31
parentb5bb39846e3743741339037a72e569fac1676011 (diff)
downloadjustbuild-be353baa567da5de46b257a4f73b48dc301aacf0.tar.gz
serve target client: Ensure repository key blob is also in remote CAS
-rw-r--r--src/buildtool/build_engine/target_map/absent_target_map.cpp3
-rw-r--r--src/buildtool/serve_api/remote/serve_api.hpp5
-rw-r--r--src/buildtool/serve_api/remote/target_client.cpp13
-rw-r--r--src/buildtool/serve_api/remote/target_client.hpp4
4 files changed, 20 insertions, 5 deletions
diff --git a/src/buildtool/build_engine/target_map/absent_target_map.cpp b/src/buildtool/build_engine/target_map/absent_target_map.cpp
index 3ceaa4d8..6d41f182 100644
--- a/src/buildtool/build_engine/target_map/absent_target_map.cpp
+++ b/src/buildtool/build_engine/target_map/absent_target_map.cpp
@@ -74,7 +74,8 @@ auto BuildMaps::Target::CreateAbsentTargetMap(
Logger::Log(LogLevel::Debug,
"Querying just serve for export target {}",
key.target.ToString());
- target_cache_value = ServeApi::ServeTarget(*target_cache_key);
+ target_cache_value =
+ ServeApi::ServeTarget(*target_cache_key, *repo_key);
from_just_serve = true;
}
diff --git a/src/buildtool/serve_api/remote/serve_api.hpp b/src/buildtool/serve_api/remote/serve_api.hpp
index 16b998b4..fce7611d 100644
--- a/src/buildtool/serve_api/remote/serve_api.hpp
+++ b/src/buildtool/serve_api/remote/serve_api.hpp
@@ -69,9 +69,10 @@ class ServeApi final {
target_root_id, target_file, target);
}
- [[nodiscard]] static auto ServeTarget(const TargetCacheKey& key)
+ [[nodiscard]] static auto ServeTarget(const TargetCacheKey& key,
+ const std::string& repo_key)
-> std::optional<std::pair<TargetCacheEntry, Artifact::ObjectInfo>> {
- return Instance().tc_->ServeTarget(key);
+ return Instance().tc_->ServeTarget(key, repo_key);
}
[[nodiscard]] static auto CheckServeRemoteExecution() -> bool {
diff --git a/src/buildtool/serve_api/remote/target_client.cpp b/src/buildtool/serve_api/remote/target_client.cpp
index 8571910d..7166a604 100644
--- a/src/buildtool/serve_api/remote/target_client.cpp
+++ b/src/buildtool/serve_api/remote/target_client.cpp
@@ -25,7 +25,8 @@ TargetClient::TargetClient(std::string const& server, Port port) noexcept {
CreateChannelWithCredentials(server, port));
}
-auto TargetClient::ServeTarget(const TargetCacheKey& key)
+auto TargetClient::ServeTarget(const TargetCacheKey& key,
+ const std::string& repo_key)
-> std::optional<std::pair<TargetCacheEntry, Artifact::ObjectInfo>> {
// make sure the blob containing the key is in the remote cas
if (!local_api_->RetrieveToCas({key.Id()}, &*remote_api_)) {
@@ -34,6 +35,16 @@ auto TargetClient::ServeTarget(const TargetCacheKey& key)
key.Id().ToString());
return std::nullopt;
}
+ // make sure the repository configuration blob is in the remote cas
+ if (!local_api_->RetrieveToCas(
+ {Artifact::ObjectInfo{.digest = ArtifactDigest{repo_key, 0, false},
+ .type = ObjectType::File}},
+ &*remote_api_)) {
+ logger_.Emit(LogLevel::Error,
+ "failed to retrieve to remote cas blob {}",
+ repo_key);
+ return std::nullopt;
+ }
bazel_re::Digest key_dgst{key.Id().digest};
justbuild::just_serve::ServeTargetRequest request{};
diff --git a/src/buildtool/serve_api/remote/target_client.hpp b/src/buildtool/serve_api/remote/target_client.hpp
index 72b8d82c..9219fb3d 100644
--- a/src/buildtool/serve_api/remote/target_client.hpp
+++ b/src/buildtool/serve_api/remote/target_client.hpp
@@ -38,8 +38,10 @@ class TargetClient {
/// \brief Retrieve the pair of TargetCacheEntry and ObjectInfo associated
/// to the given key.
/// \param[in] key The TargetCacheKey of an export target
+ /// \param[in] repo_key The RepositoryKey to upload as precondition
/// \returns Pair of cache entry and its object info on success or nullopt.
- [[nodiscard]] auto ServeTarget(const TargetCacheKey& key)
+ [[nodiscard]] auto ServeTarget(const TargetCacheKey& key,
+ const std::string& repo_key)
-> std::optional<std::pair<TargetCacheEntry, Artifact::ObjectInfo>>;
/// \brief Retrieve the flexible config variables of an export target.