Fix reentrant BatchingExecutor execution#3331
Open
He-Pin wants to merge 1 commit into
Open
Conversation
Motivation: Fork-join workers can execute another submitted batch while helping a join. The nested batch hit a single-level ThreadLocal requirement and could drop queued work. Modification: Preserve and restore the previous batch context around Batch and BlockableBatch execution. Add deterministic coverage for both modes and document nested fork-join execution. Result: Reentrant batches run without failing, and outer queued tasks continue. Normal execution retains one ThreadLocal lookup with no added allocations or locking. Tests: - sbt +actor-tests / Test / testOnly org.apache.pekko.dispatch.ExecutionContextSpec - passed on Scala 2.13 and Scala 3 - sbt headerCreateAll +headerCheckAll checkCodeStyle docs / paradox - passed - sbt +mimaReportBinaryIssues - passed - scalafmt --list --mode diff-ref=origin/main - passed - git diff --check - passed - sbt validatePullRequest - stopped at user request before completion - Qoder review - No must-fix findings References: Fixes apache#1708
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.
Motivation
Fork-join workers can execute another submitted dispatcher batch on the same worker while helping a
ForkJoinTaskjoin.BatchingExecutorrejected that nestedBatch.runorBlockableBatch.runinvocation, producingrequirement failedbefore the nested tasks could run.Modification
resubmitOnBlockmodes and verify that the outer batch continues draining its queued work.Result
Reentrant batches execute without failing or losing the outer batch's queued work. The normal path reuses the existing
ThreadLocal.get, adds no allocation or locking, and only adds a predictable null branch before the existingThreadLocal.remove.Tests
sbt "+actor-tests / Test / testOnly org.apache.pekko.dispatch.ExecutionContextSpec"- passed: 13 tests on Scala 2.13.18 and 13 tests on Scala 3.3.8.sbt headerCreateAll +headerCheckAll checkCodeStyle "docs / paradox"- passed.sbt +mimaReportBinaryIssues- passed on Scala 2.13.18 and Scala 3.3.8.scalafmt --list --mode diff-ref=origin/main- passed.git diff --check- passed.sbt validatePullRequest- not completed; interrupted at requester direction (exit 130) during the long-running impacted-module suite. An earlier forked test JVM exited with code 255, so this run is not reported as passing.References
Fixes #1708