diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-07-18 14:18:39 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-07-19 09:50:37 +0200 |
commit | 1acde5fa1f37b8e4856f96aba092a38faaac737f (patch) | |
tree | f6ddab8c598502f05f41be2c5567fb5214be0daa | |
parent | 73ad97ca278f5afe1e4d6c7bb2484f6998c754dd (diff) | |
download | justbuild-1acde5fa1f37b8e4856f96aba092a38faaac737f.tar.gz |
just: Fix operation cache threshold exponent maximum value
The threshold exponent cannot pass the log2 of the maximum internal
map size, of type size_t, thus it cannot be larger than 63.
Update the documentation and enforce the upper limit of this
argument during parsing of the command line.
-rw-r--r-- | share/man/just.1.md | 2 | ||||
-rw-r--r-- | src/buildtool/common/cli.hpp | 22 |
2 files changed, 18 insertions, 6 deletions
diff --git a/share/man/just.1.md b/share/man/just.1.md index ccd1964e..dd585920 100644 --- a/share/man/just.1.md +++ b/share/man/just.1.md @@ -797,7 +797,7 @@ Path to the TLS server key. Once the number of operations stored exceeds twice *`2^n`*, where *`n`* is given by the option **`--log-operations-threshold`**, at most *`2^n`* operations will be removed, in a FIFO scheme. If unset, defaults to -14. Must be in the range \[0,255\]. +14. Must be in the range \[0,63\]. **`gc`** specific options ------------------------- diff --git a/src/buildtool/common/cli.hpp b/src/buildtool/common/cli.hpp index 57567cf7..d136756d 100644 --- a/src/buildtool/common/cli.hpp +++ b/src/buildtool/common/cli.hpp @@ -17,6 +17,7 @@ #include <chrono> #include <cstddef> +#include <cstdint> #include <cstdlib> #include <filesystem> #include <optional> @@ -37,7 +38,8 @@ #include "src/buildtool/main/build_utils.hpp" #include "src/utils/cpp/path.hpp" -constexpr auto kDefaultTimeout = std::chrono::milliseconds{300000}; +inline constexpr auto kDefaultTimeout = std::chrono::milliseconds{300000}; +inline constexpr auto kMaxOpCacheExponent = std::uint8_t{63}; /// \brief Arguments common to all commands. struct CommonArguments { @@ -171,7 +173,7 @@ struct ServiceArguments { std::optional<std::filesystem::path> info_file{std::nullopt}; std::optional<std::string> interface{std::nullopt}; std::optional<std::string> pid_file{std::nullopt}; - std::optional<uint8_t> op_exponent; + std::optional<std::uint8_t> op_exponent; }; struct ServeArguments { @@ -742,13 +744,23 @@ static inline auto SetupServiceArguments( "Write pid to this file in plain txt. If the file exists, it " "will be overwritten."); - app->add_option( + app->add_option_function<std::uint8_t>( "--log-operations-threshold", - service_args->op_exponent, + [service_args](auto const& op_exponent) { + if (op_exponent > kMaxOpCacheExponent) { + Logger::Log(LogLevel::Warning, + "Ignoring invalid value {} for operations " + "threshold exponent.", + op_exponent); + } + else { + service_args->op_exponent = op_exponent; + } + }, "Once the number of operations stored exceeds twice 2^n, where n is " "given by the option --log-operations-threshold, at most 2^n " "operations will be removed, in a FIFO scheme. If unset, defaults to " - "14. Must be in the range [0,255]"); + "14. Must be in the range [0,63]"); } static inline auto SetupServeArguments( |