ericm-db commented on code in PR #60263:
URL: https://github.com/apache/spark/pull/60263#discussion_r4556053619


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/runtime/MicroBatchExecution.scala:
##########
@@ -466,6 +464,52 @@ class MicroBatchExecution(
     }
   }
 
+  /**
+   * Rejects source names that do not fit the source tracking of this run. 
Runs before any source is
+   * created, so that a rejected run leaves nothing behind in the checkpoint.
+   */
+  private def checkSourceNames(
+      enforceNamed: Boolean,
+      enforceNamedInCheckpoint: Option[Boolean]): Unit = {
+    val sources = StreamingSourceIdentifyingName.collectSources(analyzedPlan)
+    val namedSources = sources.map(_._2).filter(_.nameOpt.isDefined)
+    val unnamedSources = sources.zipWithIndex.collect {
+      case ((source, Unassigned), i) => s"Leaf position $i - $source"
+    }
+    def unnamedSourcesError: Throwable =
+      QueryCompilationErrors.unnamedStreamingSourcesWithEnforcementError(
+        unnamedSources.mkString("\n"))
+    val checkpointVersion = initialLatestOffsetSeq.map(_._2.version)
+    // Offset log VERSION_1 cannot track sources by name, so the config alone 
is rejected there.
+    checkpointVersion.filter(_ < OffsetSeqLog.VERSION_2).foreach { version =>
+      if 
(sparkSessionForStream.sessionState.conf.enableStreamingSourceEvolution) {
+        throw 
QueryCompilationErrors.cannotEnableSourceEvolutionOnExistingCheckpointError(version)
+      }
+    }
+    (enforceNamedInCheckpoint, checkpointVersion) match {
+      case (Some(false), Some(version)) if namedSources.nonEmpty =>
+        // A positional checkpoint cannot start tracking sources by name. 
Spark 4.2 ran the named
+        // sources of catalog tables by position, with their metadata in 
sources/<name>, and a
+        // checkpoint written that way keeps running as before.
+        val fileManager = CheckpointFileManager.create(
+          new Path(resolvedCheckpointRoot), 
sparkSession.sessionState.newHadoopConf())
+        val writtenUnderNames = namedSources.forall { name =>
+          fileManager.exists(new Path(
+            StreamingUtils.getMetadataPath(name, new AtomicLong(0L), 
resolvedCheckpointRoot)))
+        }
+        if (!writtenUnderNames) {
+          throw 
QueryCompilationErrors.cannotEnableSourceEvolutionOnExistingCheckpointError(version)

Review Comment:
   Reworded in e8d0ec360e4 after all: this PR is what starts raising it for v2 
checkpoints, so the text now says that the existing checkpoint, with offset log 
format version `<existingVersion>`, tracks streaming sources by position rather 
than by name. #60265 still rewrites it once naming a source no longer needs the 
config.
   



##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/runtime/MicroBatchExecution.scala:
##########
@@ -466,6 +464,52 @@ class MicroBatchExecution(
     }
   }
 
+  /**
+   * Rejects source names that do not fit the source tracking of this run. 
Runs before any source is
+   * created, so that a rejected run leaves nothing behind in the checkpoint.
+   */
+  private def checkSourceNames(
+      enforceNamed: Boolean,
+      enforceNamedInCheckpoint: Option[Boolean]): Unit = {
+    val sources = StreamingSourceIdentifyingName.collectSources(analyzedPlan)
+    val namedSources = sources.map(_._2).filter(_.nameOpt.isDefined)
+    val unnamedSources = sources.zipWithIndex.collect {
+      case ((source, Unassigned), i) => s"Leaf position $i - $source"
+    }
+    def unnamedSourcesError: Throwable =
+      QueryCompilationErrors.unnamedStreamingSourcesWithEnforcementError(
+        unnamedSources.mkString("\n"))
+    val checkpointVersion = initialLatestOffsetSeq.map(_._2.version)
+    // Offset log VERSION_1 cannot track sources by name, so the config alone 
is rejected there.
+    checkpointVersion.filter(_ < OffsetSeqLog.VERSION_2).foreach { version =>
+      if 
(sparkSessionForStream.sessionState.conf.enableStreamingSourceEvolution) {
+        throw 
QueryCompilationErrors.cannotEnableSourceEvolutionOnExistingCheckpointError(version)
+      }
+    }
+    (enforceNamedInCheckpoint, checkpointVersion) match {
+      case (Some(false), Some(version)) if namedSources.nonEmpty =>

Review Comment:
   Update: e8d0ec360e4 moves the `sources/<name>` exemption out of this PR into 
#60265 (SPARK-61311). Since SPARK-60270 it could be reached here only with the 
config on and an offset log v2 checkpoint; #60265 is where Spark 4.2 and 4.3 
checkpoints of named catalog tables become restartable without the config. This 
PR now rejects every positional checkpoint restarted with names, so the layout 
questions here, including connectors that never write `sources/<name>`, move 
with the exemption.
   



##########
sql/core/src/test/scala/org/apache/spark/sql/streaming/test/StreamingSourceEvolutionSuite.scala:
##########
@@ -530,6 +532,119 @@ class StreamingSourceEvolutionSuite extends StreamTest {
       s"Expected default value 'false' for missing config in V2, but got: 
$valueV2")
   }
 
+  // ================================
+  // Checkpoint Source Tracking Tests

Review Comment:
   Update: with the exemption moved to #60265 in e8d0ec360e4, tests 2 and 3 
move with it. The check for named and unnamed sources now runs before the 
checkpoint cases, and `positional checkpoint - restart with named and unnamed 
sources is rejected before creating sources` fails if it runs after them.
   



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