Repository navigation
Conversation
Call TaskMemoryManager.releaseExecutionMemory before decrementing `used` in CometTaskMemoryManager.releaseMemory so that if Spark throws, `used` and NativeMemoryConsumer.getUsed() remain unchanged rather than prematurely dropping while native code still counts the bytes as held. Add a regression test in CometTaskMemoryManagerSuite overriding TaskMemoryManager.releaseExecutionMemory to throw once and verifying that getUsed() and NativeMemoryConsumer.getUsed() are unchanged on failure and properly decremented on subsequent normal releases. Refs apache#7176 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
andygrove
enabled auto-merge
December 5, 2026 12:42
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Dec 5, 2026
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.
Which issue does this PR close?
Closes #7176.
Rationale for this change
CometTaskMemoryManager.releaseMemorydecrementedusedbefore callinginternal.releaseExecutionMemory(size, nativeMemoryConsumer). If Spark threw during the release, native code still treated the bytes as held whileused(andNativeMemoryConsumer.getUsed()) had already been lowered, skewing task-end leak checks and Spark's spill ordering.What changes are included in this PR?
spark/src/main/java/org/apache/spark/CometTaskMemoryManager.java: Callinternal.releaseExecutionMemory(size, nativeMemoryConsumer)before updatingused.addAndGet(-size)and trace logging inreleaseMemory(long size).spark/src/test/scala/org/apache/spark/CometTaskMemoryManagerSuite.scala: Addeda failed release leaves used memory unchanged, overridingTaskMemoryManager.releaseExecutionMemoryto throw once and assertingmanager.getUsed,NativeMemoryConsumer.getUsed, andgetMemoryConsumptionForThisTaskremain unchanged on failure and decrement properly on subsequent releases.How are these changes tested?
0 did not equal 128, 10/11 passed)..\mvnw.cmd -B test -Dtest=none "-Dsuites=org.apache.spark.CometTaskMemoryManagerSuite" "-Dscalastyle.skip=true" "-Dspotless.check.skip=true"— passed (11/11 tests)..\mvnw.cmd -B spotless:check "-DspotlessFiles=.*\.java"— passed (0 violations)..\mvnw.cmd -B spotless:check "-DspotlessFiles=.*CometTaskMemoryManagerSuite\.scala"— 0 scalafmt body violations (only the pre-existing Windows symlink header diff).python dev/ci/check-suites.py— passed.