cloud-fan commented on code in PR #58437:
URL: https://github.com/apache/spark/pull/58437#discussion_r4524206436


##########
core/src/main/scala/org/apache/spark/shuffle/ShuffleHandle.scala:
##########
@@ -25,4 +27,14 @@ import org.apache.spark.annotation.DeveloperApi
  * @param shuffleId ID of the shuffle
  */
 @DeveloperApi
-abstract class ShuffleHandle(val shuffleId: Int) extends Serializable {}
+abstract class ShuffleHandle(val shuffleId: Int) extends Serializable {
+  /**
+   * Whether this shuffle's output survives losing the executor or host that 
wrote it (e.g. on a
+   * remote shuffle service). If so, executor or worker loss keeps its map 
output registered.
+   *
+   * Overrides `ShuffleDriverComponents.supportsReliableStorage()` for this 
shuffle. Empty (the
+   * default) falls back to that flag, so with the flag on, worker removal and 
a map-output
+   * FetchFailed keep other shuffles' map output. A pipelined shuffle must 
leave it empty.

Review Comment:
   **Nit (P3):** "keep other shuffles' map output" fits only the FetchFailed 
case: with the flag on and an empty value, `handleWorkerRemoved` calls 
`removeOutputsOnHost(host, respectReliablyStored = true)`, which keeps this 
shuffle's map output as well and drops only push-merge results. The doc also 
does not say when Spark reads the value: `createShuffleMapStage` reads it once 
on the driver when it registers the shuffle, before any map output exists, and 
every later loss path and `TaskSetManager` use that recorded bit. A 
remote-shuffle client that decides to fall back to local disk only when a map 
task writes could return `Optional.of(true)` here and later write 
executor-local output that loss handling keeps registered. The wording in 
commit 6012875d7f0 described both loss paths accurately; restoring it and 
adding when the value is read would let an implementation be written from the 
doc alone.
   
   This extends an [existing 
discussion](https://github.com/apache/spark/pull/58437#discussion_r4505326112).
   
   See **Shared repair plan 1** in the review body.



##########
core/src/main/scala/org/apache/spark/scheduler/DAGScheduler.scala:
##########
@@ -4267,7 +4272,8 @@ private[spark] class DAGScheduler(
       fileLost: Boolean,
       hostToUnregisterOutputs: Option[String],
       maybeEpoch: Option[Long] = None,
-      ignoreShuffleFileLostEpoch: Boolean = false): Unit = {
+      ignoreShuffleFileLostEpoch: Boolean = false,
+      respectReliablyStored: Boolean = false): Unit = {

Review Comment:
   Thanks. The qualification you added to the @param fileLost text was dropped 
again by the latest comment-trim commit, so it once more says we presume all 
shuffle data for the executor is lost. Both callers pass respectReliablyStored 
= true, so reliably stored map output, apart from the failed shuffle on a 
map-output FetchFailed, is kept. Could you restore that qualification?
   
   <!-- SPARK_DEV_REVIEW_REPLY 
{"feedback_id":"inline:3968978586","thread_id":"inline:3968978586","verdict_sha256":"4d4408339a8f77a49c228858f7043527d93a383c331c4cf1cd94206a708af06a"}
 -->



##########
core/src/main/scala/org/apache/spark/scheduler/DAGScheduler.scala:
##########
@@ -4940,27 +4979,49 @@ private[spark] class DAGScheduler(
       clearCacheLocs()
     }
     if (fileLost) {
-      // When the fetch failure is for a merged shuffle chunk, 
ignoreShuffleFileLostEpoch is true
-      // and so all the files will be removed.
-      val remove = if (ignoreShuffleFileLostEpoch) {
-        true
-      } else if (!shuffleFileLostEpoch.contains(execId) ||
-        shuffleFileLostEpoch(execId) < currentEpoch) {
-        shuffleFileLostEpoch(execId) = currentEpoch
-        true
-      } else {
-        false
+      // A FetchFailed for a reliable shuffle may pass a rejecting executor 
fence once per epoch:
+      // executor loss kept that shuffle, so it must still be cleaned when 
proven gone.

Review Comment:
   **Nit (P3):** This explains the bypass only by executor loss, but a 
FetchFailed cleanup for another shuffle on the same executor also stamps 
`shuffleFileLostEpoch(execId)` and, with `respectReliablyStored = true`, keeps 
this reliable shuffle. For example, local shuffle L's FetchFailed at epoch 10 
cleans L, keeps reliable shuffle R, and sets the fence to 10 with no executor 
loss; R's FetchFailed at epoch 7 then gets through only by this bypass. Three 
of the new bypass tests set the fence exactly that way. A reader who trusts the 
comment could narrow the bypass to executor loss and break that recovery. 
Saying that an earlier cleanup at this fence, from executor loss or from 
another shuffle's FetchFailed, kept the shuffle would cover both cases.
   
   **Verification:**
   - **Inspection:** Confirm the comment's list of fence-stamping cleanups 
matches every caller of removeExecutorAndUnregisterOutputs that stamps the 
executor fence with respectReliablyStored set, including the FetchFailed path 
the existing bypass tests exercise.



##########
core/src/main/scala/org/apache/spark/scheduler/DAGScheduler.scala:
##########
@@ -4832,23 +4853,30 @@ private[spark] class DAGScheduler(
    * Responds to an executor being lost. This is called inside the event loop, 
so it assumes it can
    * modify the scheduler's internal state. Use executorLost() to post a loss 
event from outside.
    *
-   * We will also assume that we've lost all shuffle blocks associated with 
the executor if the
-   * executor serves its own blocks (i.e., we're not using an external shuffle 
service), or the
-   * entire Standalone worker is lost.
+   * We will also assume that we've lost all non-reliably-stored shuffle 
blocks associated with the
+   * executor if the executor serves its own blocks (i.e., we're not using an 
external shuffle
+   * service), or the entire Standalone worker is lost.
    */
   private[scheduler] def handleExecutorLost(
       execId: String,
       workerHost: Option[String]): Unit = {
     // if the cluster manager explicitly tells us that the entire worker was 
lost, then
     // we know to unregister shuffle output.  (Note that "worker" specifically 
refers to the process
     // from a Standalone cluster, where the shuffle service lives in the 
Worker.)
-    val fileLost = !sc.shuffleDriverComponents.supportsReliableStorage() &&
+    // Skip it if nothing is removable: the global flag is on, every 
registered shuffle is reliably
+    // stored, and no host was lost under push-based shuffle (its merge 
results must go).
+    // TODO: that host pass still bumps the epoch when the host held nothing.
+    val nothingRemovable = 
sc.shuffleDriverComponents.supportsReliableStorage() &&
+      !mapOutputTracker.hasUnreliablyStoredShuffle &&

Review Comment:
   **Nit (P3):** With `supportsReliableStorage()` true, this walk runs before 
the cheap terms. `hasUnreliablyStoredShuffle` visits every registered shuffle 
when all of them are reliable, yet with the external shuffle service on and no 
worker host `fileLost` ends up false whatever it returns, and with a worker 
host under push-based shuffle `nothingRemovable` is false whatever it returns. 
In those cases each executor loss now pays a walk over the shuffle registry on 
the DAG event loop that master did not. The cost is small, but checking 
`workerHost.isDefined || !externalShuffleServiceEnabled` and the push-based 
host case first gives the same `fileLost` for every input and leaves the walk 
only where its answer matters: a loss with no worker host while the external 
shuffle service is off, or a lost worker host without push-based shuffle.
   
   This extends existing discussions 
[1](https://github.com/apache/spark/pull/58437#issuecomment-6711788369), 
[2](https://github.com/apache/spark/pull/58437#discussion_r4505326103).
   
   **Verification:**
   - **Regression:** Under a globally reliable plugin with the external shuffle 
service on, deliver an executor loss without a worker host and assert that the 
tracker's unreliable-shuffle check is never called, that no cleanup runs, and 
that the map-output epoch is unchanged.
   - **Compatibility:** Under a globally reliable plugin with the external 
shuffle service off and one shuffle whose handle reports false, assert that 
executor loss still removes that shuffle's output on the executor while keeping 
the reliable shuffle's output, and that a worker-host loss under push-based 
shuffle still drops that host's merge results.



##########
core/src/main/scala/org/apache/spark/shuffle/ShuffleHandle.scala:
##########
@@ -25,4 +27,14 @@ import org.apache.spark.annotation.DeveloperApi
  * @param shuffleId ID of the shuffle
  */
 @DeveloperApi
-abstract class ShuffleHandle(val shuffleId: Int) extends Serializable {}
+abstract class ShuffleHandle(val shuffleId: Int) extends Serializable {
+  /**
+   * Whether this shuffle's output survives losing the executor or host that 
wrote it (e.g. on a
+   * remote shuffle service). If so, executor or worker loss keeps its map 
output registered.
+   *
+   * Overrides `ShuffleDriverComponents.supportsReliableStorage()` for this 
shuffle. Empty (the

Review Comment:
   **Nit (P3):** This promises that a present value overrides the global flag, 
but `SparkContext.executorHoldSupported` and the `reliableShuffleStorage` 
argument passed to `ExecutorAllocationManager` still read only 
`supportsReliableStorage()`. The deferral to #58687 and #59083 is agreed, but 
only the PR description and replies say so. A plugin author who returns 
`Optional.of(false)` for a local-disk fallback shuffle under a reliable plugin 
would expect executor hold and scale-down to protect that shuffle's executors, 
and nothing reminds a later change to update those consumers. A Scaladoc 
sentence naming the two retirement consumers as exceptions, with a TODO 
pointing at the follow-ups, would mark the gap until they land.
   
   This extends an [existing 
discussion](https://github.com/apache/spark/pull/58437#discussion_r4085168311).
   
   See **Shared repair plan 1** in the review body.



##########
core/src/main/scala/org/apache/spark/MapOutputTracker.scala:
##########
@@ -1045,19 +1103,73 @@ private[spark] class MapOutputTrackerMaster(
    * Removes all shuffle outputs associated with this host. Note that this 
will also remove
    * outputs which are served by an external shuffle server (if one exists).
    */
-  def removeOutputsOnHost(host: String): Unit = {
-    shuffleStatuses.valuesIterator.foreach { _.removeOutputsOnHost(host) }
-    incrementEpoch()
-  }
+  def removeOutputsOnHost(host: String): Unit =
+    removeOutputsOnHost(host, respectReliablyStored = false)
 
   /**
    * Removes all shuffle outputs associated with this executor. Note that this 
will also remove
    * outputs which are served by an external shuffle server (if one exists), 
as they are still
    * registered with this execId.
    */
-  def removeOutputsOnExecutor(execId: String): Unit = {
-    shuffleStatuses.valuesIterator.foreach { _.removeOutputsOnExecutor(execId) 
}
-    incrementEpoch()
+  def removeOutputsOnExecutor(execId: String): Unit =
+    removeOutputsOnExecutor(execId, respectReliablyStored = false)
+
+  /** Like `removeOutputsOnHost(host)`, but keeps reliably-stored map output 
if asked. */
+  def removeOutputsOnHost(host: String, respectReliablyStored: Boolean): 
CleanupOutcome =
+    removeOutputsOnHost(host, respectReliablyStored, None)
+
+  /** See `removeSelectively` for `failedShuffleId` and 
`restrictToFailedShuffle`. */
+  def removeOutputsOnHost(
+      host: String,
+      respectReliablyStored: Boolean,
+      failedShuffleId: Option[Int],
+      restrictToFailedShuffle: Boolean = false): CleanupOutcome = {
+    val outcome = removeSelectively(
+      respectReliablyStored, failedShuffleId, restrictToFailedShuffle)(
+      (status, respect) => status.removeOutputsOnHost(host, respect))
+    if (outcome.shouldBumpEpoch) incrementEpoch()
+    outcome
+  }
+
+  /** Like `removeOutputsOnExecutor(execId)`, but keeps reliably-stored map 
output if asked. */
+  def removeOutputsOnExecutor(execId: String, respectReliablyStored: Boolean): 
CleanupOutcome =
+    removeOutputsOnExecutor(execId, respectReliablyStored, None)
+
+  /** See `removeSelectively` for `failedShuffleId` and 
`restrictToFailedShuffle`. */
+  def removeOutputsOnExecutor(
+      execId: String,
+      respectReliablyStored: Boolean,
+      failedShuffleId: Option[Int],
+      restrictToFailedShuffle: Boolean = false): CleanupOutcome = {
+    val outcome = removeSelectively(
+      respectReliablyStored, failedShuffleId, restrictToFailedShuffle)(
+      (status, respect) => status.removeOutputsOnExecutor(execId, respect))
+    if (outcome.shouldBumpEpoch) incrementEpoch()
+    outcome
+  }
+
+  /**
+   * Applies `remove` to each shuffle and aggregates the results; the caller 
bumps the epoch.
+   * `failedShuffleId` is cleaned even if reliable; `restrictToFailedShuffle` 
touches only it.
+   */
+  private def removeSelectively(
+      respectReliablyStored: Boolean,
+      failedShuffleId: Option[Int],
+      restrictToFailedShuffle: Boolean = false)(
+      remove: (ShuffleStatus, Boolean) => ShuffleRemovalResult): 
CleanupOutcome = {
+    require(!restrictToFailedShuffle || failedShuffleId.isDefined,
+      "restrictToFailedShuffle requires a failedShuffleId to restrict to")
+    var metadataChanged = false
+    var preservedReliable = false
+    shuffleStatuses.foreach { case (shuffleId, status) =>

Review Comment:
   **Nit (P3):** On the restricted path, which only the reliable FetchFailed 
bypass takes, this loop still visits every registered shuffle, building a tuple 
per entry through the Scala wrapper, to touch the one whose id is 
`failedShuffleId`, which the `require` above already guarantees is defined. 
Bypasses are rare and the cost is small, but looking the status up by id gives 
the same `CleanupOutcome` and removes the walk; a shuffle unregistered 
concurrently is skipped either way.
   
   **Verification:**
   - **Behavior:** A restricted executor and host cleanup for a reliable failed 
shuffle removes that shuffle's output on the target, leaves a co-located 
shuffle's output intact, and advances the epoch.
   - **Behavior:** A restricted cleanup whose failed shuffle is no longer 
registered removes nothing, reports that it removed and kept nothing, and still 
advances the epoch as it does today.



##########
core/src/main/scala/org/apache/spark/scheduler/DAGScheduler.scala:
##########
@@ -4832,23 +4798,26 @@ private[spark] class DAGScheduler(
    * Responds to an executor being lost. This is called inside the event loop, 
so it assumes it can
    * modify the scheduler's internal state. Use executorLost() to post a loss 
event from outside.
    *
-   * We will also assume that we've lost all shuffle blocks associated with 
the executor if the
-   * executor serves its own blocks (i.e., we're not using an external shuffle 
service), or the
-   * entire Standalone worker is lost.
+   * We will also assume that we've lost the non-reliably-stored shuffle 
blocks associated with the
+   * executor if the executor serves its own blocks (i.e., we're not using an 
external shuffle
+   * service), or the entire Standalone worker is lost. Output marked reliably 
stored lives
+   * off-executor and is left registered.
    */
   private[scheduler] def handleExecutorLost(
       execId: String,
       workerHost: Option[String]): Unit = {
-    // if the cluster manager explicitly tells us that the entire worker was 
lost, then
-    // we know to unregister shuffle output.  (Note that "worker" specifically 
refers to the process
-    // from a Standalone cluster, where the shuffle service lives in the 
Worker.)
-    val fileLost = !sc.shuffleDriverComponents.supportsReliableStorage() &&
-      (workerHost.isDefined || !env.blockManager.externalShuffleServiceEnabled)
+    // Whether these outputs are candidates for removal at all; reliability is 
then honored per
+    // shuffle via respectReliablyStored below. workerHost.isDefined means the 
whole Standalone
+    // worker (which hosts the shuffle service) is gone.
+    val fileLost = workerHost.isDefined || 
!env.blockManager.externalShuffleServiceEnabled

Review Comment:
   Thanks. Under a globally reliable plugin with empty handles, executor loss 
now matches master, and so does host loss when push-based shuffle is off: no 
cleanup pass, no fence stamp, and no epoch bump. This review raises one small 
follow-up about the order of the checks in that condition.
   
   <!-- SPARK_DEV_REVIEW_REPLY 
{"feedback_id":"inline:4505326103","thread_id":"inline:4505326103","verdict_sha256":"4d4408339a8f77a49c228858f7043527d93a383c331c4cf1cd94206a708af06a"}
 -->



##########
core/src/main/scala/org/apache/spark/shuffle/ShuffleHandle.scala:
##########
@@ -25,4 +25,19 @@ import org.apache.spark.annotation.DeveloperApi
  * @param shuffleId ID of the shuffle
  */
 @DeveloperApi
-abstract class ShuffleHandle(val shuffleId: Int) extends Serializable {}
+abstract class ShuffleHandle(val shuffleId: Int) extends Serializable {
+  /**
+   * Whether this shuffle's output is stored reliably, off the executor that 
produced it (e.g. a
+   * remote shuffle service or distributed filesystem). When true, losing the 
executor or its host
+   * does not lose the output, so its map outputs are not unregistered on 
executor/worker loss.
+   *
+   * Applies only to materialized, map-output-tracked (blocking) shuffles. A 
pipelined shuffle is
+   * located through the streaming task-location registry, not map-status 
cleanup, so it cannot
+   * honor this flag; the scheduler rejects a non-`None` value on a pipelined 
dependency.
+   *
+   * Per-shuffle override of the app-global 
`ShuffleDriverComponents.supportsReliableStorage()`:
+   * `Some(value)` is authoritative for this shuffle; `None` (the default) 
means "no per-shuffle
+   * information", so the global flag is used and managers that don't set it 
keep legacy behavior.

Review Comment:
   Thanks, the Scaladoc now says that an empty value falls back to the global 
flag and names both changes. This review raises a small follow-up on that 
sentence's wording and on stating when Spark reads the value.
   
   <!-- SPARK_DEV_REVIEW_REPLY 
{"feedback_id":"inline:4505326112","thread_id":"inline:4505326112","verdict_sha256":"4d4408339a8f77a49c228858f7043527d93a383c331c4cf1cd94206a708af06a"}
 -->



-- 
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]


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

Reply via email to