This is an automated email from the ASF dual-hosted git repository.
adar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push:
new d7e7ad0 [fs] Fix possible overflow when calculate max_open_files
d7e7ad0 is described below
commit d7e7ad00f0a658fc81c87ca6325080b112ba6896
Author: lingbin <[email protected]>
AuthorDate: Mon Oct 21 16:28:18 2019 +0800
[fs] Fix possible overflow when calculate max_open_files
Originally, use `(rlimit*2)/5` to calculate its 40%, but when rlimit
is very large, `rlimit*2` may overflow, so we should change it
to `(rlimit/5)*2`
Change-Id: I7f0426c303a1c16758c7274a308bc08d613d79e8
Reviewed-on: http://gerrit.cloudera.org:8080/14518
Reviewed-by: Adar Dembo <[email protected]>
Tested-by: Adar Dembo <[email protected]>
---
src/kudu/fs/block_manager.cc | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/src/kudu/fs/block_manager.cc b/src/kudu/fs/block_manager.cc
index 94b4590..7156c91 100644
--- a/src/kudu/fs/block_manager.cc
+++ b/src/kudu/fs/block_manager.cc
@@ -96,9 +96,13 @@ int64_t GetFileCacheCapacityForBlockManager(Env* env) {
rlimit = std::min(rlimit, buf_val);
}
- // Callers of this function expect a signed 64-bit integer, so we need to
- // cap rlimit just in case it's too large.
- return std::min((2 * rlimit) / 5, static_cast<uint64_t>(kint64max));
+ // Callers of this function expect a signed 64-bit integer, and rlimit
+ // is an uint64_t type, so we need to avoid overflow.
+ // The percentage we currently use is 40% by default, and although in fact
+ // 40% of any value of the `uint64_t` type must be less than `kint64max`,
+ // but the percentage may be adjusted in the future, such as to 60%, so to
+ // prevent accidental overflow, we cap rlimit here.
+ return std::min((rlimit / 5) * 2, static_cast<uint64_t>(kint64max));
}
LOG_IF(FATAL, FLAGS_block_manager_max_open_files > rlimit) <<
Substitute(