diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/common/cli.hpp | 28 | ||||
-rw-r--r-- | src/buildtool/main/TARGETS | 1 | ||||
-rw-r--r-- | src/buildtool/main/cli.cpp | 3 | ||||
-rw-r--r-- | src/buildtool/main/cli.hpp | 1 | ||||
-rw-r--r-- | src/buildtool/main/main.cpp | 25 |
5 files changed, 58 insertions, 0 deletions
diff --git a/src/buildtool/common/cli.hpp b/src/buildtool/common/cli.hpp index e6189880..3409eae8 100644 --- a/src/buildtool/common/cli.hpp +++ b/src/buildtool/common/cli.hpp @@ -86,6 +86,13 @@ struct DiagnosticArguments { std::optional<std::string> dump_nodes{std::nullopt}; }; +/// \brief Arguments required for tuning the retry strategy. +struct RetryArguments { + std::optional<unsigned int> max_attempts{}; + std::optional<unsigned int> initial_backoff_seconds{}; + std::optional<unsigned int> max_backoff_seconds{}; +}; + /// \brief Arguments required for specifying build endpoint. struct EndpointArguments { std::optional<std::filesystem::path> local_root{}; @@ -688,4 +695,25 @@ static inline auto SetupServeArguments( ->required(); } +static inline void SetupRetryArguments( + gsl::not_null<CLI::App*> const& app, + gsl::not_null<RetryArguments*> const& args) { + app->add_option( + "--max-attempts", + args->max_attempts, + "Total number of attempts in case of a remote resource becomes " + "unavailable. Must be greater than 0. (Default: 1)"); + app->add_option( + "--initial-backoff-seconds", + args->initial_backoff_seconds, + "Initial amount of time, in seconds, to wait before retrying a rpc " + "call. The waiting time is doubled at each attempt. Must be greater " + "than 0. (Default: 1)"); + app->add_option("--max-backoff-seconds", + args->max_backoff_seconds, + "The backoff time cannot be bigger than this parameter. " + "Note that some jitter is still added to avoid to overload " + "the resources that survived the outage. (Default: 60)"); +} + #endif // INCLUDED_SRC_BUILDTOOL_COMMON_CLI_HPP diff --git a/src/buildtool/main/TARGETS b/src/buildtool/main/TARGETS index 7e9278fc..21ed04aa 100644 --- a/src/buildtool/main/TARGETS +++ b/src/buildtool/main/TARGETS @@ -25,6 +25,7 @@ , ["src/buildtool/file_system", "file_root"] , ["src/buildtool/serve_api/remote", "config"] , ["src/buildtool/serve_api/serve_service", "serve_server_implementation"] + , ["src/buildtool/common/remote", "retry_parameters"] , "common" , "cli" , "version" diff --git a/src/buildtool/main/cli.cpp b/src/buildtool/main/cli.cpp index e8bc0ffd..602f7ff5 100644 --- a/src/buildtool/main/cli.cpp +++ b/src/buildtool/main/cli.cpp @@ -42,6 +42,7 @@ auto SetupAnalyseCommandArguments( SetupServeEndpointArguments(app, &clargs->serve); SetupDiagnosticArguments(app, &clargs->diagnose); SetupCompatibilityArguments(app); + SetupRetryArguments(app, &clargs->retry); } /// \brief Setup arguments for sub command "just build". @@ -61,6 +62,7 @@ auto SetupBuildCommandArguments( SetupBuildArguments(app, &clargs->build); SetupTCArguments(app, &clargs->tc); SetupCompatibilityArguments(app); + SetupRetryArguments(app, &clargs->retry); } /// \brief Setup arguments for sub command "just install". @@ -91,6 +93,7 @@ auto SetupInstallCasCommandArguments( SetupClientAuthArguments(app, &clargs->cauth); SetupFetchArguments(app, &clargs->fetch); SetupLogArguments(app, &clargs->log); + SetupRetryArguments(app, &clargs->retry); } /// \brief Setup arguments for sub command "just traverse". diff --git a/src/buildtool/main/cli.hpp b/src/buildtool/main/cli.hpp index 5c8d91ef..1ca45255 100644 --- a/src/buildtool/main/cli.hpp +++ b/src/buildtool/main/cli.hpp @@ -51,6 +51,7 @@ struct CommandLineArguments { ServerAuthArguments sauth; ServiceArguments service; ServeArguments serve; + RetryArguments retry; }; auto ParseCommandLineArguments(int argc, char const* const* argv) diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp index ad1447be..50b8f476 100644 --- a/src/buildtool/main/main.cpp +++ b/src/buildtool/main/main.cpp @@ -42,6 +42,7 @@ #include "src/buildtool/storage/target_cache.hpp" #ifndef BOOTSTRAP_BUILD_TOOL #include "src/buildtool/auth/authentication.hpp" +#include "src/buildtool/common/remote/retry_parameters.hpp" #include "src/buildtool/execution_api/execution_service/operation_cache.hpp" #include "src/buildtool/execution_api/execution_service/server_implementation.hpp" #include "src/buildtool/execution_api/remote/config.hpp" @@ -309,6 +310,29 @@ void SetupHashFunction() { : HashFunction::JustHash::Native); } +void SetupRetryConfig(RetryArguments const& args) { + if (args.max_attempts) { + if (!Retry::SetMaxAttempts(*args.max_attempts)) { + Logger::Log(LogLevel::Error, "Invalid value for max-attempts."); + std::exit(kExitFailure); + } + } + if (args.initial_backoff_seconds) { + if (!Retry::SetInitialBackoffSeconds(*args.initial_backoff_seconds)) { + Logger::Log(LogLevel::Error, + "Invalid value for initial-backoff-seconds."); + std::exit(kExitFailure); + } + } + if (args.max_backoff_seconds) { + if (!Retry::SetMaxBackoffSeconds(*args.max_backoff_seconds)) { + Logger::Log(LogLevel::Error, + "Invalid value for max-backoff-seconds."); + std::exit(kExitFailure); + } + } +} + #endif // BOOTSTRAP_BUILD_TOOL // returns path relative to `root`. @@ -881,6 +905,7 @@ auto main(int argc, char* argv[]) -> int { : std::nullopt; #ifndef BOOTSTRAP_BUILD_TOOL + SetupRetryConfig(arguments.retry); GraphTraverser const traverser{{jobs, std::move(arguments.build), std::move(stage_args), |