You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "JiaqiWang18 (via GitHub)" <gi...@apache.org> on 2025/09/30 07:24:21 UTC
[PR] [Prototype][SPARK-53751][SDP] Explicit Checkpoint Location [spark]
JiaqiWang18 opened a new pull request, #52487:
URL: https://github.com/apache/spark/pull/52487
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
4. Be sure to keep the PR description updated to reflect all changes.
5. Please write your PR title to summarize what this PR proposes.
6. If possible, provide a concise example to reproduce the issue for a faster review.
7. If you want to add a new configuration, please read the guideline first for naming configurations in
'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
8. If you want to add or modify an error type or message, please read the guideline first in
'common/utils/src/main/resources/error/README.md'.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
Prototype PR for explicit checkpoint location that follows below format:
```
checkpoints-root/
├── myst/ # Table "myst"
│ ├── flow1/ # Flow to myst
│ │ ├── 0/ # Versioned checkpoint (0)
│ │ │ ├── commits/
│ │ │ ├── offsets/
│ │ │ └── sources/
│ │ └── 1/ # Versioned checkpoint (1)
│ │
│ └── flow2/ # Another flow to myst
│ ├── 0/ # Versioned checkpoint (0)
│ │ ├── commits/
│ │ ├── offsets/
│ │ └── sources/
│ └── 1/ # Versioned checkpoint (1)
│
└── mysink/ # Sink "mysink"
└── flowA/ # Flow to mysink
├── 0/ # Versioned checkpoint (0)
│ ├── commits/
│ ├── offsets/
│ └── sources/
└── 1/ # Versioned checkpoint (1)
```
Backend changes should be mostly finalized, all tests should pass.
For user-facing API, use a `spark.sql.pipelines.storageRoot` for now, as it is easier to revert.
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as new features, bug fixes, or other behavior changes. Documentation-only updates are not considered user-facing changes.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
If no, write 'No'.
-->
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
-->
### Was this patch authored or co-authored using generative AI tooling?
<!--
If generative AI tooling has been used in the process of authoring this patch, please include the
phrase: 'Generated-by: ' followed by the name of the tool and its version.
If no, write 'No'.
Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
-->
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-53751][SDP] Explicit Versioned Checkpoint Location [spark]
Posted by "sryza (via GitHub)" <gi...@apache.org>.
sryza commented on code in PR #52487:
URL: https://github.com/apache/spark/pull/52487#discussion_r2410641769
##########
sql/pipelines/src/main/scala/org/apache/spark/sql/pipelines/graph/State.scala:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.sql.pipelines.graph
+
+import org.apache.hadoop.fs.Path
+
+import org.apache.spark.internal.{Logging, LogKeys}
+import org.apache.spark.sql.AnalysisException
+
+object State extends Logging {
+
+ /**
+ * Find the graph elements to reset given the current update context.
+ * @param graph The graph to reset.
+ * @param env The current update context.
+ */
+ private def findElementsToReset(graph: DataflowGraph, env: PipelineUpdateContext): Seq[Input] = {
+ // If tableFilter is an instance of SomeTables, this is a refresh selection and all tables
+ // to reset should be resettable; Otherwise, this is a full graph update, and we reset all
+ // tables that are resettable.
+ val specifiedTablesToReset = {
+ val specifiedTables = env.fullRefreshTables.filter(graph.tables)
+ env.fullRefreshTables match {
+ case SomeTables(_) =>
+ specifiedTables.foreach { t =>
+ if (!PipelinesTableProperties.resetAllowed.fromMap(t.properties)) {
+ throw new AnalysisException(
+ "TABLE_NOT_RESETTABLE",
+ Map("tableName" -> t.displayName)
+ )
+ }
+ }
+ specifiedTables
+ case AllTables =>
+ specifiedTables.filter(t => PipelinesTableProperties.resetAllowed.fromMap(t.properties))
+ case NoTables => Seq.empty
+ }
+ }
+
+ specifiedTablesToReset.flatMap(t => t +: graph.resolvedFlowsTo(t.identifier))
+ }
+
+ /**
+ * Performs the following on targets selected for full refresh:
+ * - Clearing checkpoint data
+ * - Truncating table data
+ */
+ def reset(resolvedGraph: DataflowGraph, env: PipelineUpdateContext): Seq[Input] = {
+ val elementsToReset: Seq[Input] = findElementsToReset(resolvedGraph, env)
+
+ elementsToReset.foreach {
+ case f: ResolvedFlow => reset(f, env, resolvedGraph)
+ case _ => // tables is handled in materializeTables since hive metastore does not support
+ // removing all columns from a table.
+ }
+
+ elementsToReset
+ }
+
+ /**
+ * Resets the checkpoint for the given flow by creating the next consecutive directory. Also
+ * clears out batch append state if it exists.
Review Comment:
I don't think this clears out batch append state, right?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [Prototype][SPARK-53751][SDP] Explicit Checkpoint Location [spark]
Posted by "JiaqiWang18 (via GitHub)" <gi...@apache.org>.
JiaqiWang18 commented on code in PR #52487:
URL: https://github.com/apache/spark/pull/52487#discussion_r2390150741
##########
sql/pipelines/src/main/scala/org/apache/spark/sql/pipelines/graph/PipelineExecution.scala:
##########
@@ -46,6 +40,10 @@ class PipelineExecution(context: PipelineUpdateContext) {
def startPipeline(): Unit = synchronized {
// Initialize the graph.
val resolvedGraph = resolveGraph()
+ if (context.fullRefreshTables.nonEmpty) {
+ State.reset(resolvedGraph, context)
+ }
Review Comment:
with explicit storage location for checkpoint, we shouldn't need to create the tables and obtain its path beforehand. `resolvedGraph` should suffice.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-53751][SDP] Explicit Versioned Checkpoint Location [spark]
Posted by "JiaqiWang18 (via GitHub)" <gi...@apache.org>.
JiaqiWang18 commented on code in PR #52487:
URL: https://github.com/apache/spark/pull/52487#discussion_r2408997739
##########
sql/pipelines/src/test/scala/org/apache/spark/sql/pipelines/utils/StorageRootMixin.scala:
##########
@@ -0,0 +1,48 @@
+/*
+ * 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.sql.pipelines.utils
+
+
+import java.io.File
+import java.nio.file.Files
+
+import org.scalatest.{BeforeAndAfterEach, Suite}
+
+import org.apache.spark.util.Utils
+
+/**
+ * A mixin trait for tests that need a temporary directory as the storage root for pipelines.
+ * This trait creates a temporary directory before each test and deletes it after each test.
+ * The path to the temporary directory is available via the `storageRoot` variable.
+ */
+trait StorageRootMixin extends BeforeAndAfterEach { self: Suite =>
+
Review Comment:
extracting this out from `PipelineTest` so spark connect pipeline test can also extend this
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-53751][SDP] Explicit Versioned Checkpoint Location [spark]
Posted by "sryza (via GitHub)" <gi...@apache.org>.
sryza closed pull request #52487: [SPARK-53751][SDP] Explicit Versioned Checkpoint Location
URL: https://github.com/apache/spark/pull/52487
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [Prototype][SPARK-53751][SDP] Explicit Checkpoint Location [spark]
Posted by "JiaqiWang18 (via GitHub)" <gi...@apache.org>.
JiaqiWang18 commented on code in PR #52487:
URL: https://github.com/apache/spark/pull/52487#discussion_r2390153553
##########
sql/pipelines/src/main/scala/org/apache/spark/sql/pipelines/graph/DatasetManager.scala:
##########
@@ -288,8 +288,13 @@ object DatasetManager extends Logging {
}
// Wipe the data if we need to
- if ((isFullRefresh || !table.isStreamingTable) && existingTableOpt.isDefined) {
- context.spark.sql(s"TRUNCATE TABLE ${table.identifier.quotedString}")
+ if (existingTableOpt.isDefined) {
+ (isFullRefresh, table.isStreamingTable) match {
+ case (true, _) => // Already performed reset for full refresh mv/st - no-op
+ case (false, true) => // Incremental refresh of a st - no-op
+ case (false, false) => // Incremental refresh of a mv - truncate
+ context.spark.sql(s"TRUNCATE TABLE ${table.identifier.quotedString}")
Review Comment:
this `match` is to avoid calling `TRUNCATE` twice for full refresh MVs
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-53751][SDP] Explicit Versioned Checkpoint Location [spark]
Posted by "JiaqiWang18 (via GitHub)" <gi...@apache.org>.
JiaqiWang18 commented on code in PR #52487:
URL: https://github.com/apache/spark/pull/52487#discussion_r2408994872
##########
sql/connect/server/src/test/scala/org/apache/spark/sql/connect/SparkConnectServerTest.scala:
##########
@@ -70,12 +70,12 @@ trait SparkConnectServerTest extends SharedSparkSession {
super.afterAll()
}
- override def beforeEach(): Unit = {
+ protected override def beforeEach(): Unit = {
super.beforeEach()
clearAllExecutions()
}
- override def afterEach(): Unit = {
+ protected override def afterEach(): Unit = {
Review Comment:
keep consistency with signature of `BeforeAndAfterEach ` and fix an inheritance error when introducing `StorageRootMixin`
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-53751][SDP] Explicit Versioned Checkpoint Location [spark]
Posted by "JiaqiWang18 (via GitHub)" <gi...@apache.org>.
JiaqiWang18 commented on code in PR #52487:
URL: https://github.com/apache/spark/pull/52487#discussion_r2411536814
##########
sql/pipelines/src/main/scala/org/apache/spark/sql/pipelines/graph/State.scala:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.sql.pipelines.graph
+
+import org.apache.hadoop.fs.Path
+
+import org.apache.spark.internal.{Logging, LogKeys}
+import org.apache.spark.sql.AnalysisException
+
+object State extends Logging {
+
+ /**
+ * Find the graph elements to reset given the current update context.
+ * @param graph The graph to reset.
+ * @param env The current update context.
+ */
+ private def findElementsToReset(graph: DataflowGraph, env: PipelineUpdateContext): Seq[Input] = {
+ // If tableFilter is an instance of SomeTables, this is a refresh selection and all tables
+ // to reset should be resettable; Otherwise, this is a full graph update, and we reset all
+ // tables that are resettable.
+ val specifiedTablesToReset = {
+ val specifiedTables = env.fullRefreshTables.filter(graph.tables)
+ env.fullRefreshTables match {
+ case SomeTables(_) =>
+ specifiedTables.foreach { t =>
+ if (!PipelinesTableProperties.resetAllowed.fromMap(t.properties)) {
+ throw new AnalysisException(
+ "TABLE_NOT_RESETTABLE",
+ Map("tableName" -> t.displayName)
+ )
+ }
+ }
+ specifiedTables
+ case AllTables =>
+ specifiedTables.filter(t => PipelinesTableProperties.resetAllowed.fromMap(t.properties))
+ case NoTables => Seq.empty
+ }
+ }
+
+ specifiedTablesToReset.flatMap(t => t +: graph.resolvedFlowsTo(t.identifier))
+ }
+
+ /**
+ * Performs the following on targets selected for full refresh:
+ * - Clearing checkpoint data
+ * - Truncating table data
+ */
+ def reset(resolvedGraph: DataflowGraph, env: PipelineUpdateContext): Seq[Input] = {
+ val elementsToReset: Seq[Input] = findElementsToReset(resolvedGraph, env)
+
+ elementsToReset.foreach {
+ case f: ResolvedFlow => reset(f, env, resolvedGraph)
+ case _ => // tables is handled in materializeTables since hive metastore does not support
+ // removing all columns from a table.
+ }
+
+ elementsToReset
+ }
+
+ /**
+ * Resets the checkpoint for the given flow by creating the next consecutive directory. Also
+ * clears out batch append state if it exists.
Review Comment:
yeah stale comment, let me remove
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-53751][SDP] Explicit Versioned Checkpoint Location [spark]
Posted by "JiaqiWang18 (via GitHub)" <gi...@apache.org>.
JiaqiWang18 commented on PR #52487:
URL: https://github.com/apache/spark/pull/52487#issuecomment-3375293597
@sryza diff is a bit large but tried to include only the necessary changes for checkpoints
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org