This is an automated email from the ASF dual-hosted git repository. gaoyunhaii pushed a commit to branch release-1.15 in repository https://gitbox.apache.org/repos/asf/flink.git
The following commit(s) were added to refs/heads/release-1.15 by this push: new 95f4b6fc7fd [FLINK-28240][network] Fix the bug that NetworkBufferPool#getRequestedSegmentsUsage may throw ArithmeticException. 95f4b6fc7fd is described below commit 95f4b6fc7fd4a713d8d6348d32a121498ffce1e2 Author: Gen Luo <luogen...@gmail.com> AuthorDate: Thu Jun 30 10:42:44 2022 +0800 [FLINK-28240][network] Fix the bug that NetworkBufferPool#getRequestedSegmentsUsage may throw ArithmeticException. --- .../flink/runtime/io/network/buffer/NetworkBufferPool.java | 7 +++++-- .../flink/runtime/io/network/buffer/NetworkBufferPoolTest.java | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/buffer/NetworkBufferPool.java b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/buffer/NetworkBufferPool.java index ffdb9c727a0..1d83796e49f 100755 --- a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/buffer/NetworkBufferPool.java +++ b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/buffer/NetworkBufferPool.java @@ -381,8 +381,11 @@ public class NetworkBufferPool } public int getRequestedSegmentsUsage() { - return Math.toIntExact( - 100L * getNumberOfRequestedMemorySegments() / getTotalNumberOfMemorySegments()); + int totalNumberOfMemorySegments = getTotalNumberOfMemorySegments(); + return totalNumberOfMemorySegments == 0 + ? 0 + : Math.toIntExact( + 100L * getNumberOfRequestedMemorySegments() / totalNumberOfMemorySegments); } @VisibleForTesting diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/io/network/buffer/NetworkBufferPoolTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/io/network/buffer/NetworkBufferPoolTest.java index 25a5d26c580..5a5bd186b3f 100644 --- a/flink-runtime/src/test/java/org/apache/flink/runtime/io/network/buffer/NetworkBufferPoolTest.java +++ b/flink-runtime/src/test/java/org/apache/flink/runtime/io/network/buffer/NetworkBufferPoolTest.java @@ -325,6 +325,15 @@ public class NetworkBufferPoolTest extends TestLogger { } } + @Test + public void testEmptyPoolSegmentsUsage() throws IOException { + try (CloseableRegistry closeableRegistry = new CloseableRegistry()) { + NetworkBufferPool globalPool = new NetworkBufferPool(0, 128); + closeableRegistry.registerCloseable(globalPool::destroy); + assertEquals(0, globalPool.getRequestedSegmentsUsage()); + } + } + @Test public void testSegmentsUsage() throws IOException { try (CloseableRegistry closeableRegistry = new CloseableRegistry()) {