[SPARK-54585][SS] Fix State Store rollback when thread is in interrupted state#53313
Closed
dylanwong250 wants to merge 4 commits intoapache:masterfrom
Closed
[SPARK-54585][SS] Fix State Store rollback when thread is in interrupted state#53313dylanwong250 wants to merge 4 commits intoapache:masterfrom
dylanwong250 wants to merge 4 commits intoapache:masterfrom
Conversation
micheal-o
approved these changes
Dec 9, 2025
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDB.scala
Outdated
Show resolved
Hide resolved
.../org/apache/spark/sql/execution/streaming/state/RocksDBCheckpointFailureInjectionSuite.scala
Outdated
Show resolved
Hide resolved
Contributor
Author
|
@micheal-o I made some changes to fix the root cause of the interrupted exception. It happens when the executor interrupts the task thread by setting its interrupt flag, and awaitResult() checks this flag before waiting, throwing InterruptedException immediately if set. PTAL. Thanks |
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDB.scala
Show resolved
Hide resolved
...a/org/apache/spark/sql/execution/streaming/checkpointing/ChecksumCheckpointFileManager.scala
Outdated
Show resolved
Hide resolved
...a/org/apache/spark/sql/execution/streaming/checkpointing/ChecksumCheckpointFileManager.scala
Outdated
Show resolved
Hide resolved
...a/org/apache/spark/sql/execution/streaming/checkpointing/ChecksumCheckpointFileManager.scala
Outdated
Show resolved
Hide resolved
anishshri-db
approved these changes
Dec 10, 2025
Contributor
anishshri-db
left a comment
There was a problem hiding this comment.
lgtm pending green CI
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What changes were proposed in this pull request?
Modifies
ChecksumCancellableFSDataOutputStream.cancel()to cancel both the main stream and checksum stream synchronously instead of using Futures with awaitResult.Moves
changelogWriter.foreach(_.abort())andchangelogWriter = Nonein a try finally block withinRocksDB.rollback().Why are the changes needed?
For fix 1:
When cancel() is called while the thread is in an interrupted state (e.g., during task cancellation), the previous implementation would fail. The code submitted Futures to cancel each stream, then called awaitResult() to wait for completion. However, awaitResult() checks the thread's interrupt flag and throws InterruptedException immediately if the thread is interrupted.
For fix 2:
Consider the case where
abort()is called onRocksDBStateStoreProvider. This callsrollback()on theRocksDBinstance, which in turn callschangelogWriter.foreach(_.abort())and then setschangelogWriter = None.However, if
changelogWriter.abort()throws an exception, the finally block still setsbackingFileStreamandcompressedStreamtonull. The exception propagates, and we never reach the line that setschangelogWriter = None.This leaves the RocksDB instance in an inconsistent state:
Now consider calling
RocksDB.load()again. This callsreplayChangelog(), which callsput(), which callschangelogWriter.put(). At this point, the assertionassert(compressedStream != null)fails, causing an exception while loading the StateStore.Does this PR introduce any user-facing change?
No
How was this patch tested?
Added test
"SPARK-54585: Interrupted task calling rollback does not throw an exception"which simulates the case when a thread in the interrupted state and begins a rollbackWas this patch authored or co-authored using generative AI tooling?
No