Copilot commented on code in PR #3692:
URL: https://github.com/apache/celeborn/pull/3692#discussion_r3293898301


##########
client-spark/spark-3/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornShuffleReader.scala:
##########
@@ -548,6 +556,35 @@ class CelebornShuffleReader[K, C](
 
 object CelebornShuffleReader {
   var streamCreatorPool: ThreadPoolExecutor = null
+
+  @VisibleForTesting
+  private[celeborn] def createClientsInParallel(
+      locationsByHostPort: Seq[(String, Seq[PartitionLocation])],
+      streamCreatorPool: ThreadPoolExecutor,
+      createClient: PartitionLocation => TransportClient,
+      onClientCreateFailure: (String, PartitionLocation, Exception) => Unit)
+      : Map[String, TransportClient] = {
+    val clientsByHostPort = JavaUtils.newConcurrentHashMap[String, 
TransportClient]()
+    val futures = locationsByHostPort.map { case (hostPort, locations) =>
+      streamCreatorPool.submit(new Runnable {
+        override def run(): Unit = {
+          locations.find { location =>
+            try {
+              clientsByHostPort.put(hostPort, createClient(location))
+              true
+            } catch {
+              case ex: Exception =>
+                onClientCreateFailure(hostPort, location, ex)
+                false
+            }
+          }
+        }
+      })
+    }
+    futures.foreach(_.get())

Review Comment:
   `futures.foreach(_.get())` can throw `InterruptedException` and clears the 
thread's interrupt flag. Since this runs on Spark task threads, please catch 
`InterruptedException`, restore the interrupt status 
(`Thread.currentThread.interrupt()`), and then propagate/handle it so task 
cancellation semantics remain correct.
   



##########
client-spark/spark-3/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornShuffleReader.scala:
##########
@@ -548,6 +556,35 @@ class CelebornShuffleReader[K, C](
 
 object CelebornShuffleReader {
   var streamCreatorPool: ThreadPoolExecutor = null
+
+  @VisibleForTesting
+  private[celeborn] def createClientsInParallel(
+      locationsByHostPort: Seq[(String, Seq[PartitionLocation])],
+      streamCreatorPool: ThreadPoolExecutor,
+      createClient: PartitionLocation => TransportClient,
+      onClientCreateFailure: (String, PartitionLocation, Exception) => Unit)
+      : Map[String, TransportClient] = {
+    val clientsByHostPort = JavaUtils.newConcurrentHashMap[String, 
TransportClient]()
+    val futures = locationsByHostPort.map { case (hostPort, locations) =>
+      streamCreatorPool.submit(new Runnable {
+        override def run(): Unit = {
+          locations.find { location =>
+            try {
+              clientsByHostPort.put(hostPort, createClient(location))
+              true
+            } catch {
+              case ex: Exception =>
+                onClientCreateFailure(hostPort, location, ex)
+                false
+            }
+          }

Review Comment:
   Using `locations.find { ... }` purely for side effects (and ignoring the 
returned `Option`) makes the retry loop harder to read and maintain. Consider 
switching to `locations.iterator.exists { ... }` (or an explicit loop) so it's 
clear you're iterating until the first successful client creation.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to