[SPARK-50771][SPARK-53807][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
unlock
andreleaseAllLocksForTask
inBlockInfoManager
.In case read locks for a block acquired by a task are released by
unclck
andreleaseAllLocksForTask
concurrently, assertion error can happen.The reason is calling
entry.getCount
inreleaseAllLocksForTask
can return an old value even after the count in an entry is decreased bycountsForTask.remove
on another thread. Soinfo.readerCount -= lockCount
can result in a negative number, causing assertion error.This issue can be reproduced by inserting sleep into
unlock
andreleaseAllLocksForTask
like as follows.The Javadoc for ConcurrentHashMultiset#entrySet says as follows.
So, this PR calculates
lockCount
by callingreadLocks.count
to get the latest count, and place it withinblockInfo
block for exclusive execution.Similar to read locks, a race condition isssue can happen even for write locks.
During
writeLocks.forEach
inreleaseAllLocksForTask
, ablockId
can be removed fromwriteLocks
bywriteLocksByTask.get(taskAttemptId).remove(blockId)
inunlock
on 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
blockId
bywriteLocks.contains(info)
withinblockInfo
block.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 fail
passes even if sleeps are inserted intounlock
andreleaseAllLocksForTask
like as follows.Also new test for write locks is added.
Was this patch authored or co-authored using generative AI tooling?
No.