diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-07-16 16:33:48 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-07-19 09:50:37 +0200 |
commit | f2af767908e42013664e30ec40c431c41a6895c1 (patch) | |
tree | 25c15b9f5633985116926820e2e8b33185431b78 /src | |
parent | 953fc900629dd2b04c509b4f953e75dd351e09d9 (diff) | |
download | justbuild-f2af767908e42013664e30ec40c431c41a6895c1.tar.gz |
Pass RetryConfig instance to BazelNetwork and bazel clients
Diffstat (limited to 'src')
10 files changed, 63 insertions, 36 deletions
diff --git a/src/buildtool/execution_api/remote/TARGETS b/src/buildtool/execution_api/remote/TARGETS index deb75cfc..e8df48db 100644 --- a/src/buildtool/execution_api/remote/TARGETS +++ b/src/buildtool/execution_api/remote/TARGETS @@ -35,6 +35,7 @@ , ["src/utils/cpp", "gsl"] , ["src/buildtool/common/remote", "client_common"] , ["src/buildtool/common/remote", "port"] + , ["src/buildtool/common/remote", "retry_config"] , ["src/buildtool/file_system", "git_repo"] ] , "proto": @@ -54,7 +55,6 @@ , ["src/buildtool/crypto", "hash_function"] , ["@", "grpc", "", "grpc++"] , ["src/buildtool/common/remote", "retry"] - , ["src/buildtool/common/remote", "retry_config"] , ["src/buildtool/execution_api/common", "message_limits"] , ["src/buildtool/crypto", "hash_function"] , ["src/utils/cpp", "path"] @@ -80,6 +80,7 @@ [ "bazel_network" , ["@", "fmt", "", "fmt"] , ["src/buildtool/auth", "auth"] + , ["src/buildtool/common/remote", "retry_config"] , ["src/buildtool/compatibility", "compatibility"] , ["src/buildtool/multithreading", "task_system"] , ["src/buildtool/execution_api/common", "common"] diff --git a/src/buildtool/execution_api/remote/bazel/bazel_ac_client.cpp b/src/buildtool/execution_api/remote/bazel/bazel_ac_client.cpp index 50d236f6..c5025358 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_ac_client.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_ac_client.cpp @@ -20,9 +20,12 @@ #include "src/buildtool/common/remote/retry_config.hpp" #include "src/buildtool/logging/log_level.hpp" -BazelAcClient::BazelAcClient(std::string const& server, - Port port, - gsl::not_null<Auth const*> const& auth) noexcept { +BazelAcClient::BazelAcClient( + std::string const& server, + Port port, + gsl::not_null<Auth const*> const& auth, + gsl::not_null<RetryConfig const*> const& retry_config) noexcept + : retry_config_{*retry_config} { stub_ = bazel_re::ActionCache::NewStub( CreateChannelWithCredentials(server, port, auth)); } @@ -50,7 +53,7 @@ auto BazelAcClient::GetActionResult( grpc::ClientContext context; return stub_->GetActionResult(&context, request, &response); }, - RetryConfig::Instance(), + retry_config_, logger_); if (not ok) { if (status.error_code() == grpc::StatusCode::NOT_FOUND) { diff --git a/src/buildtool/execution_api/remote/bazel/bazel_ac_client.hpp b/src/buildtool/execution_api/remote/bazel/bazel_ac_client.hpp index 36e83649..fb05d5c3 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_ac_client.hpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_ac_client.hpp @@ -25,6 +25,7 @@ #include "src/buildtool/auth/authentication.hpp" #include "src/buildtool/common/bazel_types.hpp" #include "src/buildtool/common/remote/port.hpp" +#include "src/buildtool/common/remote/retry_config.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_common.hpp" #include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/logging/logger.hpp" @@ -33,9 +34,11 @@ /// https://github.com/bazelbuild/remote-apis/blob/e1fe21be4c9ae76269a5a63215bb3c72ed9ab3f0/build/bazel/remote/execution/v2/remote_execution.proto#L144 class BazelAcClient { public: - explicit BazelAcClient(std::string const& server, - Port port, - gsl::not_null<Auth const*> const& auth) noexcept; + explicit BazelAcClient( + std::string const& server, + Port port, + gsl::not_null<Auth const*> const& auth, + gsl::not_null<RetryConfig const*> const& retry_config) noexcept; [[nodiscard]] auto GetActionResult( std::string const& instance_name, @@ -46,6 +49,7 @@ class BazelAcClient { -> std::optional<bazel_re::ActionResult>; private: + RetryConfig const& retry_config_; std::unique_ptr<bazel_re::ActionCache::Stub> stub_; Logger logger_{"RemoteAcClient"}; }; diff --git a/src/buildtool/execution_api/remote/bazel/bazel_api.cpp b/src/buildtool/execution_api/remote/bazel/bazel_api.cpp index 8f6e07b4..fd109003 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_api.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_api.cpp @@ -27,6 +27,7 @@ #include "fmt/core.h" #include "src/buildtool/auth/authentication.hpp" #include "src/buildtool/common/bazel_types.hpp" +#include "src/buildtool/common/remote/retry_config.hpp" #include "src/buildtool/compatibility/compatibility.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_common.hpp" @@ -194,7 +195,7 @@ BazelApi::BazelApi(std::string const& instance_name, gsl::not_null<Auth const*> const& auth, ExecutionConfiguration const& exec_config) noexcept { network_ = std::make_shared<BazelNetwork>( - instance_name, host, port, auth, exec_config); + instance_name, host, port, auth, &RetryConfig::Instance(), exec_config); } // implement move constructor in cpp, where all members are complete types diff --git a/src/buildtool/execution_api/remote/bazel/bazel_cas_client.cpp b/src/buildtool/execution_api/remote/bazel/bazel_cas_client.cpp index 73f5c3ac..edfd1199 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_cas_client.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_cas_client.cpp @@ -174,10 +174,13 @@ namespace { } // namespace -BazelCasClient::BazelCasClient(std::string const& server, - Port port, - gsl::not_null<Auth const*> const& auth) noexcept - : stream_{std::make_unique<ByteStreamClient>(server, port, auth)} { +BazelCasClient::BazelCasClient( + std::string const& server, + Port port, + gsl::not_null<Auth const*> const& auth, + gsl::not_null<RetryConfig const*> const& retry_config) noexcept + : stream_{std::make_unique<ByteStreamClient>(server, port, auth)}, + retry_config_{*retry_config} { stub_ = bazel_re::ContentAddressableStorage::NewStub( CreateChannelWithCredentials(server, port, auth)); } @@ -254,7 +257,7 @@ auto BazelCasClient::BatchReadBlobs( [&request, &batch_read_blobs]() { return batch_read_blobs(request); }, - RetryConfig::Instance(), + retry_config_, logger_); })) { logger_.Emit(LogLevel::Error, "Failed to BatchReadBlobs."); @@ -366,7 +369,7 @@ auto BazelCasClient::SplitBlob(std::string const& instance_name, grpc::ClientContext context; return stub_->SplitBlob(&context, request, &response); }, - RetryConfig::Instance(), + retry_config_, logger_); if (not ok) { LogStatus(&logger_, LogLevel::Error, status, "SplitBlob"); @@ -395,7 +398,7 @@ auto BazelCasClient::SpliceBlob( grpc::ClientContext context; return stub_->SpliceBlob(&context, request, &response); }, - RetryConfig::Instance(), + retry_config_, logger_); if (not ok) { LogStatus(&logger_, LogLevel::Error, status, "SpliceBlob"); @@ -446,7 +449,7 @@ auto BazelCasClient::FindMissingBlobs(std::string const& instance_name, return stub_->FindMissingBlobs( &context, request, &response); }, - RetryConfig::Instance(), + retry_config_, logger_); if (ok) { auto batch = @@ -537,7 +540,7 @@ auto BazelCasClient::BatchUpdateBlobs( [&request, &batch_update_blobs]() { return batch_update_blobs(request); }, - RetryConfig::Instance(), + retry_config_, logger_); })) { logger_.Emit(LogLevel::Error, "Failed to BatchUpdateBlobs."); diff --git a/src/buildtool/execution_api/remote/bazel/bazel_cas_client.hpp b/src/buildtool/execution_api/remote/bazel/bazel_cas_client.hpp index 90d9eb75..225ae05d 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_cas_client.hpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_cas_client.hpp @@ -28,6 +28,7 @@ #include "src/buildtool/auth/authentication.hpp" #include "src/buildtool/common/bazel_types.hpp" #include "src/buildtool/common/remote/port.hpp" +#include "src/buildtool/common/remote/retry_config.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_common.hpp" #include "src/buildtool/execution_api/remote/bazel/bytestream_client.hpp" @@ -38,9 +39,11 @@ /// https://github.com/bazelbuild/remote-apis/blob/e1fe21be4c9ae76269a5a63215bb3c72ed9ab3f0/build/bazel/remote/execution/v2/remote_execution.proto#L317 class BazelCasClient { public: - explicit BazelCasClient(std::string const& server, - Port port, - gsl::not_null<Auth const*> const& auth) noexcept; + explicit BazelCasClient( + std::string const& server, + Port port, + gsl::not_null<Auth const*> const& auth, + gsl::not_null<RetryConfig const*> const& retry_config) noexcept; /// \brief Find missing blobs /// \param[in] instance_name Name of the CAS instance @@ -141,6 +144,7 @@ class BazelCasClient { private: std::unique_ptr<ByteStreamClient> stream_{}; + RetryConfig const& retry_config_; std::unique_ptr<bazel_re::ContentAddressableStorage::Stub> stub_; Logger logger_{"RemoteCasClient"}; diff --git a/src/buildtool/execution_api/remote/bazel/bazel_execution_client.cpp b/src/buildtool/execution_api/remote/bazel/bazel_execution_client.cpp index a6ab3087..7cf9e011 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_execution_client.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_execution_client.cpp @@ -19,7 +19,6 @@ #include "grpcpp/grpcpp.h" #include "src/buildtool/common/remote/client_common.hpp" #include "src/buildtool/common/remote/retry.hpp" -#include "src/buildtool/common/remote/retry_config.hpp" #include "src/buildtool/logging/log_level.hpp" namespace bazel_re = build::bazel::remote::execution::v2; @@ -59,7 +58,9 @@ auto DebugString(grpc::Status const& status) -> std::string { BazelExecutionClient::BazelExecutionClient( std::string const& server, Port port, - gsl::not_null<Auth const*> const& auth) noexcept { + gsl::not_null<Auth const*> const& auth, + gsl::not_null<RetryConfig const*> const& retry_config) noexcept + : retry_config_{*retry_config} { stub_ = bazel_re::Execution::NewStub( CreateChannelWithCredentials(server, port, auth)); } @@ -104,7 +105,7 @@ auto BazelExecutionClient::Execute(std::string const& instance_name, response.state != ExecutionResponse::State::Retry, .error_msg = contents.error_msg}; }; - if (not WithRetry(execute, RetryConfig::Instance(), logger_)) { + if (not WithRetry(execute, retry_config_, logger_)) { logger_.Emit(LogLevel::Error, "Failed to execute action {}.", action_digest.ShortDebugString()); @@ -140,7 +141,7 @@ auto BazelExecutionClient::WaitExecution(std::string const& execution_handle) response.state != ExecutionResponse::State::Retry, .error_msg = contents.error_msg}; }; - if (not WithRetry(wait_execution, RetryConfig::Instance(), logger_)) { + if (not WithRetry(wait_execution, retry_config_, logger_)) { logger_.Emit( LogLevel::Error, "Failed to Execute action {}.", request.name()); } diff --git a/src/buildtool/execution_api/remote/bazel/bazel_execution_client.hpp b/src/buildtool/execution_api/remote/bazel/bazel_execution_client.hpp index aa505121..b78ac36c 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_execution_client.hpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_execution_client.hpp @@ -26,6 +26,7 @@ #include "src/buildtool/auth/authentication.hpp" #include "src/buildtool/common/bazel_types.hpp" #include "src/buildtool/common/remote/port.hpp" +#include "src/buildtool/common/remote/retry_config.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_common.hpp" #include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/logging/logger.hpp" @@ -59,7 +60,8 @@ class BazelExecutionClient { explicit BazelExecutionClient( std::string const& server, Port port, - gsl::not_null<Auth const*> const& auth) noexcept; + gsl::not_null<Auth const*> const& auth, + gsl::not_null<RetryConfig const*> const& retry_config) noexcept; [[nodiscard]] auto Execute(std::string const& instance_name, bazel_re::Digest const& action_digest, @@ -70,6 +72,7 @@ class BazelExecutionClient { -> ExecutionResponse; private: + RetryConfig const& retry_config_; std::unique_ptr<bazel_re::Execution::Stub> stub_; Logger logger_{"RemoteExecutionClient"}; struct RetryReadOperation { diff --git a/src/buildtool/execution_api/remote/bazel/bazel_network.cpp b/src/buildtool/execution_api/remote/bazel/bazel_network.cpp index 34ae6af4..b5fafd5b 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_network.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_network.cpp @@ -21,16 +21,21 @@ #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/logging/logger.hpp" -BazelNetwork::BazelNetwork(std::string instance_name, - std::string const& host, - Port port, - gsl::not_null<Auth const*> const& auth, - ExecutionConfiguration const& exec_config) noexcept +BazelNetwork::BazelNetwork( + std::string instance_name, + std::string const& host, + Port port, + gsl::not_null<Auth const*> const& auth, + gsl::not_null<RetryConfig const*> const& retry_config, + ExecutionConfiguration const& exec_config) noexcept : instance_name_{std::move(instance_name)}, - exec_config_{exec_config}, - cas_{std::make_unique<BazelCasClient>(host, port, auth)}, - ac_{std::make_unique<BazelAcClient>(host, port, auth)}, - exec_{std::make_unique<BazelExecutionClient>(host, port, auth)} {} + cas_{std::make_unique<BazelCasClient>(host, port, auth, retry_config)}, + ac_{std::make_unique<BazelAcClient>(host, port, auth, retry_config)}, + exec_{std::make_unique<BazelExecutionClient>(host, + port, + auth, + retry_config)}, + exec_config_{exec_config} {} auto BazelNetwork::IsAvailable(bazel_re::Digest const& digest) const noexcept -> bool { diff --git a/src/buildtool/execution_api/remote/bazel/bazel_network.hpp b/src/buildtool/execution_api/remote/bazel/bazel_network.hpp index ca0b0e2a..33fbf713 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_network.hpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_network.hpp @@ -26,6 +26,7 @@ #include "src/buildtool/auth/authentication.hpp" #include "src/buildtool/common/bazel_types.hpp" #include "src/buildtool/common/remote/port.hpp" +#include "src/buildtool/common/remote/retry_config.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_msg_factory.hpp" #include "src/buildtool/execution_api/common/execution_api.hpp" @@ -41,6 +42,7 @@ class BazelNetwork { std::string const& host, Port port, gsl::not_null<Auth const*> const& auth, + gsl::not_null<RetryConfig const*> const& retry_config, ExecutionConfiguration const& exec_config) noexcept; /// \brief Check if digest exists in CAS @@ -85,10 +87,10 @@ class BazelNetwork { private: std::string const instance_name_{}; - ExecutionConfiguration exec_config_{}; std::unique_ptr<BazelCasClient> cas_{}; std::unique_ptr<BazelAcClient> ac_{}; std::unique_ptr<BazelExecutionClient> exec_{}; + ExecutionConfiguration exec_config_{}; template <class T_Iter> [[nodiscard]] auto DoUploadBlobs(T_Iter const& first, |