[SPARK-53807][SPARK-50771][CORE] Fix race condition issues between unlock and releaseAllLocksForTask in BlockInfoManager
#52524
+39
−9
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?
This PR fixes race condition issues between
unlockandreleaseAllLocksForTaskinBlockInfoManager.In case read locks for a block acquired by a task are released by
unclckandreleaseAllLocksForTaskconcurrently, assertion error can happen.The reason is calling
entry.getCountinreleaseAllLocksForTaskcan return an old value even after the count in an entry is decreased bycountsForTask.removeon another thread. Soinfo.readerCount -= lockCountcan result in a negative number, causing assertion error.This issue can be reproduced by inserting sleep into
unlockandreleaseAllLocksForTasklike as follows.And then, run the test like as follows.
The Javadoc for ConcurrentHashMultiset#entrySet says as follows.
So, this PR calculates
lockCountby callingreadLocks.countto get the latest count, and place it withinblockInfoblock for exclusive execution.Similar to read locks, a race condition isssue can happen even for write locks.
During
writeLocks.forEachinreleaseAllLocksForTask, ablockIdcan be removed fromwriteLocksbywriteLocksByTask.get(taskAttemptId).remove(blockId)inunlockon another thread.You can reproduce this issue by the new test added in this PR.
This PR fixes this issue by checking the existence of a
blockIdbywriteLocks.contains(info)withinblockInfoblock.Why are the changes needed?
Bug fix.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
Confirmed
SPARK-38675 - concurrent unlock and releaseAllLocksForTask calls should not failpasses even if sleeps are inserted intounlockandreleaseAllLocksForTasklike as follows.Also new test for write locks is added.
Was this patch authored or co-authored using generative AI tooling?
No.