You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by gu...@apache.org on 2023/03/08 02:34:09 UTC
[flink] 02/03: [hotfix][runtime] IO Scheduler should handle un-expected exceptions.
This is an automated email from the ASF dual-hosted git repository.
guoweijie pushed a commit to branch release-1.17
in repository https://gitbox.apache.org/repos/asf/flink.git
commit e8c7c1048110e9bdfd470d078eed4ac2678ce72f
Author: Weijie Guo <re...@163.com>
AuthorDate: Mon Mar 6 22:29:43 2023 +0800
[hotfix][runtime] IO Scheduler should handle un-expected exceptions.
(cherry picked from commit faf663a6298c602d93c351f9971eed8aa8dabb93)
---
.../partition/SortMergeResultPartitionReadScheduler.java | 12 +++++++++++-
.../io/network/partition/hybrid/HsFileDataManager.java | 12 +++++++++++-
.../network/partition/hybrid/HsResultPartitionTest.java | 16 ++++++++++++++--
3 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/SortMergeResultPartitionReadScheduler.java b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/SortMergeResultPartitionReadScheduler.java
index 1a5bbae4b54..0f38aca3062 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/SortMergeResultPartitionReadScheduler.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/SortMergeResultPartitionReadScheduler.java
@@ -427,7 +427,17 @@ class SortMergeResultPartitionReadScheduler implements Runnable, BufferRecycler
&& numRequestedBuffers + bufferPool.getNumBuffersPerRequest() <= maxRequestedBuffers
&& numRequestedBuffers < bufferPool.getAverageBuffersPerRequester()) {
isRunning = true;
- ioExecutor.execute(this);
+ ioExecutor.execute(
+ () -> {
+ try {
+ run();
+ } catch (Throwable throwable) {
+ // handle un-expected exception as unhandledExceptionHandler is not
+ // worked for ScheduledExecutorService.
+ FatalExitExceptionHandler.INSTANCE.uncaughtException(
+ Thread.currentThread(), throwable);
+ }
+ });
}
}
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/hybrid/HsFileDataManager.java b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/hybrid/HsFileDataManager.java
index dc898dacfb8..14ac2c84b93 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/hybrid/HsFileDataManager.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/hybrid/HsFileDataManager.java
@@ -289,7 +289,17 @@ public class HsFileDataManager implements Runnable, BufferRecycler {
<= maxRequestedBuffers
&& numRequestedBuffers < bufferPool.getAverageBuffersPerRequester()) {
isRunning = true;
- ioExecutor.execute(this);
+ ioExecutor.execute(
+ () -> {
+ try {
+ run();
+ } catch (Throwable throwable) {
+ // handle un-expected exception as unhandledExceptionHandler is not
+ // worked for ScheduledExecutorService.
+ FatalExitExceptionHandler.INSTANCE.uncaughtException(
+ Thread.currentThread(), throwable);
+ }
+ });
}
}
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/hybrid/HsResultPartitionTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/hybrid/HsResultPartitionTest.java
index 0ad1541f697..f4104e7b869 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/hybrid/HsResultPartitionTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/hybrid/HsResultPartitionTest.java
@@ -45,6 +45,7 @@ import org.apache.flink.runtime.io.network.partition.ResultSubpartitionView;
import org.apache.flink.runtime.metrics.groups.TaskIOMetricGroup;
import org.apache.flink.runtime.metrics.groups.UnregisteredMetricGroups;
import org.apache.flink.util.IOUtils;
+import org.apache.flink.util.concurrent.ExecutorThreadFactory;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -61,8 +62,9 @@ import java.util.Arrays;
import java.util.List;
import java.util.Queue;
import java.util.Random;
-import java.util.concurrent.Executors;
+import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
@@ -100,7 +102,17 @@ class HsResultPartitionTest {
new FileChannelManagerImpl(new String[] {tempDataPath.toString()}, "testing");
globalPool = new NetworkBufferPool(totalBuffers, bufferSize);
readBufferPool = new BatchShuffleReadBufferPool(totalBytes, bufferSize);
- readIOExecutor = Executors.newScheduledThreadPool(numThreads);
+ readIOExecutor =
+ new ScheduledThreadPoolExecutor(
+ numThreads,
+ new ExecutorThreadFactory("test-io-scheduler-thread"),
+ (ignored, executor) -> {
+ if (executor.isShutdown()) {
+ // ignore rejected as shutdown.
+ } else {
+ throw new RejectedExecutionException();
+ }
+ });
}
@AfterEach