This is an automated email from the ASF dual-hosted git repository.
HyukjinKwon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new 2b7423059386 [SPARK-60950][CORE] Reply with a failure when
MapOutputTrackerMaster fails to handle a map output status request
2b7423059386 is described below
commit 2b74230593862eb89d55ef7d331a35b089265eb4
Author: Ivan <[email protected]>
AuthorDate: Thu Nov 12 07:49:44 2026 +0900
[SPARK-60950][CORE] Reply with a failure when MapOutputTrackerMaster fails
to handle a map output status request
### What changes were proposed in this pull request?
`MapOutputTrackerMasterEndpoint` does not answer `GetMapOutputStatuses`,
`GetMapAndMergeResultStatuses` or `GetShufflePushMergerLocations` itself. It
posts each request, together with its `RpcCallContext`, to a queue that
`MapOutputTrackerMaster.MessageLoop` threads serve. If handling a message
throws a non-fatal exception, `MessageLoop` logs it and never replies.
This PR makes `MessageLoop` reply with that exception instead:
- Adds `def context: RpcCallContext` to the sealed, `private[spark]`
`MapOutputTrackerMasterMessage` trait. All three case classes already have this
field, so this only declares it on the trait.
- Takes the message from the queue, and checks for `PoisonPill`, before the
inner `try`, so the message is in scope in the `catch`. An
`InterruptedException` from `take()` still reaches the outer `catch` and stops
the loop, as before.
- In the `catch`, calls `context.sendFailure(e)` after logging, through a
new `replyFailure` helper. If `sendFailure` itself throws (for example, the
exception cannot be serialized), the helper logs a warning and returns. Without
that, the exception would escape to the outer `catch`, which only handles
`InterruptedException`, and kill the dispatcher thread.
- For fatal throwables (anything `NonFatal` does not match), also replies
with `sendFailure` and then rethrows, as the RPC `Inbox` does for
`receiveAndReply`. The error still ends that `MessageLoop` as before; the
waiting request is just answered first.
### Why are the changes needed?
Once a request is queued, the RPC `Inbox` considers it handled, so only
`MessageLoop` can answer it. When the handler throws, nobody answers: the
caller (normally `MapOutputTrackerWorker` on an executor) blocks in `askSync`
until `spark.rpc.askTimeout` expires (120s by default), then fails with an
`RpcTimeoutException` that hides the real error. If a retried task hits the
same exception, every attempt waits out the full timeout.
One easy trigger is a request for a shuffle that is unregistered after the
request is posted but before `MessageLoop` handles it. `handleStatusMessage`
calls `shuffleStatuses.get(shuffleId).head`, which throws
`NoSuchElementException`, and that request never gets a reply. Failures while
serializing or sending the reply take the same path.
### Does this PR introduce _any_ user-facing change?
No API change: the modified trait is `private[spark]` and sealed. If the
driver fails to handle a map output status request, the task now fails
immediately with the actual error, instead of after `spark.rpc.askTimeout` with
an RPC timeout error. Successful requests behave as before.
### How was this patch tested?
Added four tests to `MapOutputTrackerSuite`. For these request kinds the
endpoint only posts the request, so whether a request goes through the endpoint
or is posted directly, the handler runs (and throws) on a
`map-output-dispatcher` `MessageLoop` thread. The tests post directly so they
can drive `MessageLoop` with mocked call contexts, including ones whose `reply`
or `sendFailure` throws, without setting up an `RpcEnv` and endpoint. Each mock
is named after its request kind, so a ve [...]
All four fail on current master (`WantedButNotInvoked` after the 30s
verification timeout) and pass with this change. The whole suite passes:
```shell
build/sbt "core/testOnly org.apache.spark.MapOutputTrackerSuite"
```
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5.5
Closes #60149 from sadikovi/SPARK-60950.
Lead-authored-by: Ivan <[email protected]>
Co-authored-by: Ivan Sadikov <[email protected]>
Signed-off-by: Hyukjin Kwon <[email protected]>
skip-checks: true
---
.../scala/org/apache/spark/MapOutputTracker.scala | 44 ++++++++--
.../org/apache/spark/MapOutputTrackerSuite.scala | 97 +++++++++++++++++++++-
2 files changed, 131 insertions(+), 10 deletions(-)
diff --git a/core/src/main/scala/org/apache/spark/MapOutputTracker.scala
b/core/src/main/scala/org/apache/spark/MapOutputTracker.scala
index 933da9477272..2e5c1c4e98be 100644
--- a/core/src/main/scala/org/apache/spark/MapOutputTracker.scala
+++ b/core/src/main/scala/org/apache/spark/MapOutputTracker.scala
@@ -586,7 +586,9 @@ private[spark] case class
GetShufflePushMergerLocations(shuffleId: Int)
extends MapOutputTrackerMessage
private[spark] case object StopMapOutputTracker extends MapOutputTrackerMessage
-private[spark] sealed trait MapOutputTrackerMasterMessage
+private[spark] sealed trait MapOutputTrackerMasterMessage {
+ def context: RpcCallContext
+}
private[spark] case class GetMapOutputMessage(shuffleId: Int,
context: RpcCallContext) extends MapOutputTrackerMasterMessage
private[spark] case class GetMapAndMergeOutputMessage(shuffleId: Int,
@@ -889,17 +891,33 @@ private[spark] class MapOutputTrackerMaster(
}
}
+ /**
+ * Replies to `message` with `error` after its handler threw. Without this
reply the caller's
+ * ask stays pending until its RPC timeout expires. Never throws, so a
failing reply cannot
+ * kill the MessageLoop thread.
+ */
+ private def replyFailure(message: MapOutputTrackerMasterMessage, error:
Throwable): Unit = {
+ try {
+ message.context.sendFailure(error)
+ } catch {
+ case NonFatal(e) =>
+ logWarning(log"Failed to send the failure reply for " +
+ log"${MDC(CLASS_NAME, message.getClass.getSimpleName)}", e)
+ }
+ }
+
override def run(): Unit = {
try {
while (true) {
- try {
- val data = mapOutputTrackerMasterMessages.take()
- if (data == PoisonPill) {
- // Put PoisonPill back so that other MessageLoops can see it.
- mapOutputTrackerMasterMessages.offer(PoisonPill)
- return
- }
+ // Taken outside the try below so that its catch can reply on the
message's context.
+ val data = mapOutputTrackerMasterMessages.take()
+ if (data == PoisonPill) {
+ // Put PoisonPill back so that other MessageLoops can see it.
+ mapOutputTrackerMasterMessages.offer(PoisonPill)
+ return
+ }
+ try {
data match {
case GetMapOutputMessage(shuffleId, context) =>
handleStatusMessage(shuffleId, context, false)
@@ -912,7 +930,15 @@ private[spark] class MapOutputTrackerMaster(
.getOrElse(Seq.empty[BlockManagerId]))
}
} catch {
- case NonFatal(e) => logError(log"${MDC(ERROR, e.getMessage)}", e)
+ case NonFatal(e) =>
+ logError(log"${MDC(ERROR, e.getMessage)}", e)
+ replyFailure(data, e)
+ case t: Throwable =>
+ // Answer the request before rethrowing, as the RPC Inbox does,
so the caller sees
+ // the error instead of an RPC timeout. The rethrow ends this
MessageLoop as before.
+ logError(log"${MDC(ERROR, t.getMessage)}", t)
+ replyFailure(data, t)
+ throw t
}
}
} catch {
diff --git a/core/src/test/scala/org/apache/spark/MapOutputTrackerSuite.scala
b/core/src/test/scala/org/apache/spark/MapOutputTrackerSuite.scala
index 8668d7cf289f..eef831542a0b 100644
--- a/core/src/test/scala/org/apache/spark/MapOutputTrackerSuite.scala
+++ b/core/src/test/scala/org/apache/spark/MapOutputTrackerSuite.scala
@@ -23,7 +23,7 @@ import java.util.concurrent.atomic.LongAdder
import scala.collection.mutable.ArrayBuffer
import scala.jdk.CollectionConverters._
-import org.mockito.ArgumentMatchers.any
+import org.mockito.ArgumentMatchers.{any, isA}
import org.mockito.Mockito._
import org.mockito.invocation.InvocationOnMock
import org.roaringbitmap.RoaringBitmap
@@ -208,6 +208,101 @@ class MapOutputTrackerSuite extends SparkFunSuite with
LocalSparkContext {
rpcEnv.shutdown()
}
+ // SPARK-60950: for the queued request kinds the endpoint only posts the
request, so on both
+ // routes the handler runs, and throws, on a map-output-dispatcher
MessageLoop thread. These
+ // tests post directly so they can drive the MessageLoop with mocked call
contexts, including
+ // ones whose reply or sendFailure throws, without setting up an RpcEnv and
endpoint.
+
+ /** Creates a master tracker that has shuffle 10 with a single registered
map output. */
+ private def newTrackerMasterWithOneMapOutput(sparkConf: SparkConf):
MapOutputTrackerMaster = {
+ val tracker = newTrackerMaster(sparkConf)
+ tracker.registerShuffle(10, 1, MergeStatus.SHUFFLE_PUSH_DUMMY_NUM_REDUCES)
+ tracker.registerMapOutput(10, 0, MapStatus(
+ BlockManagerId("88", "mph", 1000), createArray(10, 0L), 5))
+ tracker
+ }
+
+ /** Creates a mock call context; `name` shows up in Mockito verification
failures. */
+ private def newCallContext(name: String): RpcCallContext = {
+ val context = mock(classOf[RpcCallContext], withSettings().name(name))
+ when(context.senderAddress).thenReturn(RpcAddress("localhost", 12345))
+ context
+ }
+
+ test("SPARK-60950: master replies with a failure when a map output request
handler throws") {
+ val masterTracker = newTrackerMaster()
+ try {
+ // Shuffle 10 is not registered, so looking up its status throws
NoSuchElementException.
+ val requests: Seq[(String, RpcCallContext =>
MapOutputTrackerMasterMessage)] = Seq(
+ ("GetMapOutputMessage", GetMapOutputMessage(10, _)),
+ ("GetMapAndMergeOutputMessage", GetMapAndMergeOutputMessage(10, _)))
+ requests.foreach { case (name, request) =>
+ val context = newCallContext(name)
+ masterTracker.post(request(context))
+ verify(context,
timeout(30000)).sendFailure(isA(classOf[NoSuchElementException]))
+ verify(context, never()).reply(any())
+ }
+ } finally {
+ masterTracker.stop()
+ }
+ }
+
+ test("SPARK-60950: master replies with a failure when sending the reply
throws") {
+ val masterTracker = newTrackerMasterWithOneMapOutput(conf)
+ try {
+ // Models a reply that cannot be delivered, e.g. one that fails to
serialize.
+ val replyError = new IllegalStateException("injected reply failure")
+ val requests: Seq[(String, RpcCallContext =>
MapOutputTrackerMasterMessage)] = Seq(
+ ("GetMapOutputMessage", GetMapOutputMessage(10, _)),
+ ("GetShufflePushMergersMessage", GetShufflePushMergersMessage(10, _)))
+ requests.foreach { case (name, request) =>
+ val context = newCallContext(name)
+ doThrow(replyError).when(context).reply(any())
+ masterTracker.post(request(context))
+ verify(context, timeout(30000)).sendFailure(replyError)
+ }
+ } finally {
+ masterTracker.stop()
+ }
+ }
+
+ test("SPARK-60950: master replies with a failure when the handler throws a
fatal error") {
+ val masterTracker = newTrackerMasterWithOneMapOutput(conf)
+ try {
+ // A fatal error is rethrown after the reply and ends the MessageLoop
that handled it, so
+ // this test does not rely on that loop serving any later request.
+ val fatalError = new LinkageError("injected fatal reply failure")
+ val context = newCallContext("GetMapOutputMessage")
+ doThrow(fatalError).when(context).reply(any())
+ masterTracker.post(GetMapOutputMessage(10, context))
+ verify(context, timeout(30000)).sendFailure(fatalError)
+ } finally {
+ masterTracker.stop()
+ }
+ }
+
+ test("SPARK-60950: MessageLoop keeps serving requests when the failure reply
also throws") {
+ // A single dispatcher thread, so the second request is served by the same
MessageLoop that
+ // handled the failure.
+ val masterTracker = newTrackerMasterWithOneMapOutput(
+ new SparkConf().set(SHUFFLE_MAPOUTPUT_DISPATCHER_NUM_THREADS, 1))
+ try {
+ val failingContext = newCallContext("failingContext")
+ doThrow(new IllegalStateException("injected sendFailure failure"))
+ .when(failingContext).sendFailure(any())
+ // Shuffle 11 is not registered, so the handler throws and the loop
calls sendFailure.
+ masterTracker.post(GetMapOutputMessage(11, failingContext))
+ verify(failingContext, timeout(30000)).sendFailure(any())
+
+ val context = newCallContext("context")
+ masterTracker.post(GetMapOutputMessage(10, context))
+ verify(context, timeout(30000)).reply(any())
+ verify(context, never()).sendFailure(any())
+ } finally {
+ masterTracker.stop()
+ }
+ }
+
test("min broadcast size exceeds max RPC message size") {
val newConf = new SparkConf
newConf.set(RPC_MESSAGE_MAX_SIZE, 1)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]