Skip to content

Commit fbe4a5f

Browse files
teamconfxApache9
authored andcommitted
HBASE-27989 ByteBuffAllocator causes ArithmeticException due to improper poolBufSize value checking (#5388)
Signed-off-by: Duo Zhang <[email protected]> (cherry picked from commit bfc5375)
1 parent c057037 commit fbe4a5f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

hbase-common/src/main/java/org/apache/hadoop/hbase/io/ByteBuffAllocator.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,19 @@ public static ByteBuffAllocator create(Configuration conf, boolean reservoirEnab
175175
// that by the time a handler originated response is actually done writing to socket and so
176176
// released the BBs it used, the handler might have processed one more read req. On an avg 2x
177177
// we consider and consider that also for the max buffers to pool
178+
if (poolBufSize <= 0) {
179+
throw new IllegalArgumentException(BUFFER_SIZE_KEY + " must be positive. Please disable "
180+
+ "the reservoir rather than setting the size of the buffer to zero or negative.");
181+
}
178182
int bufsForTwoMB = (2 * 1024 * 1024) / poolBufSize;
179183
int maxBuffCount =
180184
conf.getInt(MAX_BUFFER_COUNT_KEY, conf.getInt(HConstants.REGION_SERVER_HANDLER_COUNT,
181185
HConstants.DEFAULT_REGION_SERVER_HANDLER_COUNT) * bufsForTwoMB * 2);
182186
int minSizeForReservoirUse = conf.getInt(MIN_ALLOCATE_SIZE_KEY, poolBufSize / 6);
187+
if (minSizeForReservoirUse <= 0) {
188+
LOG.warn("The minimal size for reservoir use is less or equal to zero, all allocations "
189+
+ "will be from the pool. Set a higher " + MIN_ALLOCATE_SIZE_KEY + " to avoid this.");
190+
}
183191
Class<?> clazz = conf.getClass(BYTEBUFF_ALLOCATOR_CLASS, ByteBuffAllocator.class);
184192
return (ByteBuffAllocator) ReflectionUtils.newInstance(clazz, true, maxBuffCount, poolBufSize,
185193
minSizeForReservoirUse);

0 commit comments

Comments
 (0)