From 24c900225902337feee7a8cc4399fdffdecd945f Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Tue, 9 Jul 2024 17:44:45 +0200 Subject: TargetCache: Use StorageConfig instance for sharding Instead of computing the shard based on the RemoteExecutionConfig singleton, use the already computed hash stored in the passed StorageConfig instance, which now needs to be set up separately if bootstrapping in order to avoid unwanted includes. Storing the backend description to CAS and corresponding audit checks now take place in main. --- src/buildtool/main/main.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/buildtool/main/main.cpp') diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp index 716545a5..a82a6db8 100644 --- a/src/buildtool/main/main.cpp +++ b/src/buildtool/main/main.cpp @@ -80,7 +80,9 @@ #include "src/buildtool/progress_reporting/progress_reporter.hpp" #include "src/buildtool/serve_api/remote/config.hpp" #include "src/buildtool/serve_api/serve_service/serve_server_implementation.hpp" +#include "src/buildtool/storage/backend_description.hpp" #include "src/buildtool/storage/garbage_collector.hpp" +#include "src/utils/cpp/gsl.hpp" #endif // BOOTSTRAP_BUILD_TOOL namespace { @@ -291,6 +293,23 @@ void SetupFileChunker() { FileChunker::Initialize(); } +/// \brief Write backend description (which determines the target cache shard) +/// to CAS. +void StoreTargetCacheShard(StorageConfig const& storage_config, + Storage const& storage) noexcept { + auto backend_description = + DescribeBackend(RemoteExecutionConfig::RemoteAddress(), + RemoteExecutionConfig::PlatformProperties(), + RemoteExecutionConfig::DispatchList()); + if (not backend_description) { + Logger::Log(LogLevel::Error, backend_description.error()); + std::exit(kExitFailure); + } + [[maybe_unused]] auto id = storage.CAS().StoreBlob(*backend_description); + EnsuresAudit(id and ArtifactDigest{*id}.hash() == + storage_config.backend_description_id); +} + #endif // BOOTSTRAP_BUILD_TOOL // returns path relative to `root`. @@ -847,6 +866,7 @@ auto main(int argc, char* argv[]) -> int { return kExitFailure; } auto const storage = Storage::Create(&*storage_config); + StoreTargetCacheShard(*storage_config, storage); SetupExecutionServiceConfig(arguments.service); ApiBundle const exec_apis{&*storage_config, @@ -879,6 +899,7 @@ auto main(int argc, char* argv[]) -> int { return kExitFailure; } auto const storage = Storage::Create(&*storage_config); + StoreTargetCacheShard(*storage_config, storage); ApiBundle const serve_apis{ &*storage_config, @@ -937,6 +958,10 @@ auto main(int argc, char* argv[]) -> int { } auto const storage = Storage::Create(&*storage_config); +#ifndef BOOTSTRAP_BUILD_TOOL + StoreTargetCacheShard(*storage_config, storage); +#endif // BOOTSTRAP_BUILD_TOOL + auto jobs = arguments.build.build_jobs > 0 ? arguments.build.build_jobs : arguments.common.jobs; -- cgit v1.2.3