This is an automated email from the ASF dual-hosted git repository.
zaynt4606 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/celeborn.git
The following commit(s) were added to refs/heads/main by this push:
new 1f0c5f2f5d [CELEBORN-2520] Show partition splits and push failures per
worker in the Spark UI Celeborn tab
1f0c5f2f5d is described below
commit 1f0c5f2f5d32e18a56690d56c14f6a4262fd3511
Author: ForVic <[email protected]>
AuthorDate: Mon Nov 16 16:12:10 2026 +0800
[CELEBORN-2520] Show partition splits and push failures per worker in the
Spark UI Celeborn tab
### What changes were proposed in this pull request?
Show how many partitions were revived on each worker because of a soft
split, a hard split or a push failure, on the Celeborn tab of the Spark UI and
the History Server. This covers the split and failure part of the "Shuffle
Write Servers" follow-up planned in CELEBORN-2415. The driver-side
LifecycleManager already handles every revive, so no executor changes are
needed.
- **client**: once new slots are reserved, `ChangePartitionManager` reports
each batch of revived partitions to a new `PartitionReviveListener`, counted by
worker and revive cause. Requests are already deduplicated per partition at
that point, so a partition counts once per revive however many map tasks asked
for it. Revives that fail to reserve slots are not reported, since the client
retries them. Replica push failures (`*_REPLICA`, `REPLICATE_DATA_FAILED`)
count against the replica [...]
- **spark-ui**: `CelebornPlugin` posts a `CelebornPartitionReviveEvent` per
batch, and `CelebornListener` keeps per-worker totals by cause in the KVStore
for the live UI and History Server replay. When it registers the listener, the
plugin also posts a one-off `CelebornPartitionReviveReportingEvent`, so event
logs from older clients show `N/A` rather than zero. The tab gets a *Revived
Partitions* summary line and, once any partition is revived, a collapsed
*Worker Revives* table with [...]
### Why are the changes needed?
Splits and push failures are only visible in the driver log today. Per
worker, they show which workers keep hitting the split threshold or the file
size limit, and which ones fail pushes for this application.
### Does this PR resolve a correctness bug?
- [ ] Yes
### Does this PR introduce _any_ user-facing change?
- [x] Yes
The Celeborn tab gets the summary line and, once any partition is revived,
the collapsed table. Nothing changes for applications without `CelebornPlugin`.
Some things are not covered:
- The counts are revived partitions, not failed pushes. Pushes that fail
against a location that was already revived are not counted again. A note under
the table says so.
- Splits count against the primary worker, even when its replica triggered
the split, because the primary forwards the replica's split status unchanged.
The split columns say *(Primary)* and the note under the table explains this.
- Push failures include partitions revived because the client had already
excluded the worker after an earlier failure, shown with a `*_WORKER_EXCLUDED`
cause.
- Congestion never reaches the driver, so it is not included.
- As with shuffle assignments, shuffle managers that create their own
LifecycleManager (e.g. Gluten's) report nothing.
Same workload on a local cluster: Spark 3.5.9, 4 workers, replication
enabled, `spark.celeborn.client.shuffle.partitionSplit.threshold=2m`. Workers 3
and 4 set `celeborn.worker.shuffle.partitionSplit.max=1m`, so every split there
is a hard split. Worker 2 is killed during the second shuffle.
Before (main):

After, with *Worker Revives* expanded:

### How was this patch tested?
- `LifecycleManagerSuite`: against a mini cluster, revives sent through the
`Revive` RPC are reported once per partition, with a hard split counted against
the primary worker and a replica push timeout against the replica worker. A
revive that gets no new slots is not reported.
- `CelebornListenerSuite`: per-worker totals across events, the event JSON
round trip, and the History Server KVStore serializer round trip.
- `CelebornPluginSuite`: a local SparkContext with `CelebornPlugin` and
`SparkShuffleManager` has the listener registered, and reported revives reach
the UI store and the rendered page. On History Server replay, an event log
without the reporting event shows `N/A`, one with it shows zero, and the
*Worker Revives* table appears only once partitions were revived. A shuffle
manager other than `SparkShuffleManager` reports nothing.
- `./build/mvn -P<profile> -pl client-spark/spark-3-ui test` passes for
`spark-3.0`, `spark-3.5` and `spark-4.0`.
- Manual: the run above. The tab shows 88 soft splits, 171 hard splits and
3 push failures, which matches the 262 partitions in the driver's `Batch handle
change partition` log lines. All 3 push failures are on the killed worker,
including the replica connection failure of a primary replicating to it. The
History Server shows the same numbers after replay
([screenshot](https://raw.githubusercontent.com/ForVic/celeborn/9f26382da46dabc377f537c3580e8d39b1617cc6/history-server.png)),
and [...]
Closes #3918 from ForVic/ForVic/spark-ui-worker-revives.
Authored-by: ForVic <[email protected]>
Signed-off-by: zhengtao <[email protected]>
AI-Contributed/Feature: 0/274
AI-Contributed/UT: 0/289
---
.../spark/shuffle/celeborn/CelebornListener.scala | 17 +++
.../celeborn/CelebornPartitionReviveEvent.scala | 37 +++++
.../spark/shuffle/celeborn/CelebornPlugin.scala | 10 +-
.../shuffle/celeborn/CelebornStatusStore.scala | 18 +++
.../shuffle/celeborn/ui/CelebornShufflePage.scala | 84 +++++++++++
.../shuffle/celeborn/CelebornListenerSuite.scala | 79 +++++++++++
.../shuffle/celeborn/CelebornPluginSuite.scala | 157 ++++++++++++++++++++-
.../shuffle/celeborn/SparkShuffleManager.java | 15 ++
.../client/listener/PartitionReviveListener.java | 41 ++++++
.../celeborn/client/ChangePartitionManager.scala | 1 +
.../apache/celeborn/client/LifecycleManager.scala | 51 ++++++-
.../tests/client/LifecycleManagerSuite.scala | 53 ++++++-
12 files changed, 558 insertions(+), 5 deletions(-)
diff --git
a/client-spark/spark-3-ui/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornListener.scala
b/client-spark/spark-3-ui/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornListener.scala
index efcc56841a..7a238d2dac 100644
---
a/client-spark/spark-3-ui/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornListener.scala
+++
b/client-spark/spark-3-ui/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornListener.scala
@@ -67,6 +67,8 @@ private[celeborn] class CelebornListener(
private var assignedShuffles = 0L
private val workerShuffles = mutable.HashMap[String, Int]()
private val workerSlots = mutable.HashMap[String, Int]()
+ // worker -> revive cause -> revived partitions.
+ private val workerRevives = mutable.HashMap[String, mutable.HashMap[String,
Int]]()
def register(sc: org.apache.spark.SparkContext): Unit = {
sc.addSparkListener(this)
@@ -107,6 +109,9 @@ private[celeborn] class CelebornListener(
mayUpdate()
}
case e: CelebornShuffleAssignmentEvent => onShuffleAssignment(e)
+ // Persists an empty record, which tells no revives apart from unreported
revives.
+ case _: CelebornPartitionReviveReportingEvent =>
onPartitionRevive(Map.empty)
+ case e: CelebornPartitionReviveEvent => onPartitionRevive(e.workerRevives)
case _ =>
}
@@ -163,6 +168,18 @@ private[celeborn] class CelebornListener(
kvstore.write(WorkerSlotsUIData(assignedShuffles, workerShuffles.toMap,
workerSlots.toMap))
}
+ // Written right away like shuffle assignments, since a revive can arrive
after the last
+ // throttled flush of an application that then stays idle.
+ private def onPartitionRevive(revives: Map[String, Map[String, Int]]): Unit
= {
+ revives.foreach { case (worker, causes) =>
+ val totals = workerRevives.getOrElseUpdate(worker,
mutable.HashMap[String, Int]())
+ causes.foreach { case (cause, n) => totals(cause) =
totals.getOrElse(cause, 0) + n }
+ }
+ kvstore.write(WorkerRevivesUIData(workerRevives.map { case (worker,
causes) =>
+ worker -> causes.toMap
+ }.toMap))
+ }
+
// Drops the lowest Celeborn shuffle ids, which roughly are the oldest
shuffles.
private def dropLowestShuffleAssignments(): Unit = {
val uiDataClass = classOf[ShuffleAssignmentUIData]
diff --git
a/client-spark/spark-3-ui/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornPartitionReviveEvent.scala
b/client-spark/spark-3-ui/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornPartitionReviveEvent.scala
new file mode 100644
index 0000000000..0626990095
--- /dev/null
+++
b/client-spark/spark-3-ui/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornPartitionReviveEvent.scala
@@ -0,0 +1,37 @@
+/*
+ * 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.scheduler.SparkListenerEvent
+
+/**
+ * Partitions of a Celeborn shuffle revived in one batch, counted by worker
unique id and
+ * revive cause (a StatusCode name, e.g. SOFT_SPLIT). Recorded in the event
log; the listener
+ * writes the per-worker totals to the KVStore both for the live UI and on
History Server replay.
+ */
+private[celeborn] case class CelebornPartitionReviveEvent(
+ shuffleId: Int,
+ appShuffleId: Int,
+ workerRevives: Map[String, Map[String, Int]])
+ extends SparkListenerEvent
+
+/**
+ * Recorded once when the driver plugin registers the revive listener, so that
the UI shows zero
+ * for applications without revives, but N/A for event logs of clients that
did not report them.
+ */
+private[celeborn] case class CelebornPartitionReviveReportingEvent() extends
SparkListenerEvent
diff --git
a/client-spark/spark-3-ui/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornPlugin.scala
b/client-spark/spark-3-ui/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornPlugin.scala
index 54c85dc2ef..becbd5b7cc 100644
---
a/client-spark/spark-3-ui/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornPlugin.scala
+++
b/client-spark/spark-3-ui/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornPlugin.scala
@@ -76,8 +76,16 @@ private class CelebornDriverPlugin extends DriverPlugin with
Logging {
shuffleId,
appShuffleId,
workerSlots.asScala.map { case (worker, slots) => worker ->
slots.intValue }.toMap)))
+ manager.registerPartitionReviveListener((shuffleId, appShuffleId,
workerRevives) =>
+ sc.listenerBus.post(CelebornPartitionReviveEvent(
+ shuffleId,
+ appShuffleId,
+ workerRevives.asScala.map { case (worker, causes) =>
+ worker -> causes.asScala.map { case (cause, n) => cause.name ->
n.intValue }.toMap
+ }.toMap)))
+ sc.listenerBus.post(CelebornPartitionReviveReportingEvent())
case other =>
- logInfo("Shuffle assignments are not reported by shuffle manager " +
+ logInfo("Shuffle assignments and partition revives are not reported by
shuffle manager " +
s"${Option(other).map(_.getClass.getName).orNull}.")
}
}
diff --git
a/client-spark/spark-3-ui/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornStatusStore.scala
b/client-spark/spark-3-ui/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornStatusStore.scala
index dbc4f64940..8977e88c52 100644
---
a/client-spark/spark-3-ui/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornStatusStore.scala
+++
b/client-spark/spark-3-ui/src/main/scala/org/apache/spark/shuffle/celeborn/CelebornStatusStore.scala
@@ -79,6 +79,14 @@ private[celeborn] case class WorkerSlotsUIData(
def id: String = classOf[WorkerSlotsUIData].getName
}
+/** Revived partitions of each worker by revive cause, over all shuffles of
the application. */
+private[celeborn] case class WorkerRevivesUIData(workerRevives: Map[String,
Map[String, Int]]) {
+
+ @JsonIgnore
+ @KVIndex
+ def id: String = classOf[WorkerRevivesUIData].getName
+}
+
/**
* Marker persisted during History Server replay when the application's
recorded
* `spark.plugins` or `spark.plugins.defaultList` contains [[CelebornPlugin]].
@@ -137,6 +145,16 @@ private[celeborn] class CelebornStatusStore(store:
KVStore) {
}
}
+ // None means reporting was unavailable; an empty record means no revives
occurred.
+ def workerRevives(): Option[WorkerRevivesUIData] = {
+ val kClass = classOf[WorkerRevivesUIData]
+ try {
+ Some(store.read(kClass, kClass.getName))
+ } catch {
+ case _: NoSuchElementException => None
+ }
+ }
+
def extensionEnabled(): Boolean = {
val kClass = classOf[CelebornExtensionEnabledUIData]
try {
diff --git
a/client-spark/spark-3-ui/src/main/scala/org/apache/spark/shuffle/celeborn/ui/CelebornShufflePage.scala
b/client-spark/spark-3-ui/src/main/scala/org/apache/spark/shuffle/celeborn/ui/CelebornShufflePage.scala
index a8d4356e64..eee0b9c8af 100644
---
a/client-spark/spark-3-ui/src/main/scala/org/apache/spark/shuffle/celeborn/ui/CelebornShufflePage.scala
+++
b/client-spark/spark-3-ui/src/main/scala/org/apache/spark/shuffle/celeborn/ui/CelebornShufflePage.scala
@@ -25,11 +25,25 @@ import
org.apache.spark.shuffle.celeborn.ui.SparkServletBridge.HttpServletReques
import org.apache.spark.ui.{UIUtils, WebUIPage}
import org.apache.spark.util.Utils
+import org.apache.celeborn.common.protocol.message.StatusCode
+
+private case class WorkerReviveRow(
+ worker: String,
+ softSplits: Int,
+ hardSplits: Int,
+ failureCauses: Seq[(String, Int)]) {
+ def pushFailures: Int = failureCauses.map(_._2).sum
+ def total: Int = softSplits + hardSplits + pushFailures
+}
+
private[celeborn] class CelebornShufflePage(parent: CelebornUITab)
extends WebUIPage("") with Logging {
private val store = parent.store
+ private val SoftSplit = StatusCode.SOFT_SPLIT.name
+ private val HardSplit = StatusCode.HARD_SPLIT.name
+
override def render(request: HttpServletRequest): Seq[Node] = {
try {
renderBody(request)
@@ -60,6 +74,15 @@ private[celeborn] class CelebornShufflePage(parent:
CelebornUITab)
val workerRows = workerSlots.workerSlots.toSeq.map { case (worker, slots)
=>
(worker, workerSlots.workerShuffles.getOrElse(worker, 0), slots)
}.sortBy { case (worker, _, slots) => (-slots, worker) }
+ val workerRevives = store.workerRevives()
+ val reviveRows =
+ workerRevives.toSeq.flatMap(_.workerRevives.toSeq).map { case (worker,
causes) =>
+ WorkerReviveRow(
+ worker,
+ causes.getOrElse(SoftSplit, 0),
+ causes.getOrElse(HardSplit, 0),
+ (causes - SoftSplit - HardSplit).toSeq.sortBy { case (cause, n) =>
(-n, cause) })
+ }.sortBy(row => (-row.total, row.worker))
val writeBytes = taskInfo.shuffleWriteBytes
val readBytes = taskInfo.shuffleReadBytes
@@ -79,6 +102,14 @@ private[celeborn] class CelebornShufflePage(parent:
CelebornUITab)
s"Shuffles: ${workerSlots.shuffles} | Workers: ${workerRows.size} | " +
s"Reserved Slots: ${workerRows.map(_._3.toLong).sum}"
}
+ // Revived partitions by cause, not individual pushes.
+ def reviveSummary: String =
+ if (workerRevives.isEmpty) "N/A"
+ else {
+ s"Soft Split: ${reviveRows.map(_.softSplits.toLong).sum} | " +
+ s"Hard Split: ${reviveRows.map(_.hardSplits.toLong).sum} | " +
+ s"Push Failure: ${reviveRows.map(_.pushFailures.toLong).sum}"
+ }
val assignmentsTitle =
if (workerSlots.shuffles > assignments.size) {
s"Shuffle Assignments (${workerSlots.shuffles}, only showing
${assignments.size})"
@@ -127,6 +158,10 @@ private[celeborn] class CelebornShufflePage(parent:
CelebornUITab)
<strong>Shuffle Assignments: </strong>
{assignmentSummary}
</li>
+ <li>
+ <strong>Revived Partitions: </strong>
+ {reviveSummary}
+ </li>
</ul>
</div>
@@ -156,6 +191,41 @@ private[celeborn] class CelebornShufflePage(parent:
CelebornUITab)
fixedWidth = true,
headerClasses = Seq("sorttable_alpha", "sorttable_numeric",
"sorttable_numeric"))
+ val workerRevivesTable = UIUtils.listingTable(
+ Seq(
+ "Worker",
+ "Soft Split (Primary)",
+ "Hard Split (Primary)",
+ "Push Failure",
+ "Push Failure Causes"),
+ workerReviveRow,
+ reviveRows,
+ fixedWidth = true,
+ headerClasses = Seq("sorttable_alpha") ++
Seq.fill(3)("sorttable_numeric") ++
+ Seq("sorttable_alpha"))
+ // Most applications revive no partitions, so the empty table is left out.
+ val workerRevivesSection: Seq[Node] =
+ if (reviveRows.isEmpty) Nil
+ else {
+ <span class="collapse-aggregated-celebornWorkerRevives collapse-table"
+ onClick="collapseTable('collapse-aggregated-celebornWorkerRevives',
+ 'aggregated-celebornWorkerRevives')">
+ <h4>
+ <span class="collapse-table-arrow arrow-closed"></span>
+ <a>Worker Revives</a>
+ </h4>
+ </span> ++
+ <div class="aggregated-celebornWorkerRevives collapsible-table
collapsed">
+ {workerRevivesTable}
+ <p>
+ Counts are revived partitions, not individual pushes: each
revive of a partition
+ counts once, however many map tasks hit the split or push
failure. Splits are
+ counted against the primary worker, even when its replica
triggered the split.
+ Replica push failures are counted against the replica worker.
+ </p>
+ </div>
+ }
+
val buildInfoTable = UIUtils.listingTable(
propertyHeader,
propertyRow,
@@ -210,6 +280,7 @@ private[celeborn] class CelebornShufflePage(parent:
CelebornUITab)
<div class="aggregated-celebornWorkerSlots collapsible-table
collapsed">
{workerSlotsTable}
</div>
+ {workerRevivesSection}
</span>
UIUtils.headerSparkPage(request, "Celeborn Shuffle", content, parent)
@@ -241,6 +312,19 @@ private[celeborn] class CelebornShufflePage(parent:
CelebornUITab)
<td>{row._3}</td>
</tr>
+ private def workerReviveRow(row: WorkerReviveRow): Seq[Node] = {
+ val causes = row.failureCauses.map { case (cause, n) =>
+ <div class="text-nowrap">{s"$cause: $n"}</div>
+ }
+ <tr>
+ <td>{row.worker}</td>
+ <td>{row.softSplits}</td>
+ <td>{row.hardSplits}</td>
+ <td>{row.pushFailures}</td>
+ <td>{causes}</td>
+ </tr>
+ }
+
private def propertyRow(kv: (String, String)): Seq[Node] =
<tr>
<td>{kv._1}</td>
diff --git
a/client-spark/spark-3-ui/src/test/scala/org/apache/spark/shuffle/celeborn/CelebornListenerSuite.scala
b/client-spark/spark-3-ui/src/test/scala/org/apache/spark/shuffle/celeborn/CelebornListenerSuite.scala
index f7192039f1..83d56f9b97 100644
---
a/client-spark/spark-3-ui/src/test/scala/org/apache/spark/shuffle/celeborn/CelebornListenerSuite.scala
+++
b/client-spark/spark-3-ui/src/test/scala/org/apache/spark/shuffle/celeborn/CelebornListenerSuite.scala
@@ -18,6 +18,7 @@
package org.apache.spark.shuffle.celeborn
import com.fasterxml.jackson.databind.ObjectMapper
+import com.fasterxml.jackson.module.scala.DefaultScalaModule
import org.apache.spark.{SparkConf, Success, TaskEndReason, TaskKilled,
TaskState}
import org.apache.spark.executor.TaskMetrics
import org.apache.spark.internal.config.Status.{ASYNC_TRACKING_ENABLED,
MAX_RETAINED_STAGES}
@@ -365,4 +366,82 @@ class CelebornListenerSuite {
assertEquals(workerSlots, restored)
assertEquals(4, restored.workerSlots.values.sum)
}
+
+ @Test
+ def workerRevivesAggregatedFromPostedEvents(): Unit = {
+ val store = new InMemoryStore()
+ val statusStore = new CelebornStatusStore(store)
+ val listener = new CelebornListener(store, new SparkConf())
+
+ listener.onOtherEvent(CelebornPartitionReviveEvent(
+ 3,
+ 1,
+ Map("w1" -> Map("SOFT_SPLIT" -> 2), "w2" ->
Map("PUSH_DATA_TIMEOUT_REPLICA" -> 1))))
+ listener.onOtherEvent(CelebornPartitionReviveEvent(
+ 4,
+ 2,
+ Map("w1" -> Map("SOFT_SPLIT" -> 1, "HARD_SPLIT" -> 1))))
+ listener.flush()
+
+ assertEquals(
+ WorkerRevivesUIData(Map(
+ "w1" -> Map("SOFT_SPLIT" -> 3, "HARD_SPLIT" -> 1),
+ "w2" -> Map("PUSH_DATA_TIMEOUT_REPLICA" -> 1))),
+ statusStore.workerRevives().get)
+ }
+
+ @Test
+ def workerRevivesPersistedWithoutFlushAfterJobEnd(): Unit = {
+ val store = new InMemoryStore()
+ val statusStore = new CelebornStatusStore(store)
+ val listener = new CelebornListener(store, new SparkConf())
+
+ listener.onOtherEvent(CelebornPartitionReviveReportingEvent())
+ listener.onJobEnd(SparkListenerJobEnd(0, 0L, JobSucceeded))
+ // A revive finishing right after the job's flush, with the application
then staying idle.
+ listener.onOtherEvent(CelebornPartitionReviveEvent(3, 1, Map("w1" ->
Map("SOFT_SPLIT" -> 1))))
+
+ assertEquals(
+ Some(WorkerRevivesUIData(Map("w1" -> Map("SOFT_SPLIT" -> 1)))),
+ statusStore.workerRevives())
+ }
+
+ @Test
+ def partitionReviveEventJsonRoundTrip(): Unit = {
+ // Same mapper setup as Spark's JsonProtocol for events it does not know.
+ val mapper = new ObjectMapper().registerModule(DefaultScalaModule)
+ val event = CelebornPartitionReviveEvent(3, 1, Map("w1" ->
Map("HARD_SPLIT" -> 2)))
+ val restored = mapper
+ .readValue(mapper.writeValueAsString(event), classOf[SparkListenerEvent])
+ .asInstanceOf[CelebornPartitionReviveEvent]
+
+ val store = new InMemoryStore()
+ val listener = new CelebornListener(store, new SparkConf())
+ listener.onOtherEvent(restored)
+ listener.flush()
+ assertEquals(
+ WorkerRevivesUIData(Map("w1" -> Map("HARD_SPLIT" -> 2))),
+ new CelebornStatusStore(store).workerRevives().get)
+ }
+
+ @Test
+ def workerRevivesKVStoreRoundTrip(): Unit = {
+ val serializer = new KVStoreScalaSerializer()
+ val revives = WorkerRevivesUIData(Map(
+ "w1" -> Map("SOFT_SPLIT" -> 3, "HARD_SPLIT" -> 1),
+ "w2" -> Map("PUSH_DATA_TIMEOUT_REPLICA" -> 1)))
+
+ val restored =
+ serializer.deserialize(serializer.serialize(revives),
classOf[WorkerRevivesUIData])
+ assertEquals(revives, restored)
+ assertEquals(4, restored.workerRevives("w1").values.sum)
+
+ // A persisted empty record must still distinguish zero from unavailable
on replay.
+ val empty = WorkerRevivesUIData(Map.empty)
+ val store = new InMemoryStore()
+ val statusStore = new CelebornStatusStore(store)
+ assertEquals(None, statusStore.workerRevives())
+ store.write(serializer.deserialize(serializer.serialize(empty),
classOf[WorkerRevivesUIData]))
+ assertEquals(Some(empty), statusStore.workerRevives())
+ }
}
diff --git
a/client-spark/spark-3-ui/src/test/scala/org/apache/spark/shuffle/celeborn/CelebornPluginSuite.scala
b/client-spark/spark-3-ui/src/test/scala/org/apache/spark/shuffle/celeborn/CelebornPluginSuite.scala
index 07f20578a1..ced2e9ed43 100644
---
a/client-spark/spark-3-ui/src/test/scala/org/apache/spark/shuffle/celeborn/CelebornPluginSuite.scala
+++
b/client-spark/spark-3-ui/src/test/scala/org/apache/spark/shuffle/celeborn/CelebornPluginSuite.scala
@@ -17,17 +17,110 @@
*/
package org.apache.spark.shuffle.celeborn
+import java.lang.reflect.{InvocationHandler, Method, Proxy}
+
import scala.collection.JavaConverters._
-import org.apache.spark.{SparkConf, SparkContext, SparkEnv}
-import org.junit.Assert.assertEquals
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.fasterxml.jackson.module.scala.DefaultScalaModule
+import org.apache.spark.{SecurityManager, SparkConf, SparkContext, SparkEnv}
+import org.apache.spark.scheduler.{JobSucceeded, ReplayListenerBus,
SparkListenerEnvironmentUpdate, SparkListenerEvent, SparkListenerJobEnd}
+import org.apache.spark.shuffle.celeborn.ui.CelebornUITab
+import
org.apache.spark.shuffle.celeborn.ui.SparkServletBridge.HttpServletRequest
+import org.apache.spark.status.ElementTrackingStore
+import org.apache.spark.ui.SparkUI
+import org.junit.Assert.{assertEquals, assertFalse, assertTrue}
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
+import org.apache.celeborn.common.protocol.message.StatusCode
+
@RunWith(classOf[JUnit4])
class CelebornPluginSuite {
+ // Render without binding an HTTP server: Spark 3 and 4 use different Jersey
versions.
+ private def createUI(sc: SparkContext): SparkUI = SparkUI.create(
+ Some(sc),
+ sc.statusStore,
+ sc.conf,
+ new SecurityManager(sc.conf),
+ sc.appName,
+ "",
+ System.currentTimeMillis())
+
+ private def page(ui: SparkUI): String = {
+ val request = Proxy.newProxyInstance(
+ getClass.getClassLoader,
+ Array(classOf[HttpServletRequest]),
+ new InvocationHandler {
+ override def invoke(proxy: Any, method: Method, args: Array[AnyRef]):
AnyRef =
+ method.getName match {
+ case "getParameterMap" => java.util.Collections.emptyMap[String,
Array[String]]()
+ case _ => null
+ }
+ }).asInstanceOf[HttpServletRequest]
+ ui.getTabs.find(_.prefix ==
"celeborn").get.pages.head.render(request).mkString
+ }
+
+ private def reviveSummary(html: String): String =
+ """(?s)<strong>Revived Partitions: </strong>\s*([^<]+)""".r
+ .findFirstMatchIn(html).get.group(1).trim
+
+ private def hasWorkerRevives(html: String): Boolean =
html.contains("<a>Worker Revives</a>")
+
+ @Test
+ def historyServerDistinguishesUnavailableRevivesFromZero(): Unit = {
+ val conf = new SparkConf()
+ .setMaster("local")
+ .setAppName("CelebornPluginSuite")
+ .set("spark.ui.enabled", "false")
+ val sc = new SparkContext(conf)
+ try {
+ val historyPlugin = new CelebornHistoryServerPlugin()
+ val listener = historyPlugin.createListeners(
+ conf,
+ sc.statusStore.store.asInstanceOf[ElementTrackingStore]).head
+ .asInstanceOf[CelebornListener]
+ val mapper = new ObjectMapper().registerModule(DefaultScalaModule)
+ val replayBus = new ReplayListenerBus()
+ replayBus.addListener(listener)
+ def replay(event: SparkListenerEvent): Unit = {
+ assertTrue(replayBus.replay(
+ Iterator(mapper.writeValueAsString(event)),
+ "revive-events",
+ false,
+ _ => true))
+ listener.flush()
+ }
+
+ listener.onEnvironmentUpdate(SparkListenerEnvironmentUpdate(Map(
+ "Spark Properties" -> Seq("spark.plugins" ->
classOf[CelebornPlugin].getName))))
+ replay(CelebornShuffleAssignmentEvent(3, 1, Map("w1" -> 2)))
+ val ui = createUI(sc)
+ new CelebornHistoryServerPlugin().setupUI(ui)
+
+ def assertRevives(summary: String, tableShown: Boolean): Unit = {
+ val html = page(ui)
+ assertEquals(summary, reviveSummary(html))
+ assertEquals(tableShown, hasWorkerRevives(html))
+ }
+
+ // Older clients reported assignments, but did not record revive metrics.
+ assertRevives("N/A", tableShown = false)
+
+ replay(CelebornPartitionReviveReportingEvent())
+ assertRevives("Soft Split: 0 | Hard Split: 0 | Push Failure: 0",
tableShown = false)
+
+ replay(CelebornPartitionReviveEvent(3, 1, Map("w1" -> Map("HARD_SPLIT"
-> 2))))
+ // Replaying a marker again must not reset the recorded counts.
+ replay(CelebornPartitionReviveReportingEvent())
+ assertRevives("Soft Split: 0 | Hard Split: 2 | Push Failure: 0",
tableShown = true)
+ } finally {
+ sc.stop()
+ }
+ }
+
@Test
def shuffleAssignmentsReportedThroughSparkShuffleManager(): Unit = {
val conf = new SparkConf()
@@ -50,4 +143,64 @@ class CelebornPluginSuite {
sc.stop()
}
}
+
+ @Test
+ def partitionRevivesReportedThroughSparkShuffleManager(): Unit = {
+ val conf = new SparkConf()
+ .setMaster("local")
+ .setAppName("CelebornPluginSuite")
+ .set("spark.plugins", classOf[CelebornPlugin].getName)
+ .set("spark.shuffle.manager", classOf[SparkShuffleManager].getName)
+ .set("spark.ui.enabled", "false")
+ val sc = new SparkContext(conf)
+ try {
+ sc.listenerBus.waitUntilEmpty()
+ assertEquals(
+ Some(WorkerRevivesUIData(Map.empty)),
+ new CelebornStatusStore(sc.statusStore.store).workerRevives())
+ val ui = createUI(sc)
+ new CelebornUITab(new CelebornStatusStore(sc.statusStore.store), ui)
+ val emptyHtml = page(ui)
+ assertEquals("Soft Split: 0 | Hard Split: 0 | Push Failure: 0",
reviveSummary(emptyHtml))
+ assertFalse(hasWorkerRevives(emptyHtml))
+
+ val listener =
+
SparkEnv.get.shuffleManager.asInstanceOf[SparkShuffleManager].getPartitionReviveListener
+ val causes = Map[StatusCode, Integer](StatusCode.HARD_SPLIT -> 2).asJava
+ listener.onPartitionsRevived(3, 1, Map("w1" -> causes).asJava)
+ sc.listenerBus.post(SparkListenerJobEnd(0, System.currentTimeMillis(),
JobSucceeded))
+ sc.listenerBus.waitUntilEmpty()
+
+ assertEquals(
+ Some(WorkerRevivesUIData(Map("w1" -> Map("HARD_SPLIT" -> 2)))),
+ new CelebornStatusStore(sc.statusStore.store).workerRevives())
+ val html = page(ui)
+ assertEquals("Soft Split: 0 | Hard Split: 2 | Push Failure: 0",
reviveSummary(html))
+ assertTrue(hasWorkerRevives(html))
+ assertTrue(html.contains("Hard Split (Primary)"))
+ val note = html.replaceAll("\\s+", " ")
+ assertTrue(note.contains("Counts are revived partitions, not individual
pushes"))
+ assertTrue(note.contains(
+ "Splits are counted against the primary worker, even when its replica
triggered the split."))
+ } finally {
+ sc.stop()
+ }
+ }
+
+ @Test
+ def unsupportedShuffleManagerDoesNotReportRevives(): Unit = {
+ val conf = new SparkConf()
+ .setMaster("local")
+ .setAppName("CelebornPluginSuite")
+ .set("spark.plugins", classOf[CelebornPlugin].getName)
+ .set("spark.shuffle.manager", "sort")
+ .set("spark.ui.enabled", "false")
+ val sc = new SparkContext(conf)
+ try {
+ sc.listenerBus.waitUntilEmpty()
+ assertEquals(None, new
CelebornStatusStore(sc.statusStore.store).workerRevives())
+ } finally {
+ sc.stop()
+ }
+ }
}
diff --git
a/client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn/SparkShuffleManager.java
b/client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn/SparkShuffleManager.java
index 1103355b8a..74f4ec44f5 100644
---
a/client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn/SparkShuffleManager.java
+++
b/client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn/SparkShuffleManager.java
@@ -36,6 +36,7 @@ import org.slf4j.LoggerFactory;
import org.apache.celeborn.client.LifecycleManager;
import org.apache.celeborn.client.ShuffleClient;
+import org.apache.celeborn.client.listener.PartitionReviveListener;
import org.apache.celeborn.client.listener.ShuffleAssignmentListener;
import org.apache.celeborn.client.security.CryptoHandler;
import org.apache.celeborn.common.CelebornConf;
@@ -101,6 +102,7 @@ public class SparkShuffleManager implements ShuffleManager {
private LifecycleManager lifecycleManager;
private ShuffleAssignmentListener shuffleAssignmentListener;
+ private PartitionReviveListener partitionReviveListener;
private ShuffleClient shuffleClient;
private volatile SortShuffleManager _sortShuffleManager;
private final ConcurrentHashMap.KeySetView<Integer, Boolean> sortShuffleIds =
@@ -197,6 +199,9 @@ public class SparkShuffleManager implements ShuffleManager {
if (shuffleAssignmentListener != null) {
lifecycleManager.registerShuffleAssignmentListener(shuffleAssignmentListener);
}
+ if (partitionReviveListener != null) {
+
lifecycleManager.registerPartitionReviveListener(partitionReviveListener);
+ }
// Register only when the UI plugin is opted in, otherwise every map
task
// posts an event nobody consumes and each one flushes the event log.
if (SparkUtils.isCelebornPluginEnabled(conf)) {
@@ -576,6 +581,16 @@ public class SparkShuffleManager implements ShuffleManager
{
return shuffleAssignmentListener;
}
+ /** Registers a listener for the LifecycleManager, which is created on the
first shuffle. */
+ public synchronized void
registerPartitionReviveListener(PartitionReviveListener listener) {
+ partitionReviveListener = listener;
+ }
+
+ // for testing
+ public synchronized PartitionReviveListener getPartitionReviveListener() {
+ return partitionReviveListener;
+ }
+
// for testing
public LifecycleManager getLifecycleManager() {
return this.lifecycleManager;
diff --git
a/client/src/main/java/org/apache/celeborn/client/listener/PartitionReviveListener.java
b/client/src/main/java/org/apache/celeborn/client/listener/PartitionReviveListener.java
new file mode 100644
index 0000000000..2d48aecbb2
--- /dev/null
+++
b/client/src/main/java/org/apache/celeborn/client/listener/PartitionReviveListener.java
@@ -0,0 +1,41 @@
+/*
+ * 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.celeborn.client.listener;
+
+import java.util.Map;
+
+import org.apache.celeborn.common.protocol.message.StatusCode;
+
+/** The Listener about the partitions revived after partition splits or push
failures. */
+public interface PartitionReviveListener {
+
+ /**
+ * Notifies the partitions that the LifecycleManager moved to new locations.
A partition is
+ * reported once per revive, however many map tasks requested it, with the
cause of one of those
+ * requests. Revives that fail to reserve new slots are not reported.
+ *
+ * @param shuffleId the Celeborn shuffle id
+ * @param appShuffleId the application shuffle id, which differs on stage
rerun
+ * @param workerRevives revived partitions by worker unique id and revive
cause. Replica push
+ * failures count against the replica worker, other causes against the
primary worker. This
+ * includes splits triggered by the replica, as the primary forwards the
replica's split
+ * status unchanged.
+ */
+ void onPartitionsRevived(
+ int shuffleId, int appShuffleId, Map<String, Map<StatusCode, Integer>>
workerRevives);
+}
diff --git
a/client/src/main/scala/org/apache/celeborn/client/ChangePartitionManager.scala
b/client/src/main/scala/org/apache/celeborn/client/ChangePartitionManager.scala
index ec843e8f54..669284111b 100644
---
a/client/src/main/scala/org/apache/celeborn/client/ChangePartitionManager.scala
+++
b/client/src/main/scala/org/apache/celeborn/client/ChangePartitionManager.scala
@@ -350,6 +350,7 @@ class ChangePartitionManager(
s"shuffle $shuffleId, succeed partitions: " +
s"$changes.")
}
+ lifecycleManager.reportPartitionRevives(shuffleId, changePartitions)
replySuccess(newPrimaryLocations.toArray)
}
diff --git
a/client/src/main/scala/org/apache/celeborn/client/LifecycleManager.scala
b/client/src/main/scala/org/apache/celeborn/client/LifecycleManager.scala
index 005806a510..b51a5cdbbd 100644
--- a/client/src/main/scala/org/apache/celeborn/client/LifecycleManager.scala
+++ b/client/src/main/scala/org/apache/celeborn/client/LifecycleManager.scala
@@ -39,7 +39,7 @@ import com.google.common.annotations.VisibleForTesting
import com.google.common.cache.{Cache, CacheBuilder}
import org.apache.celeborn.client.LifecycleManager.{ShuffleAllocatedWorkers,
ShuffleFailedWorkers}
-import org.apache.celeborn.client.listener.{MapperEndCallback,
ShuffleAssignmentListener, WorkerStatusListener}
+import org.apache.celeborn.client.listener.{MapperEndCallback,
PartitionReviveListener, ShuffleAssignmentListener, WorkerStatusListener}
import org.apache.celeborn.common.{CelebornConf, CommitMetadata}
import org.apache.celeborn.common.CelebornConf.ACTIVE_STORAGE_TYPES
import org.apache.celeborn.common.client.{ApplicationInfoProvider,
MasterClient}
@@ -74,6 +74,16 @@ object LifecycleManager {
type ShuffleAllocatedWorkers =
ConcurrentHashMap[Int, ConcurrentHashMap[String,
ShufflePartitionLocationInfo]]
type ShuffleFailedWorkers = ConcurrentHashMap[WorkerInfo, (StatusCode, Long)]
+
+ // Push failures caused by the replica, which count against the replica
worker.
+ private val replicaReviveCauses = Set(
+ StatusCode.PUSH_DATA_WRITE_FAIL_REPLICA,
+ StatusCode.PUSH_DATA_CREATE_CONNECTION_FAIL_REPLICA,
+ StatusCode.PUSH_DATA_CONNECTION_EXCEPTION_REPLICA,
+ StatusCode.PUSH_DATA_TIMEOUT_REPLICA,
+ StatusCode.PUSH_DATA_FAIL_NON_CRITICAL_CAUSE_REPLICA,
+ StatusCode.PUSH_DATA_REPLICA_WORKER_EXCLUDED,
+ StatusCode.REPLICATE_DATA_FAILED)
}
class LifecycleManager(val appUniqueId: String, val conf: CelebornConf)
extends RpcEndpoint
@@ -974,6 +984,40 @@ class LifecycleManager(val appUniqueId: String, val conf:
CelebornConf) extends
}
}
+ private[client] def reportPartitionRevives(
+ shuffleId: Int,
+ requests: Array[ChangePartitionRequest]): Unit = {
+ partitionReviveListener.foreach { listener =>
+ val workerRevives = new util.HashMap[String, util.Map[StatusCode,
Integer]]()
+ requests.foreach { request =>
+ // Requests without a cause or an old location do not come from Revive.
+ for (cause <- request.causes; oldPartition <-
Option(request.oldPartition)) {
+ val location =
+ if (LifecycleManager.replicaReviveCauses.contains(cause) &&
oldPartition.hasPeer) {
+ oldPartition.getPeer
+ } else {
+ oldPartition
+ }
+ val causes = workerRevives.computeIfAbsent(
+ location.getWorker.toUniqueId,
+ _ => new util.HashMap[StatusCode, Integer]())
+ causes.put(cause, causes.getOrDefault(cause, 0) + 1)
+ }
+ }
+ if (!workerRevives.isEmpty) {
+ try {
+ listener.onPartitionsRevived(
+ shuffleId,
+ celebornShuffleIdToAppShuffleIdMap.getOrDefault(shuffleId,
shuffleId),
+ workerRevives)
+ } catch {
+ case NonFatal(e) =>
+ logWarning(s"Failed to report the partition revives of shuffle
$shuffleId.", e)
+ }
+ }
+ }
+ }
+
private def handleRevive(
context: RpcCallContext,
shuffleId: Int,
@@ -2324,6 +2368,11 @@ class LifecycleManager(val appUniqueId: String, val
conf: CelebornConf) extends
shuffleAssignmentListener = Some(listener)
}
+ @volatile private var partitionReviveListener:
Option[PartitionReviveListener] = None
+ def registerPartitionReviveListener(listener: PartitionReviveListener): Unit
= {
+ partitionReviveListener = Some(listener)
+ }
+
// Initialize at the end of LifecycleManager construction.
initialize()
diff --git
a/tests/spark-it/src/test/scala/org/apache/celeborn/tests/client/LifecycleManagerSuite.scala
b/tests/spark-it/src/test/scala/org/apache/celeborn/tests/client/LifecycleManagerSuite.scala
index 75892d70c2..e0e2b742e0 100644
---
a/tests/spark-it/src/test/scala/org/apache/celeborn/tests/client/LifecycleManagerSuite.scala
+++
b/tests/spark-it/src/test/scala/org/apache/celeborn/tests/client/LifecycleManagerSuite.scala
@@ -29,7 +29,9 @@ import org.scalatest.time.SpanSugar.convertIntToGrainOfTime
import org.apache.celeborn.client.{LifecycleManager, WithShuffleClientSuite}
import org.apache.celeborn.common.CelebornConf
import org.apache.celeborn.common.identity.UserIdentifier
-import
org.apache.celeborn.common.protocol.message.ControlMessages.MapperMetrics
+import org.apache.celeborn.common.network.protocol.SerdeVersion
+import org.apache.celeborn.common.protocol.{PartitionLocation, ReviveRequest}
+import
org.apache.celeborn.common.protocol.message.ControlMessages.{ChangeLocationResponse,
MapperMetrics, Revive}
import org.apache.celeborn.common.protocol.message.StatusCode
import org.apache.celeborn.service.deploy.MiniClusterFeature
@@ -156,6 +158,55 @@ class LifecycleManagerSuite extends WithShuffleClientSuite
with MiniClusterFeatu
assert(workerSlots.keySet.subsetOf(workerInfos.keySet.map(_.workerInfo.toUniqueId)))
}
+ test("report revived partitions by worker and revive cause") {
+ prepareService()
+ val reported = new ConcurrentLinkedQueue[(Int, Int, Map[String,
Map[StatusCode, Int]])]()
+ lifecycleManager.registerPartitionReviveListener { (shuffleId,
appShuffleId, workerRevives) =>
+ val revives = workerRevives.asScala.map { case (worker, causes) =>
+ worker -> causes.asScala.map { case (cause, n) => cause -> n.intValue
}.toMap
+ }.toMap
+ reported.add((shuffleId, appShuffleId, revives))
+ }
+ val shuffleId = nextShuffleId
+ val locations = shuffleClient.getPartitionLocation(shuffleId, 2, 3)
+ val (loc0, loc1, loc2) = (locations.get(0), locations.get(1),
locations.get(2))
+ assert(loc1.hasPeer)
+
+ def revive(mapId: Int, loc: PartitionLocation, cause: StatusCode):
StatusCode = {
+ val request = new ReviveRequest(shuffleId, mapId, 0, loc.getId,
loc.getEpoch, loc, cause)
+ lifecycleManager.self.askSync[ChangeLocationResponse](Revive(
+ shuffleId,
+ util.Arrays.asList[Integer](mapId),
+ util.Arrays.asList(request),
+ SerdeVersion.V1)).newLocs.get(loc.getId)._1
+ }
+ revive(0, loc0, StatusCode.HARD_SPLIT)
+ revive(0, loc1, StatusCode.PUSH_DATA_TIMEOUT_REPLICA)
+ // Another map task hits the same hard split, which was already revived.
+ revive(1, loc0, StatusCode.HARD_SPLIT)
+
+ // Reported before the reply.
+ assert(reported.asScala.forall { case (id, appId, _) => id == shuffleId &&
appId == shuffleId })
+ val revives = reported.asScala.toSeq.flatMap(_._3.toSeq.flatMap { case
(worker, causes) =>
+ causes.toSeq.map { case (cause, n) => (worker, cause, n) }
+ })
+ assert(revives.map(_._3).sum == 2)
+ assert(revives.contains((loc0.getWorker.toUniqueId, StatusCode.HARD_SPLIT,
1)))
+ // A replica push failure counts against the replica worker.
+ assert(revives.contains(
+ (loc1.getPeer.getWorker.toUniqueId,
StatusCode.PUSH_DATA_TIMEOUT_REPLICA, 1)))
+
+ // A revive that gets no new slots is not reported, as the client retries
it.
+ val failedWorkers = new LifecycleManager.ShuffleFailedWorkers()
+ workerInfos.keySet.foreach(worker =>
+ failedWorkers.put(
+ worker.workerInfo,
+ (StatusCode.PUSH_DATA_TIMEOUT_PRIMARY, System.currentTimeMillis())))
+ lifecycleManager.workerStatusTracker.recordWorkerFailure(failedWorkers)
+ assert(revive(0, loc2, StatusCode.HARD_SPLIT) ==
StatusCode.SLOT_NOT_AVAILABLE)
+ assert(reported.asScala.flatMap(_._3.values.flatMap(_.values)).sum == 2)
+ }
+
test("CELEBORN-2479: mapper end callback reports only the accepted attempt")
{
prepareService()
val numMappers = 8