This is an automated email from the ASF dual-hosted git repository.

angerszhuuuu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-celeborn.git


The following commit(s) were added to refs/heads/main by this push:
     new a22c61e47 [CELEBORN-582] Celeborn should handle InterruptedException 
during kill task properly (#1486)
a22c61e47 is described below

commit a22c61e4797309da88de08f6d4e3080d60d0c023
Author: Angerszhuuuu <[email protected]>
AuthorDate: Wed May 17 18:17:41 2023 +0800

    [CELEBORN-582] Celeborn should handle InterruptedException during kill task 
properly (#1486)
---
 .../spark/shuffle/celeborn/SortBasedPusher.java    | 56 ++++++++++------
 .../shuffle/celeborn/TaskInterruptedHelper.java    | 39 +++++++++++
 .../shuffle/celeborn/HashBasedShuffleWriter.java   | 69 +++++++++++---------
 .../shuffle/celeborn/HashBasedShuffleWriter.java   | 75 +++++++++++++---------
 .../celeborn/client/read/DfsPartitionReader.java   |  8 +--
 .../celeborn/client/read/PartitionReader.java      |  2 +-
 .../celeborn/client/read/RssInputStream.java       |  2 +-
 .../client/read/WorkerPartitionReader.java         | 22 ++++---
 .../celeborn/client/write/DataPushQueue.java       |  6 +-
 .../apache/celeborn/client/write/DataPusher.java   | 45 ++++++-------
 .../celeborn/client/write/DataPushQueueSuitJ.java  |  2 +-
 11 files changed, 202 insertions(+), 124 deletions(-)

diff --git 
a/client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/SortBasedPusher.java
 
b/client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/SortBasedPusher.java
index 089dbd6f9..8aa58299a 100644
--- 
a/client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/SortBasedPusher.java
+++ 
b/client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/SortBasedPusher.java
@@ -50,7 +50,7 @@ public class SortBasedPusher extends MemoryConsumer {
   private long pageCursor = -1;
 
   private final ShuffleClient rssShuffleClient;
-  private final DataPusher dataPusher;
+  private DataPusher dataPusher;
   private final int pushBufferMaxSize;
   private final long pushSortMemoryThreshold;
   final int uaoSize = UnsafeAlignedOffset.getUaoSize();
@@ -88,8 +88,7 @@ public class SortBasedPusher extends MemoryConsumer {
       LongAdder[] mapStatusLengths,
       long pushSortMemoryThreshold,
       Object sharedPushLock,
-      ExecutorService executorService)
-      throws IOException {
+      ExecutorService executorService) {
     super(
         memoryManager,
         (int) Math.min(PackedRecordPointer.MAXIMUM_PAGE_SIZE_BYTES, 
memoryManager.pageSizeBytes()),
@@ -115,19 +114,23 @@ public class SortBasedPusher extends MemoryConsumer {
     this.afterPush = afterPush;
     this.mapStatusLengths = mapStatusLengths;
 
-    dataPusher =
-        new DataPusher(
-            appId,
-            shuffleId,
-            mapId,
-            attemptNumber,
-            taskAttemptId,
-            numMappers,
-            numPartitions,
-            conf,
-            rssShuffleClient,
-            afterPush,
-            mapStatusLengths);
+    try {
+      dataPusher =
+          new DataPusher(
+              appId,
+              shuffleId,
+              mapId,
+              attemptNumber,
+              taskAttemptId,
+              numMappers,
+              numPartitions,
+              conf,
+              rssShuffleClient,
+              afterPush,
+              mapStatusLengths);
+    } catch (InterruptedException e) {
+      TaskInterruptedHelper.throwTaskKillException();
+    }
 
     pushBufferMaxSize = conf.pushBufferMaxSize();
     this.pushSortMemoryThreshold = pushSortMemoryThreshold;
@@ -181,7 +184,11 @@ public class SortBasedPusher extends MemoryConsumer {
         int recordSize = UnsafeAlignedOffset.getSize(recordPage, 
recordOffsetInPage);
 
         if (offSet + recordSize > dataBuf.length) {
-          dataPusher.addTask(partition, dataBuf, offSet);
+          try {
+            dataPusher.addTask(partition, dataBuf, offSet);
+          } catch (InterruptedException e) {
+            TaskInterruptedHelper.throwTaskKillException();
+          }
           offSet = 0;
         }
 
@@ -195,7 +202,11 @@ public class SortBasedPusher extends MemoryConsumer {
         offSet += recordSize;
       }
       if (offSet > 0) {
-        dataPusher.addTask(currentPartition, dataBuf, offSet);
+        try {
+          dataPusher.addTask(currentPartition, dataBuf, offSet);
+        } catch (InterruptedException e) {
+          TaskInterruptedHelper.throwTaskKillException();
+        }
       }
 
       long freedBytes = freeMemory();
@@ -279,7 +290,8 @@ public class SortBasedPusher extends MemoryConsumer {
       try {
         Thread.sleep(50);
       } catch (InterruptedException e) {
-        throw new IOException("Interrupted when waitPushFinish", e);
+        logger.error("SortBasedPusher thread interrupted while waiting push 
finished.");
+        TaskInterruptedHelper.throwTaskKillException();
       }
     }
   }
@@ -405,7 +417,11 @@ public class SortBasedPusher extends MemoryConsumer {
 
   public void close() throws IOException {
     cleanupResources();
-    dataPusher.waitOnTermination();
+    try {
+      dataPusher.waitOnTermination();
+    } catch (InterruptedException e) {
+      TaskInterruptedHelper.throwTaskKillException();
+    }
   }
 
   public long getUsed() {
diff --git 
a/client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/TaskInterruptedHelper.java
 
b/client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/TaskInterruptedHelper.java
new file mode 100644
index 000000000..f57d57bf3
--- /dev/null
+++ 
b/client-spark/common/src/main/java/org/apache/spark/shuffle/celeborn/TaskInterruptedHelper.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.shuffle.celeborn;
+
+import org.apache.spark.TaskContext;
+import org.apache.spark.TaskKilledException;
+
+public class TaskInterruptedHelper {
+
+  /**
+   * Apache Celeborn implement shuffle writer in java, Celeborn must catch 
InterruptedException.
+   * According to the constraint of the ShuffleWriter interface, Celeborn 
cannot throw
+   * InterruptedException. Since Spark executor side handle 
TaskKilledException and
+   * InterruptedException in the same way and Spark throw TaskKilledException 
with the TaskContext's
+   * kill reason, so here we throw the TaskKilledException.
+   */
+  public static void throwTaskKillException() {
+    if (TaskContext.get().getKillReason().isDefined()) {
+      throw new TaskKilledException(TaskContext.get().getKillReason().get());
+    } else {
+      throw new TaskKilledException();
+    }
+  }
+}
diff --git 
a/client-spark/spark-2/src/main/java/org/apache/spark/shuffle/celeborn/HashBasedShuffleWriter.java
 
b/client-spark/spark-2/src/main/java/org/apache/spark/shuffle/celeborn/HashBasedShuffleWriter.java
index 532d822d4..a8f8b6378 100644
--- 
a/client-spark/spark-2/src/main/java/org/apache/spark/shuffle/celeborn/HashBasedShuffleWriter.java
+++ 
b/client-spark/spark-2/src/main/java/org/apache/spark/shuffle/celeborn/HashBasedShuffleWriter.java
@@ -94,7 +94,7 @@ public class HashBasedShuffleWriter<K, V, C> extends 
ShuffleWriter<K, V> {
    */
   private volatile boolean stopping = false;
 
-  private final DataPusher dataPusher;
+  private DataPusher dataPusher;
 
   // In order to facilitate the writing of unit test code, ShuffleClient needs 
to be passed in as
   // parameters. By the way, simplify the passed parameters.
@@ -140,35 +140,43 @@ public class HashBasedShuffleWriter<K, V, C> extends 
ShuffleWriter<K, V> {
     }
     sendOffsets = new int[numPartitions];
 
-    dataPusher =
-        new DataPusher(
-            appId,
-            shuffleId,
-            mapId,
-            taskContext.attemptNumber(),
-            taskContext.taskAttemptId(),
-            numMappers,
-            numPartitions,
-            conf,
-            rssShuffleClient,
-            writeMetrics::incBytesWritten,
-            mapStatusLengths);
+    try {
+      dataPusher =
+          new DataPusher(
+              appId,
+              shuffleId,
+              mapId,
+              taskContext.attemptNumber(),
+              taskContext.taskAttemptId(),
+              numMappers,
+              numPartitions,
+              conf,
+              rssShuffleClient,
+              writeMetrics::incBytesWritten,
+              mapStatusLengths);
+    } catch (InterruptedException e) {
+      TaskInterruptedHelper.throwTaskKillException();
+    }
   }
 
   @Override
   public void write(scala.collection.Iterator<Product2<K, V>> records) throws 
IOException {
-    if (canUseFastWrite()) {
-      fastWrite0(records);
-    } else if (dep.mapSideCombine()) {
-      if (dep.aggregator().isEmpty()) {
-        throw new UnsupportedOperationException(
-            "When using map side combine, an aggregator must be specified.");
+    try {
+      if (canUseFastWrite()) {
+        fastWrite0(records);
+      } else if (dep.mapSideCombine()) {
+        if (dep.aggregator().isEmpty()) {
+          throw new UnsupportedOperationException(
+              "When using map side combine, an aggregator must be specified.");
+        }
+        write0(dep.aggregator().get().combineValuesByKey(records, 
taskContext));
+      } else {
+        write0(records);
       }
-      write0(dep.aggregator().get().combineValuesByKey(records, taskContext));
-    } else {
-      write0(records);
+      close();
+    } catch (InterruptedException e) {
+      TaskInterruptedHelper.throwTaskKillException();
     }
-    close();
   }
 
   @VisibleForTesting
@@ -177,7 +185,8 @@ public class HashBasedShuffleWriter<K, V, C> extends 
ShuffleWriter<K, V> {
         && partitioner instanceof PartitionIdPassthrough;
   }
 
-  private void fastWrite0(scala.collection.Iterator iterator) throws 
IOException {
+  private void fastWrite0(scala.collection.Iterator iterator)
+      throws IOException, InterruptedException {
     final scala.collection.Iterator<Product2<Integer, UnsafeRow>> records = 
iterator;
 
     SQLMetric dataSize =
@@ -220,7 +229,7 @@ public class HashBasedShuffleWriter<K, V, C> extends 
ShuffleWriter<K, V> {
     }
   }
 
-  private void write0(scala.collection.Iterator iterator) throws IOException {
+  private void write0(scala.collection.Iterator iterator) throws IOException, 
InterruptedException {
     final scala.collection.Iterator<Product2<K, ?>> records = iterator;
 
     while (records.hasNext()) {
@@ -277,7 +286,8 @@ public class HashBasedShuffleWriter<K, V, C> extends 
ShuffleWriter<K, V> {
     writeMetrics.incWriteTime(System.nanoTime() - pushStartTime);
   }
 
-  private int getOrUpdateOffset(int partitionId, int serializedRecordSize) 
throws IOException {
+  private int getOrUpdateOffset(int partitionId, int serializedRecordSize)
+      throws IOException, InterruptedException {
     int offset = sendOffsets[partitionId];
     byte[] buffer = getOrCreateBuffer(partitionId);
     while ((buffer.length - offset) < serializedRecordSize
@@ -298,14 +308,15 @@ public class HashBasedShuffleWriter<K, V, C> extends 
ShuffleWriter<K, V> {
     return offset;
   }
 
-  private void flushSendBuffer(int partitionId, byte[] buffer, int size) 
throws IOException {
+  private void flushSendBuffer(int partitionId, byte[] buffer, int size)
+      throws IOException, InterruptedException {
     long pushStartTime = System.nanoTime();
     logger.debug("Flush buffer for partition {}, size {}.", partitionId, size);
     dataPusher.addTask(partitionId, buffer, size);
     writeMetrics.incWriteTime(System.nanoTime() - pushStartTime);
   }
 
-  private void close() throws IOException {
+  private void close() throws IOException, InterruptedException {
     // here we wait for all the in-flight batches to return which sent by 
dataPusher thread
     dataPusher.waitOnTermination();
     rssShuffleClient.prepareForMergeData(shuffleId, mapId, 
taskContext.attemptNumber());
diff --git 
a/client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn/HashBasedShuffleWriter.java
 
b/client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn/HashBasedShuffleWriter.java
index e54ba063e..203849577 100644
--- 
a/client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn/HashBasedShuffleWriter.java
+++ 
b/client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn/HashBasedShuffleWriter.java
@@ -99,7 +99,7 @@ public class HashBasedShuffleWriter<K, V, C> extends 
ShuffleWriter<K, V> {
    */
   private volatile boolean stopping = false;
 
-  private final DataPusher dataPusher;
+  private DataPusher dataPusher;
 
   private StructType schema;
 
@@ -148,19 +148,23 @@ public class HashBasedShuffleWriter<K, V, C> extends 
ShuffleWriter<K, V> {
     }
     sendOffsets = new int[numPartitions];
 
-    dataPusher =
-        new DataPusher(
-            appId,
-            shuffleId,
-            mapId,
-            taskContext.attemptNumber(),
-            taskContext.taskAttemptId(),
-            numMappers,
-            numPartitions,
-            conf,
-            rssShuffleClient,
-            writeMetrics::incBytesWritten,
-            mapStatusLengths);
+    try {
+      dataPusher =
+          new DataPusher(
+              appId,
+              shuffleId,
+              mapId,
+              taskContext.attemptNumber(),
+              taskContext.taskAttemptId(),
+              numMappers,
+              numPartitions,
+              conf,
+              rssShuffleClient,
+              writeMetrics::incBytesWritten,
+              mapStatusLengths);
+    } catch (InterruptedException e) {
+      TaskInterruptedHelper.throwTaskKillException();
+    }
 
     if (conf.columnarShuffleEnabled()) {
       this.schema = SparkUtils.getSchema(dep);
@@ -171,22 +175,26 @@ public class HashBasedShuffleWriter<K, V, C> extends 
ShuffleWriter<K, V> {
 
   @Override
   public void write(scala.collection.Iterator<Product2<K, V>> records) throws 
IOException {
-    if (canUseFastWrite()) {
-      if (isColumnarShuffle) {
-        fastColumnarWrite0(records);
+    try {
+      if (canUseFastWrite()) {
+        if (isColumnarShuffle) {
+          fastColumnarWrite0(records);
+        } else {
+          fastWrite0(records);
+        }
+      } else if (dep.mapSideCombine()) {
+        if (dep.aggregator().isEmpty()) {
+          throw new UnsupportedOperationException(
+              "When using map side combine, an aggregator must be specified.");
+        }
+        write0(dep.aggregator().get().combineValuesByKey(records, 
taskContext));
       } else {
-        fastWrite0(records);
-      }
-    } else if (dep.mapSideCombine()) {
-      if (dep.aggregator().isEmpty()) {
-        throw new UnsupportedOperationException(
-            "When using map side combine, an aggregator must be specified.");
+        write0(records);
       }
-      write0(dep.aggregator().get().combineValuesByKey(records, taskContext));
-    } else {
-      write0(records);
+      close();
+    } catch (InterruptedException e) {
+      TaskInterruptedHelper.throwTaskKillException();
     }
-    close();
   }
 
   @VisibleForTesting
@@ -233,7 +241,8 @@ public class HashBasedShuffleWriter<K, V, C> extends 
ShuffleWriter<K, V> {
     }
   }
 
-  private void fastWrite0(scala.collection.Iterator iterator) throws 
IOException {
+  private void fastWrite0(scala.collection.Iterator iterator)
+      throws IOException, InterruptedException {
     final scala.collection.Iterator<Product2<Integer, UnsafeRow>> records = 
iterator;
 
     SQLMetric dataSize = SparkUtils.getDataSize((UnsafeRowSerializer) 
dep.serializer());
@@ -275,7 +284,7 @@ public class HashBasedShuffleWriter<K, V, C> extends 
ShuffleWriter<K, V> {
     }
   }
 
-  private void write0(scala.collection.Iterator iterator) throws IOException {
+  private void write0(scala.collection.Iterator iterator) throws IOException, 
InterruptedException {
     final scala.collection.Iterator<Product2<K, ?>> records = iterator;
 
     while (records.hasNext()) {
@@ -332,7 +341,8 @@ public class HashBasedShuffleWriter<K, V, C> extends 
ShuffleWriter<K, V> {
     writeMetrics.incWriteTime(System.nanoTime() - pushStartTime);
   }
 
-  private int getOrUpdateOffset(int partitionId, int serializedRecordSize) 
throws IOException {
+  private int getOrUpdateOffset(int partitionId, int serializedRecordSize)
+      throws IOException, InterruptedException {
     int offset = sendOffsets[partitionId];
     byte[] buffer = getOrCreateBuffer(partitionId);
     while ((buffer.length - offset) < serializedRecordSize
@@ -353,7 +363,8 @@ public class HashBasedShuffleWriter<K, V, C> extends 
ShuffleWriter<K, V> {
     return offset;
   }
 
-  private void flushSendBuffer(int partitionId, byte[] buffer, int size) 
throws IOException {
+  private void flushSendBuffer(int partitionId, byte[] buffer, int size)
+      throws IOException, InterruptedException {
     long pushStartTime = System.nanoTime();
     logger.debug("Flush buffer, size {}.", size);
     dataPusher.addTask(partitionId, buffer, size);
@@ -419,7 +430,7 @@ public class HashBasedShuffleWriter<K, V, C> extends 
ShuffleWriter<K, V> {
     sendOffsets = null;
   }
 
-  private void close() throws IOException {
+  private void close() throws IOException, InterruptedException {
     // here we wait for all the in-flight batches to return which sent by 
dataPusher thread
     long pushMergedDataTime = System.nanoTime();
     dataPusher.waitOnTermination();
diff --git 
a/client/src/main/java/org/apache/celeborn/client/read/DfsPartitionReader.java 
b/client/src/main/java/org/apache/celeborn/client/read/DfsPartitionReader.java
index e9326c323..46f9abec7 100644
--- 
a/client/src/main/java/org/apache/celeborn/client/read/DfsPartitionReader.java
+++ 
b/client/src/main/java/org/apache/celeborn/client/read/DfsPartitionReader.java
@@ -206,7 +206,7 @@ public class DfsPartitionReader implements PartitionReader {
   }
 
   @Override
-  public ByteBuf next() throws IOException {
+  public ByteBuf next() throws IOException, InterruptedException {
     ByteBuf chunk = null;
     try {
       while (chunk == null) {
@@ -215,10 +215,8 @@ public class DfsPartitionReader implements PartitionReader 
{
         logger.debug("poll result with result size: {}", results.size());
       }
     } catch (InterruptedException e) {
-      Thread.currentThread().interrupt();
-      IOException ioe = new IOException(e);
-      exception.set(ioe);
-      throw ioe;
+      logger.error("PartitionReader thread interrupted while fetching data.");
+      throw e;
     }
     returnedChunks++;
     return chunk;
diff --git 
a/client/src/main/java/org/apache/celeborn/client/read/PartitionReader.java 
b/client/src/main/java/org/apache/celeborn/client/read/PartitionReader.java
index fa88e8c2c..cf8009d90 100644
--- a/client/src/main/java/org/apache/celeborn/client/read/PartitionReader.java
+++ b/client/src/main/java/org/apache/celeborn/client/read/PartitionReader.java
@@ -26,7 +26,7 @@ import org.apache.celeborn.common.protocol.PartitionLocation;
 public interface PartitionReader {
   boolean hasNext();
 
-  ByteBuf next() throws IOException;
+  ByteBuf next() throws IOException, InterruptedException;
 
   void close();
 
diff --git 
a/client/src/main/java/org/apache/celeborn/client/read/RssInputStream.java 
b/client/src/main/java/org/apache/celeborn/client/read/RssInputStream.java
index de48891ce..a7cb295f3 100644
--- a/client/src/main/java/org/apache/celeborn/client/read/RssInputStream.java
+++ b/client/src/main/java/org/apache/celeborn/client/read/RssInputStream.java
@@ -295,7 +295,7 @@ public abstract class RssInputStream extends InputStream {
 
     private PartitionReader createReader(
         PartitionLocation location, int fetchChunkRetryCnt, int 
fetchChunkMaxRetry)
-        throws IOException {
+        throws IOException, InterruptedException {
       if (location.getPeer() == null) {
         logger.debug("Partition {} has only one partition replica.", location);
       }
diff --git 
a/client/src/main/java/org/apache/celeborn/client/read/WorkerPartitionReader.java
 
b/client/src/main/java/org/apache/celeborn/client/read/WorkerPartitionReader.java
index 2058fa8ba..ca4951ad3 100644
--- 
a/client/src/main/java/org/apache/celeborn/client/read/WorkerPartitionReader.java
+++ 
b/client/src/main/java/org/apache/celeborn/client/read/WorkerPartitionReader.java
@@ -71,7 +71,7 @@ public class WorkerPartitionReader implements PartitionReader 
{
       int endMapIndex,
       int fetchChunkRetryCnt,
       int fetchChunkMaxRetry)
-      throws IOException {
+      throws IOException, InterruptedException {
     fetchMaxReqsInFlight = conf.fetchMaxReqsInFlight();
     results = new LinkedBlockingQueue<>();
     // only add the buffer to results queue if this reader is not closed.
@@ -96,11 +96,12 @@ public class WorkerPartitionReader implements 
PartitionReader {
             exception.set(new CelebornIOException(errorMsg, e));
           }
         };
-    TransportClient client;
+    TransportClient client = null;
     try {
       client = clientFactory.createClient(location.getHost(), 
location.getFetchPort());
     } catch (InterruptedException ie) {
-      throw new CelebornIOException("Interrupted when createClient", ie);
+      logger.error("PartitionReader thread interrupted while creating 
client.");
+      throw ie;
     }
     OpenStream openBlocks =
         new OpenStream(shuffleKey, location.getFileName(), startMapIndex, 
endMapIndex);
@@ -119,7 +120,7 @@ public class WorkerPartitionReader implements 
PartitionReader {
     return returnedChunks < streamHandle.numChunks;
   }
 
-  public ByteBuf next() throws IOException {
+  public ByteBuf next() throws IOException, InterruptedException {
     checkException();
     if (chunkIndex < streamHandle.numChunks) {
       fetchChunks();
@@ -131,10 +132,8 @@ public class WorkerPartitionReader implements 
PartitionReader {
         chunk = results.poll(500, TimeUnit.MILLISECONDS);
       }
     } catch (InterruptedException e) {
-      Thread.currentThread().interrupt();
-      IOException ioe = new CelebornIOException(e);
-      exception.set(ioe);
-      throw ioe;
+      logger.error("PartitionReader thread interrupted while polling data.");
+      throw e;
     }
     returnedChunks++;
     return chunk;
@@ -155,7 +154,7 @@ public class WorkerPartitionReader implements 
PartitionReader {
     return location;
   }
 
-  private void fetchChunks() throws IOException {
+  private void fetchChunks() throws IOException, InterruptedException {
     final int inFlight = chunkIndex - returnedChunks;
     if (inFlight < fetchMaxReqsInFlight) {
       final int toFetch =
@@ -169,13 +168,16 @@ public class WorkerPartitionReader implements 
PartitionReader {
                 clientFactory.createClient(location.getHost(), 
location.getFetchPort());
             client.fetchChunk(streamHandle.streamId, chunkIndex, callback);
             chunkIndex++;
-          } catch (IOException | InterruptedException e) {
+          } catch (IOException e) {
             logger.error(
                 "fetchChunk for streamId: {}, chunkIndex: {} failed.",
                 streamHandle.streamId,
                 chunkIndex,
                 e);
             ExceptionUtils.wrapAndThrowIOException(e);
+          } catch (InterruptedException e) {
+            logger.error("PartitionReader thread interrupted while fetching 
chunks.");
+            throw e;
           }
         }
       }
diff --git 
a/client/src/main/java/org/apache/celeborn/client/write/DataPushQueue.java 
b/client/src/main/java/org/apache/celeborn/client/write/DataPushQueue.java
index 843cccbb8..42e97e954 100644
--- a/client/src/main/java/org/apache/celeborn/client/write/DataPushQueue.java
+++ b/client/src/main/java/org/apache/celeborn/client/write/DataPushQueue.java
@@ -28,7 +28,6 @@ import org.slf4j.LoggerFactory;
 import org.apache.celeborn.client.ShuffleClient;
 import org.apache.celeborn.common.CelebornConf;
 import org.apache.celeborn.common.protocol.PartitionLocation;
-import org.apache.celeborn.common.util.ExceptionUtils;
 import org.apache.celeborn.common.util.Utils;
 import org.apache.celeborn.common.write.PushState;
 
@@ -83,7 +82,7 @@ public class DataPushQueue {
    * Now, `takePushTasks` is only used by one thread,
    * so it is not thread-safe.
    * */
-  public ArrayList<PushTask> takePushTasks() throws IOException {
+  public ArrayList<PushTask> takePushTasks() throws IOException, 
InterruptedException {
     ArrayList<PushTask> tasks = new ArrayList<>();
     HashMap<String, Integer> workerCapacity = new HashMap<>();
     while (dataPusher.stillRunning()) {
@@ -126,7 +125,8 @@ public class DataPushQueue {
         // Reaching here means no available tasks can be pushed to any worker, 
wait for a while
         Thread.sleep(takeTaskWaitTimeMs);
       } catch (InterruptedException ie) {
-        ExceptionUtils.wrapAndThrowIOException(ie);
+        logger.info("Thread interrupted while waiting push task.");
+        throw ie;
       }
     }
     return tasks;
diff --git 
a/client/src/main/java/org/apache/celeborn/client/write/DataPusher.java 
b/client/src/main/java/org/apache/celeborn/client/write/DataPusher.java
index 3fdaaafa9..95fcb55be 100644
--- a/client/src/main/java/org/apache/celeborn/client/write/DataPusher.java
+++ b/client/src/main/java/org/apache/celeborn/client/write/DataPusher.java
@@ -73,7 +73,7 @@ public class DataPusher {
       ShuffleClient client,
       Consumer<Integer> afterPush,
       LongAdder[] mapStatusLengths)
-      throws IOException {
+      throws InterruptedException {
     final int pushQueueCapacity = conf.pushQueueCapacity();
     final int pushBufferMaxSize = conf.pushBufferMaxSize();
 
@@ -83,12 +83,7 @@ public class DataPusher {
             conf, this, client, appId, shuffleId, mapId, attemptId, 
numMappers, numPartitions);
 
     for (int i = 0; i < pushQueueCapacity; i++) {
-      try {
-        idleQueue.put(new PushTask(pushBufferMaxSize));
-      } catch (InterruptedException e) {
-        Thread.currentThread().interrupt();
-        throw new CelebornIOException(e);
-      }
+      idleQueue.put(new PushTask(pushBufferMaxSize));
     }
 
     this.appId = appId;
@@ -111,8 +106,8 @@ public class DataPusher {
                 idleFull.signal();
               }
             } catch (InterruptedException e) {
-              Thread.currentThread().interrupt();
-              exceptionRef.set(new CelebornIOException(e));
+              logger.error("DataPusher thread interrupted while reclaiming 
data.");
+              throw e;
             } finally {
               idleLock.unlock();
             }
@@ -130,8 +125,11 @@ public class DataPusher {
                 }
               } catch (CelebornIOException e) {
                 exceptionRef.set(e);
-              } catch (InterruptedException | IOException e) {
+              } catch (IOException e) {
                 exceptionRef.set(new CelebornIOException(e));
+              } catch (InterruptedException e) {
+                logger.error("DataPusher push thread interrupted while pushing 
data.");
+                break;
               }
             }
           }
@@ -140,7 +138,8 @@ public class DataPusher {
     pushThread.start();
   }
 
-  public void addTask(int partitionId, byte[] buffer, int size) throws 
IOException {
+  public void addTask(int partitionId, byte[] buffer, int size)
+      throws IOException, InterruptedException {
     try {
       PushTask task = null;
       while (task == null) {
@@ -154,27 +153,29 @@ public class DataPusher {
         checkException();
       }
     } catch (InterruptedException e) {
-      Thread.currentThread().interrupt();
-      IOException ioe = new CelebornIOException(e);
-      exceptionRef.set(ioe);
-      throw ioe;
+      logger.error("DataPusher thread interrupted while adding push task.");
+      pushThread.interrupt();
+      throw e;
     }
   }
 
-  public void waitOnTermination() throws IOException {
+  public void waitOnTermination() throws IOException, InterruptedException {
     try {
       idleLock.lockInterruptibly();
       waitIdleQueueFullWithLock();
     } catch (InterruptedException e) {
-      Thread.currentThread().interrupt();
-      exceptionRef.set(new CelebornIOException(e));
+      logger.error("DataPusher thread interrupted while waitOnTermination.");
+      pushThread.interrupt();
+      throw e;
     }
 
     terminated = true;
     try {
       pushThread.join();
-    } catch (InterruptedException ignored) {
+    } catch (InterruptedException e) {
       logger.info("Thread interrupted while joining pushThread");
+      Thread.currentThread().interrupt();
+      throw e;
     }
     idleQueue.clear();
     dataPushQueue.clear();
@@ -208,14 +209,14 @@ public class DataPusher {
     mapStatusLengths[task.getPartitionId()].add(bytesWritten);
   }
 
-  private void waitIdleQueueFullWithLock() {
+  private void waitIdleQueueFullWithLock() throws InterruptedException {
     try {
       while (idleQueue.remainingCapacity() > 0 && exceptionRef.get() == null) {
         idleFull.await(WAIT_TIME_NANOS, TimeUnit.NANOSECONDS);
       }
     } catch (InterruptedException e) {
-      Thread.currentThread().interrupt();
-      exceptionRef.set(new CelebornIOException(e));
+      logger.error("Thread interrupted while waitIdleQueueFullWithLock.", e);
+      throw e;
     } finally {
       idleLock.unlock();
     }
diff --git 
a/client/src/test/java/org/apache/celeborn/client/write/DataPushQueueSuitJ.java 
b/client/src/test/java/org/apache/celeborn/client/write/DataPushQueueSuitJ.java
index 29b66a33f..70850377d 100644
--- 
a/client/src/test/java/org/apache/celeborn/client/write/DataPushQueueSuitJ.java
+++ 
b/client/src/test/java/org/apache/celeborn/client/write/DataPushQueueSuitJ.java
@@ -139,7 +139,7 @@ public class DataPushQueueSuitJ {
                         partitionBatchIdMap.get(partitionId),
                         reducePartitionMap.get(partitionId).hostAndPushPort());
                   }
-                } catch (IOException e) {
+                } catch (IOException | InterruptedException e) {
                   throw new RuntimeException(e);
                 }
               }

Reply via email to