summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-12-20 16:34:04 +0100
committerMaksim Denisov <denisov.maksim@huawei.com>2025-01-07 14:18:09 +0100
commit71ffe14b0083c9c4975f66db4127de9ee5b9a84d (patch)
tree70b2477cfa47fc5cd18da047f6a01323cd77c0da /src
parenta6d84f97fceaf2ef6ce2e3c86f25a7812e2f4f84 (diff)
downloadjustbuild-71ffe14b0083c9c4975f66db4127de9ee5b9a84d.tar.gz
Add backend description to CAS in a ctor of TargetCache
...instead of adding it preliminarily.
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/main/main.cpp24
-rw-r--r--src/buildtool/serve_api/serve_service/target.cpp10
-rw-r--r--src/buildtool/storage/target_cache.hpp31
-rw-r--r--src/buildtool/storage/target_cache.tpp1
4 files changed, 30 insertions, 36 deletions
diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp
index 544027ca..d125041f 100644
--- a/src/buildtool/main/main.cpp
+++ b/src/buildtool/main/main.cpp
@@ -26,7 +26,6 @@
#include <optional>
#include <set>
#include <string>
-#include <tuple>
#include <utility>
#include <variant>
#include <vector>
@@ -248,23 +247,6 @@ void SetupFileChunker() {
FileChunker::Initialize();
}
-/// \brief Write backend description (which determines the target cache shard)
-/// to CAS.
-void StoreTargetCacheShard(
- Storage const& storage,
- RemoteExecutionConfig const& remote_exec_config) noexcept {
- auto backend_description =
- BackendDescription::Describe(remote_exec_config.remote_address,
- remote_exec_config.platform_properties,
- remote_exec_config.dispatch);
- if (not backend_description) {
- Logger::Log(LogLevel::Error, backend_description.error());
- std::exit(kExitFailure);
- }
- std::ignore =
- storage.CAS().StoreBlob(backend_description->GetDescription());
-}
-
#endif // BOOTSTRAP_BUILD_TOOL
// returns path relative to `root`.
@@ -820,7 +802,6 @@ auto main(int argc, char* argv[]) -> int {
return kExitFailure;
}
auto const storage = Storage::Create(&*storage_config);
- StoreTargetCacheShard(storage, remote_exec_config);
// pack the local context instances to be passed as needed
LocalContext const local_context{
@@ -886,7 +867,6 @@ auto main(int argc, char* argv[]) -> int {
return kExitFailure;
}
auto const storage = Storage::Create(&*storage_config);
- StoreTargetCacheShard(storage, *remote_exec_config);
// pack the local context instances to be passed as needed
LocalContext const local_context{
@@ -967,10 +947,6 @@ auto main(int argc, char* argv[]) -> int {
}
auto const storage = Storage::Create(&*storage_config);
-#ifndef BOOTSTRAP_BUILD_TOOL
- StoreTargetCacheShard(storage, *remote_exec_config);
-#endif // BOOTSTRAP_BUILD_TOOL
-
auto jobs = arguments.build.build_jobs > 0 ? arguments.build.build_jobs
: arguments.common.jobs;
diff --git a/src/buildtool/serve_api/serve_service/target.cpp b/src/buildtool/serve_api/serve_service/target.cpp
index 6b46dbea..1154bc9c 100644
--- a/src/buildtool/serve_api/serve_service/target.cpp
+++ b/src/buildtool/serve_api/serve_service/target.cpp
@@ -213,16 +213,6 @@ auto TargetService::ServeTarget(
return ::grpc::Status{::grpc::StatusCode::INTERNAL, err};
}
- // add backend description to CAS
- auto execution_backend_dgst =
- local_context_.storage->CAS().StoreBlob(description->GetDescription());
- if (not execution_backend_dgst) {
- std::string err{
- "Failed to store execution backend description in local CAS"};
- logger_->Emit(LogLevel::Error, err);
- return ::grpc::Status{::grpc::StatusCode::INTERNAL, err};
- }
-
// get a target cache instance with the correct computed shard
auto const tc =
local_context_.storage->TargetCache().WithShard(*description);
diff --git a/src/buildtool/storage/target_cache.hpp b/src/buildtool/storage/target_cache.hpp
index d674a9ed..bd9edb9c 100644
--- a/src/buildtool/storage/target_cache.hpp
+++ b/src/buildtool/storage/target_cache.hpp
@@ -30,6 +30,7 @@
#include "src/buildtool/common/artifact_digest.hpp"
#include "src/buildtool/file_system/file_storage.hpp"
#include "src/buildtool/file_system/object_type.hpp"
+#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/logging/logger.hpp"
#include "src/buildtool/storage/backend_description.hpp"
#include "src/buildtool/storage/config.hpp"
@@ -149,7 +150,35 @@ class TargetCache {
root /
backend_description.HashContent(cas->GetHashFunction()).hash()},
uplinker_{*uplinker},
- backend_description_{std::move(backend_description)} {}
+ backend_description_{std::move(backend_description)} {
+ if constexpr (kDoGlobalUplink) {
+ // Write backend description (which determines the target cache
+ // shard) to CAS. It needs to be added for informational purposes
+ // only, so it is not an error if insertion fails or returns an
+ // unexpected result.
+ auto const id = cas_.StoreBlob(
+ backend_description_.GetDescription(), /*is_executable=*/false);
+
+ auto const expected_hash =
+ file_store_.StorageRoot().filename().string();
+ if (not id) {
+ logger_->Emit(LogLevel::Debug,
+ "TargetCache: Failed to add backend description "
+ "{} to the storage:\n{}",
+ expected_hash,
+ backend_description_.GetDescription());
+ }
+ else if (id->hash() != expected_hash) {
+ logger_->Emit(LogLevel::Debug,
+ "TargetCache: backend description was added to "
+ "the storage with an unexpected hash. Expected "
+ "{}, added with {}. Content:\n{}",
+ expected_hash,
+ id->hash(),
+ backend_description_.GetDescription());
+ }
+ }
+ }
template <bool kIsLocalGeneration = not kDoGlobalUplink>
requires(kIsLocalGeneration)
diff --git a/src/buildtool/storage/target_cache.tpp b/src/buildtool/storage/target_cache.tpp
index 5a6acb88..973373b3 100644
--- a/src/buildtool/storage/target_cache.tpp
+++ b/src/buildtool/storage/target_cache.tpp
@@ -22,7 +22,6 @@
#include "nlohmann/json.hpp"
#include "src/buildtool/crypto/hash_function.hpp"
-#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/storage/target_cache.hpp"
template <bool kDoGlobalUplink>