This is an automated email from the ASF dual-hosted git repository. zhangduo pushed a commit to branch branch-2.4 in repository https://gitbox.apache.org/repos/asf/hbase.git
commit 4f6709d71475d3abf47065bff15451d99b3b1f56 Author: ConfX <114765570+teamco...@users.noreply.github.com> AuthorDate: Thu Mar 28 23:01:40 2024 +0800 HBASE-27989 ByteBuffAllocator causes ArithmeticException due to improper poolBufSize value checking (#5388) Signed-off-by: Duo Zhang <zhang...@apache.org> (cherry picked from commit bfc537562c86c5b41a52a1eff50bc6c85e89caf9) --- .../main/java/org/apache/hadoop/hbase/io/ByteBuffAllocator.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/ByteBuffAllocator.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/ByteBuffAllocator.java index 4aa99516c49..cfa08f2f3de 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/ByteBuffAllocator.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/ByteBuffAllocator.java @@ -199,11 +199,19 @@ public class ByteBuffAllocator { // that by the time a handler originated response is actually done writing to socket and so // released the BBs it used, the handler might have processed one more read req. On an avg 2x // we consider and consider that also for the max buffers to pool + if (poolBufSize <= 0) { + throw new IllegalArgumentException(BUFFER_SIZE_KEY + " must be positive. Please disable " + + "the reservoir rather than setting the size of the buffer to zero or negative."); + } int bufsForTwoMB = (2 * 1024 * 1024) / poolBufSize; int maxBuffCount = conf.getInt(MAX_BUFFER_COUNT_KEY, conf.getInt(HConstants.REGION_SERVER_HANDLER_COUNT, HConstants.DEFAULT_REGION_SERVER_HANDLER_COUNT) * bufsForTwoMB * 2); int minSizeForReservoirUse = conf.getInt(MIN_ALLOCATE_SIZE_KEY, poolBufSize / 6); + if (minSizeForReservoirUse <= 0) { + LOG.warn("The minimal size for reservoir use is less or equal to zero, all allocations " + + "will be from the pool. Set a higher " + MIN_ALLOCATE_SIZE_KEY + " to avoid this."); + } Class<?> clazz = conf.getClass(BYTEBUFF_ALLOCATOR_CLASS, ByteBuffAllocator.class); return (ByteBuffAllocator) ReflectionUtils.newInstance(clazz, true, maxBuffCount, poolBufSize, minSizeForReservoirUse);