felixcheung commented on a change in pull request #24017: [SPARK-27094][YARN] 
Work around RackResolver swallowing thread interrupt.
URL: https://github.com/apache/spark/pull/24017#discussion_r266188431
 
 

 ##########
 File path: 
resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/YarnAllocator.scala
 ##########
 @@ -417,12 +424,40 @@ private[yarn] class YarnAllocator(
         containersToUse, remainingAfterHostMatches)
     }
 
-    // Match remaining by rack
+    // Match remaining by rack. Because YARN's RackResolver swallows thread 
interrupts
+    // (see SPARK-27094), which can cause this code to miss interrupts from 
the AM, use
+    // a separate thread to perform the operation.
     val remainingAfterRackMatches = new ArrayBuffer[Container]
-    for (allocatedContainer <- remainingAfterHostMatches) {
-      val rack = resolver.resolve(conf, allocatedContainer.getNodeId.getHost)
-      matchContainerToRequest(allocatedContainer, rack, containersToUse,
-        remainingAfterRackMatches)
+    if (remainingAfterHostMatches.nonEmpty) {
+      var exception: Option[Throwable] = None
+      val thread = new Thread("spark-rack-resolver") {
+        override def run(): Unit = {
+          try {
+            for (allocatedContainer <- remainingAfterHostMatches) {
+              val rack = resolver.resolve(conf, 
allocatedContainer.getNodeId.getHost)
+              matchContainerToRequest(allocatedContainer, rack, 
containersToUse,
+                remainingAfterRackMatches)
+            }
+          } catch {
+            case NonFatal(e) =>
+              exception = Some(e)
 
 Review comment:
   should it capture all exception/error when it is fatal (if possible)
   I can see how the error can be "lost" on this new thread instead of getting 
propagate to re-throw from the original (the one calling thread.join())

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to