summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2024-04-17 12:52:42 +0200
committerKlaus Aehlig <klaus.aehlig@huawei.com>2024-04-18 15:51:28 +0200
commit8744b30b9612354b42474b2a1fb323fce5d182c1 (patch)
tree3526b4c3694791ecfd84c94e3809d25d9bf25b9d /src
parent3e19cd959774ccb09df97e8dd96d5bacfff57ca3 (diff)
downloadjustbuild-8744b30b9612354b42474b2a1fb323fce5d182c1.tar.gz
Move retry-related CLI parts into separate libraries
... to simplify reuse.
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/common/TARGETS8
-rw-r--r--src/buildtool/common/cli.hpp29
-rw-r--r--src/buildtool/common/retry_cli.hpp51
-rw-r--r--src/buildtool/main/TARGETS11
-rw-r--r--src/buildtool/main/main.cpp29
-rw-r--r--src/buildtool/main/retry.cpp53
-rw-r--r--src/buildtool/main/retry.hpp22
7 files changed, 149 insertions, 54 deletions
diff --git a/src/buildtool/common/TARGETS b/src/buildtool/common/TARGETS
index d79fa3bf..5e882fce 100644
--- a/src/buildtool/common/TARGETS
+++ b/src/buildtool/common/TARGETS
@@ -5,12 +5,20 @@
, "stage": ["src", "buildtool", "common"]
, "deps": [["src/buildtool/logging", "log_level"]]
}
+, "retry_cli":
+ { "type": ["@", "rules", "CC", "library"]
+ , "name": ["retry_cli"]
+ , "hdrs": ["retry_cli.hpp"]
+ , "stage": ["src", "buildtool", "common"]
+ , "deps": [["@", "cli11", "", "cli11"], ["@", "gsl", "", "gsl"]]
+ }
, "cli":
{ "type": ["@", "rules", "CC", "library"]
, "name": ["cli"]
, "hdrs": ["cli.hpp"]
, "deps":
[ "clidefaults"
+ , "retry_cli"
, ["src/buildtool/build_engine/expression", "expression"]
, ["src/buildtool/compatibility", "compatibility"]
, ["src/buildtool/logging", "log_level"]
diff --git a/src/buildtool/common/cli.hpp b/src/buildtool/common/cli.hpp
index 1d64fbda..eded8112 100644
--- a/src/buildtool/common/cli.hpp
+++ b/src/buildtool/common/cli.hpp
@@ -31,6 +31,7 @@
#include "nlohmann/json.hpp"
#include "src/buildtool/build_engine/expression/evaluator.hpp"
#include "src/buildtool/common/clidefaults.hpp"
+#include "src/buildtool/common/retry_cli.hpp"
#include "src/buildtool/compatibility/compatibility.hpp"
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/main/build_utils.hpp"
@@ -92,13 +93,6 @@ 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{};
@@ -761,27 +755,6 @@ 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)");
-}
-
static inline void SetupGcArguments(gsl::not_null<CLI::App*> const& app,
gsl::not_null<GcArguments*> const& args) {
app->add_flag("--no-rotate",
diff --git a/src/buildtool/common/retry_cli.hpp b/src/buildtool/common/retry_cli.hpp
new file mode 100644
index 00000000..53076252
--- /dev/null
+++ b/src/buildtool/common/retry_cli.hpp
@@ -0,0 +1,51 @@
+// Copyright 2024 Huawei Cloud Computing Technology Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef INCLUDED_SRC_BUILDTOOL_COMMON_RETRY_CLI_HPP
+#define INCLUDED_SRC_BUILDTOOL_COMMON_RETRY_CLI_HPP
+
+#include <optional>
+
+#include "CLI/CLI.hpp"
+#include "gsl/gsl"
+
+/// \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{};
+};
+
+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
diff --git a/src/buildtool/main/TARGETS b/src/buildtool/main/TARGETS
index 4f439201..f1d5aa99 100644
--- a/src/buildtool/main/TARGETS
+++ b/src/buildtool/main/TARGETS
@@ -31,7 +31,6 @@
, ["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"]
, ["src/buildtool/storage", "file_chunker"]
, "common"
, "cli"
@@ -44,6 +43,7 @@
, "constants"
, "serve"
, "build_utils"
+ , "retry"
]
, "stage": ["src", "buildtool", "main"]
, "private-ldflags":
@@ -54,6 +54,15 @@
]
}
}
+, "retry":
+ { "type": ["@", "rules", "CC", "library"]
+ , "name": ["retry"]
+ , "hdrs": ["retry.hpp"]
+ , "srcs": ["retry.cpp"]
+ , "stage": ["src", "buildtool", "main"]
+ , "deps": [["src/buildtool/common", "retry_cli"]]
+ , "private-deps": [["src/buildtool/common/remote", "retry_parameters"]]
+ }
, "describe":
{ "type": ["@", "rules", "CC", "library"]
, "name": ["describe"]
diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp
index 59225fc7..a5185a47 100644
--- a/src/buildtool/main/main.cpp
+++ b/src/buildtool/main/main.cpp
@@ -50,6 +50,7 @@
#include "src/buildtool/main/diagnose.hpp"
#include "src/buildtool/main/exit_codes.hpp"
#include "src/buildtool/main/install_cas.hpp"
+#include "src/buildtool/main/retry.hpp"
#include "src/buildtool/main/version.hpp"
#include "src/buildtool/multithreading/async_map_consumer.hpp"
#include "src/buildtool/multithreading/task_system.hpp"
@@ -64,7 +65,6 @@
#ifndef BOOTSTRAP_BUILD_TOOL
#include "fmt/core.h"
#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"
@@ -329,29 +329,6 @@ void SetupFileChunker() {
FileChunker::Initialize();
}
-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`.
@@ -931,7 +908,9 @@ auto main(int argc, char* argv[]) -> int {
Progress progress{};
#ifndef BOOTSTRAP_BUILD_TOOL
- SetupRetryConfig(arguments.retry);
+ if (not SetupRetryConfig(arguments.retry)) {
+ std::exit(kExitFailure);
+ }
GraphTraverser const traverser{
{jobs,
std::move(arguments.build),
diff --git a/src/buildtool/main/retry.cpp b/src/buildtool/main/retry.cpp
new file mode 100644
index 00000000..f2ba4b3a
--- /dev/null
+++ b/src/buildtool/main/retry.cpp
@@ -0,0 +1,53 @@
+// Copyright 2024 Huawei Cloud Computing Technology Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "src/buildtool/main/retry.hpp"
+
+#ifdef BOOTSTRAP_BUILD_TOOL
+
+[[nodiscard]] auto SetupRetryConfig(RetryArguments const& args) -> bool {
+ return true;
+}
+
+#else
+
+#include "src/buildtool/common/remote/retry_parameters.hpp"
+#include "src/buildtool/logging/log_level.hpp"
+#include "src/buildtool/logging/logger.hpp"
+
+[[nodiscard]] auto SetupRetryConfig(RetryArguments const& args) -> bool {
+ if (args.max_attempts) {
+ if (!Retry::SetMaxAttempts(*args.max_attempts)) {
+ Logger::Log(LogLevel::Error, "Invalid value for max-attempts.");
+ return false;
+ }
+ }
+ if (args.initial_backoff_seconds) {
+ if (!Retry::SetInitialBackoffSeconds(*args.initial_backoff_seconds)) {
+ Logger::Log(LogLevel::Error,
+ "Invalid value for initial-backoff-seconds.");
+ return false;
+ }
+ }
+ if (args.max_backoff_seconds) {
+ if (!Retry::SetMaxBackoffSeconds(*args.max_backoff_seconds)) {
+ Logger::Log(LogLevel::Error,
+ "Invalid value for max-backoff-seconds.");
+ return false;
+ }
+ }
+ return true;
+}
+
+#endif // BOOTSTRAP_BUILD_TOOL
diff --git a/src/buildtool/main/retry.hpp b/src/buildtool/main/retry.hpp
new file mode 100644
index 00000000..ddc89557
--- /dev/null
+++ b/src/buildtool/main/retry.hpp
@@ -0,0 +1,22 @@
+// Copyright 2024 Huawei Cloud Computing Technology Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef INCLUDED_SRC_BUILDOOL_MAIN_RETRY_HPP
+#define INCLUDED_SRC_BUILDOOL_MAIN_RETRY_HPP
+
+#include "src/buildtool/common/retry_cli.hpp"
+
+[[nodiscard]] auto SetupRetryConfig(RetryArguments const& args) -> bool;
+
+#endif