-
Notifications
You must be signed in to change notification settings - Fork 29.2k
[SPARK-56968][SS] Force offset log VERSION_2 when streaming source evolution is enabled #56015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ericm-db
wants to merge
5
commits into
apache:master
Choose a base branch
from
ericm-db:spark-source-evolution-offset-log-v2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0682b3a
[SPARK-56968][SS] Force offset log VERSION_2 when streaming source ev…
ericm-db d301b6c
[SPARK-56968][SS][FOLLOWUP] Extract CheckpointVersionManager helper f…
ericm-db 7e519dd
[SPARK-56968][SS][FOLLOWUP] Test that source evolution flag does not …
ericm-db c080404
[SPARK-56968][SS][FOLLOWUP] Reject enabling source evolution on an ex…
ericm-db 6588488
[SPARK-56968][SS][FOLLOWUP] Align CheckpointVersionManager structure …
ericm-db File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
...ala/org/apache/spark/sql/execution/streaming/checkpointing/CheckpointVersionManager.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| /* | ||
| * 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.execution.streaming.checkpointing | ||
|
|
||
| import org.apache.spark.internal.Logging | ||
| import org.apache.spark.sql.SparkSession | ||
| import org.apache.spark.sql.errors.QueryCompilationErrors | ||
| import org.apache.spark.sql.internal.SQLConf | ||
|
|
||
| /** | ||
| * Case class for managing the internal versioning for the streaming checkpoint. Versions are | ||
| * tracked per component (currently just the offset log; other components are managed elsewhere via | ||
| * dedicated configs). | ||
| */ | ||
| case class StreamingCheckpointVersion(offsetLogVersion: Int) { | ||
| override def toString: String = { | ||
| s"StreamingCheckpointVersion(offsetLogVersion: $offsetLogVersion)" | ||
| } | ||
| } | ||
|
|
||
| sealed trait CheckpointLogType | ||
| case object OffsetLogType extends CheckpointLogType | ||
|
|
||
| /** | ||
| * The `CheckpointVersionManager` is responsible for managing the versioning of the streaming | ||
| * checkpoint. It determines which version of each system-managed log format to use when starting | ||
| * a streaming query, and validates that the requested feature set is compatible with the existing | ||
| * checkpoint when restarting. | ||
| * | ||
| * Writer versions are typically used only while starting a new streaming query and are not | ||
| * intended to be exposed directly to users; once set, they are not intended to change for the | ||
| * lifetime of the query. | ||
| */ | ||
| object CheckpointVersionManager extends Logging { | ||
|
|
||
| // Streaming checkpoint writer version 1: base version supporting DataFrame-based streaming | ||
| // queries across the standard trigger types. | ||
| private val CHECKPOINT_VERSION_V1 = StreamingCheckpointVersion(OffsetSeqLog.VERSION_1) | ||
|
|
||
| // The current version of the streaming checkpoint. To bump this, define a new | ||
| // `StreamingCheckpointVersion` instance with the new per-component version numbers and update | ||
| // this constant. | ||
| private val CURRENT_VERSION = CHECKPOINT_VERSION_V1 | ||
|
|
||
| def getCurrentVersion(): StreamingCheckpointVersion = CURRENT_VERSION | ||
|
|
||
| /** | ||
| * Returns the offset log format version to use for a new streaming query. We take the max of: | ||
| * - the current default version | ||
| * - the minimum required version implied by enabled features (e.g. streaming source evolution | ||
| * requires [[OffsetSeqLog.VERSION_2]] for OffsetMap-based named source tracking) | ||
| * - the configured version (via [[SQLConf.STREAMING_OFFSET_LOG_FORMAT_VERSION]]) | ||
| * | ||
| * @param sparkSessionForStream the cloned `SparkSession` for the streaming query | ||
| */ | ||
| private def getOffsetLogVersion(sparkSessionForStream: SparkSession): Int = { | ||
| val currentDefaultVersion = getCurrentVersion().offsetLogVersion | ||
| val minRequiredVersion = getMinRequiredOffsetLogVersion(sparkSessionForStream) | ||
| val configuredVersion = sparkSessionForStream.sessionState.conf.streamingOffsetLogFormatVersion | ||
| val result = List[Int](currentDefaultVersion, minRequiredVersion, configuredVersion).max | ||
| logInfo(s"Retrieved offset log writer version=$result") | ||
| result | ||
| } | ||
|
|
||
| /** | ||
| * Minimum offset log format version required by the features enabled on this session. Streaming | ||
| * source evolution relies on the OffsetMap (sourceId -> offset) format, which is only available | ||
| * in [[OffsetSeqLog.VERSION_2]]. | ||
| */ | ||
| private def getMinRequiredOffsetLogVersion(sparkSessionForStream: SparkSession): Int = { | ||
| if (sparkSessionForStream.sessionState.conf.enableStreamingSourceEvolution) { | ||
| OffsetSeqLog.VERSION_2 | ||
| } else { | ||
| OffsetSeqLog.VERSION_1 | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Set the SparkSession configurations for the offset log format version. | ||
| */ | ||
| private def setSparkSessionConfigsForOffsetLog( | ||
| sparkSessionForStream: SparkSession, | ||
| offsetLogFormatVersion: Int): Unit = { | ||
| sparkSessionForStream.conf.set( | ||
| SQLConf.STREAMING_OFFSET_LOG_FORMAT_VERSION.key, offsetLogFormatVersion) | ||
| } | ||
|
|
||
| /** | ||
| * Returns the format version for the given log type. Reads any feature-driven minimums from the | ||
| * `sparkSessionForStream` config, which must be initialized before calling. | ||
| */ | ||
| def getFormatVersionFromSession( | ||
| sparkSessionForStream: SparkSession, | ||
| logType: CheckpointLogType): Int = { | ||
| logType match { | ||
| case OffsetLogType => getOffsetLogVersion(sparkSessionForStream) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Determines the offset log format version for this query run. For existing queries, reads from | ||
| * the last written offset log entry. For new queries, delegates to the session config (honoring | ||
| * any feature-driven minimums). | ||
| * | ||
| * Also validates that the session config is compatible with the existing checkpoint. Currently, | ||
| * enabling streaming source evolution on a checkpoint whose offset log is below VERSION_2 is | ||
| * rejected, since the OffsetMap-based named source tracking required by source evolution is not | ||
| * available in earlier versions. | ||
| */ | ||
| def resolveOffsetLogVersion( | ||
| sparkSessionForStream: SparkSession, | ||
| latestStartedBatch: Option[(Long, OffsetSeqBase)]): Int = { | ||
| latestStartedBatch match { | ||
| case Some((_, offsetSeq)) => | ||
| val existingVersion = offsetSeq.version | ||
| if (existingVersion < OffsetSeqLog.VERSION_2 && | ||
| sparkSessionForStream.sessionState.conf.enableStreamingSourceEvolution) { | ||
| throw QueryCompilationErrors.cannotEnableSourceEvolutionOnExistingCheckpointError( | ||
| existingVersion) | ||
| } | ||
| existingVersion | ||
| case None => | ||
| getFormatVersionFromSession(sparkSessionForStream, OffsetLogType) | ||
| } | ||
| } | ||
|
|
||
| def setFormatVersion( | ||
| sparkSessionForStream: SparkSession, | ||
| logType: CheckpointLogType, | ||
| version: Int): Unit = { | ||
| logType match { | ||
| case OffsetLogType => | ||
| setSparkSessionConfigsForOffsetLog(sparkSessionForStream, version) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to update any other tests that were setting both configs ?