This is an automated email from the ASF dual-hosted git repository.
morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
The following commit(s) were added to refs/heads/master by this push:
new 80f0b5f [BUG] Fix calculation error when the memory parameter is a
float value percentage (#5916)
80f0b5f is described below
commit 80f0b5fd1ca63b7330b889ac8c501e7e0ab33564
Author: Xinyi Zou <[email protected]>
AuthorDate: Thu May 27 22:06:50 2021 +0800
[BUG] Fix calculation error when the memory parameter is a float value
percentage (#5916)
When parsing memory parameters in `ParseUtil::parse_mem_spec`, convert the
percentage to `double` instead of `int`.
The currently affected parameters include `mem_limit` and
`storage_page_cache_limit`
---
be/src/util/parse_util.cpp | 20 +++++++++-----------
be/test/util/parse_util_test.cpp | 6 ++++++
2 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/be/src/util/parse_util.cpp b/be/src/util/parse_util.cpp
index 39768d7..0a54dd9 100644
--- a/be/src/util/parse_util.cpp
+++ b/be/src/util/parse_util.cpp
@@ -69,8 +69,8 @@ int64_t ParseUtil::parse_mem_spec(const std::string&
mem_spec_str, bool* is_perc
StringParser::ParseResult result;
int64_t bytes;
- if (multiplier != -1) {
- // Parse float - MB or GB
+ if (multiplier != -1 || *is_percent) {
+ // Parse float - MB or GB or percent
double limit_val =
StringParser::string_to_float<double>(mem_spec_str.data(),
number_str_len, &result);
@@ -78,28 +78,26 @@ int64_t ParseUtil::parse_mem_spec(const std::string&
mem_spec_str, bool* is_perc
return -1;
}
- bytes = multiplier * limit_val;
+ if (multiplier != -1) {
+ bytes = multiplier * limit_val;
+ } else if (*is_percent) {
+ bytes = (static_cast<double>(limit_val) / 100.0) *
MemInfo::physical_mem();
+ }
} else {
- // Parse int - bytes or percent
+ // Parse int - bytes
int64_t limit_val =
StringParser::string_to_int<int64_t>(mem_spec_str.data(),
number_str_len, &result);
if (result != StringParser::PARSE_SUCCESS) {
return -1;
}
-
- if (*is_percent) {
- bytes = (static_cast<double>(limit_val) / 100.0) *
MemInfo::physical_mem();
- } else {
- bytes = limit_val;
- }
+ bytes = limit_val;
}
// Accept -1 as indicator for infinite memory that we report by a 0 return
value.
if (bytes == -1) {
return 0;
}
-
return bytes;
}
diff --git a/be/test/util/parse_util_test.cpp b/be/test/util/parse_util_test.cpp
index f257fe6..27a97a0 100644
--- a/be/test/util/parse_util_test.cpp
+++ b/be/test/util/parse_util_test.cpp
@@ -55,6 +55,12 @@ TEST(TestParseMemSpec, Normal) {
int64_t bytes = ParseUtil::parse_mem_spec("20%", &is_percent);
ASSERT_GT(bytes, 0);
ASSERT_TRUE(is_percent);
+
+ MemInfo::_s_physical_mem = 1000;
+ is_percent = true;
+ bytes = ParseUtil::parse_mem_spec("0.1%", &is_percent);
+ ASSERT_EQ(bytes, 1);
+ ASSERT_TRUE(is_percent);
}
TEST(TestParseMemSpec, Bad) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]