summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-07-16 13:12:07 +0200
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-07-16 17:51:12 +0200
commit69eef57f9b286a0f61cebedcfecd8dd7aa1125ce (patch)
treede50077f023ca8f5eab21a643adc7d5794351717 /src
parentb095fb67afbd8fe72122cad22d3cbde8b2bf897c (diff)
downloadjustbuild-69eef57f9b286a0f61cebedcfecd8dd7aa1125ce.tar.gz
target service: Replace duplicated code in TC shard computation
...by using the new DescribeBackend method instead. This ensures that the TC shard computation is indeed consistent between local and serve endpoint.
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/serve_api/serve_service/TARGETS1
-rw-r--r--src/buildtool/serve_api/serve_service/target.cpp48
2 files changed, 13 insertions, 36 deletions
diff --git a/src/buildtool/serve_api/serve_service/TARGETS b/src/buildtool/serve_api/serve_service/TARGETS
index 40b11f34..6239a0e7 100644
--- a/src/buildtool/serve_api/serve_service/TARGETS
+++ b/src/buildtool/serve_api/serve_service/TARGETS
@@ -118,6 +118,7 @@
, ["src/buildtool/main", "analyse_context"]
, ["src/buildtool/common", "config"]
, ["src/buildtool/serve_api/remote", "serve_api"]
+ , ["src/buildtool/storage", "backend_description"]
]
}
, "configuration_service":
diff --git a/src/buildtool/serve_api/serve_service/target.cpp b/src/buildtool/serve_api/serve_service/target.cpp
index 6cae3d8b..1e69af63 100644
--- a/src/buildtool/serve_api/serve_service/target.cpp
+++ b/src/buildtool/serve_api/serve_service/target.cpp
@@ -40,6 +40,7 @@
#include "src/buildtool/progress_reporting/progress.hpp"
#include "src/buildtool/progress_reporting/progress_reporter.hpp"
#include "src/buildtool/serve_api/serve_service/target_utils.hpp"
+#include "src/buildtool/storage/backend_description.hpp"
#include "src/buildtool/storage/garbage_collector.hpp"
#include "src/buildtool/storage/target_cache_key.hpp"
#include "src/utils/cpp/verify_hash.hpp"
@@ -138,7 +139,7 @@ auto TargetService::ServeTarget(
// start filling in the backend description
auto const address = RemoteExecutionConfig::RemoteAddress();
- // read in the execution properties and add it to the description;
+ // read in the execution properties.
// Important: we will need to pass these platform properties also to the
// executor (via the graph_traverser) in order for the build to be properly
// dispatched to the correct remote-execution endpoint.
@@ -146,11 +147,7 @@ auto TargetService::ServeTarget(
for (auto const& p : request->execution_properties()) {
platform_properties[p.name()] = p.value();
}
- auto description = nlohmann::json{
- {"remote_address", address ? address->ToJson() : nlohmann::json{}},
- {"platform_properties", platform_properties}};
-
- // read in the dispatch list and add it to the description, if not empty
+ // Read in the dispatch list
if (auto msg = IsAHash(request->dispatch_info().hash()); msg) {
logger_->Emit(LogLevel::Error, "{}", *msg);
return ::grpc::Status{::grpc::StatusCode::INVALID_ARGUMENT, *msg};
@@ -165,40 +162,19 @@ auto TargetService::ServeTarget(
// keep dispatch list, as it needs to be passed to the executor (via the
// graph_traverser)
auto dispatch_list = *res;
- // parse dispatch list to json and add to description
- auto dispatch_json = nlohmann::json::array();
- try {
- for (auto const& [props, endpoint] : dispatch_list) {
- auto entry = nlohmann::json::array();
- entry.push_back(nlohmann::json(props));
- entry.push_back(endpoint.ToJson());
- dispatch_json.push_back(entry);
- }
- } catch (std::exception const& ex) {
- logger_->Emit(LogLevel::Info,
- "Parsing dispatch list to JSON failed with:\n{}",
- ex.what());
- }
- if (not dispatch_json.empty()) {
- description["endpoint dispatch list"] = std::move(dispatch_json);
- }
- // add backend description to CAS;
- // we match the sharding strategy from regular just builds, i.e., allowing
- // fields with invalid UTF-8 characters to be considered for the serialized
- // JSON description, but using the UTF-8 replacement character to solve any
- // decoding errors.
- std::string description_str;
- try {
- description_str = description.dump(
- 2, ' ', false, nlohmann::json::error_handler_t::replace);
- } catch (std::exception const& ex) {
- // normally shouldn't happen
- std::string err{"Failed to dump backend JSON description to string"};
+ // get backend description
+ auto description =
+ DescribeBackend(address, platform_properties, dispatch_list);
+ if (not description) {
+ auto err = fmt::format("Failed to create backend description:\n{}",
+ description.error());
logger_->Emit(LogLevel::Error, err);
return ::grpc::Status{::grpc::StatusCode::INTERNAL, err};
}
- auto execution_backend_dgst = storage_.CAS().StoreBlob(description_str);
+
+ // add backend description to CAS
+ auto execution_backend_dgst = storage_.CAS().StoreBlob(*description);
if (not execution_backend_dgst) {
std::string err{
"Failed to store execution backend description in local CAS"};