HDFS-17777. Replace synchronized methods in ExcessRedundancyMap with ReentrantReadWriteLock#8325
Open
balodesecurity wants to merge 1 commit intoapache:trunkfrom
Open
HDFS-17777. Replace synchronized methods in ExcessRedundancyMap with ReentrantReadWriteLock#8325balodesecurity wants to merge 1 commit intoapache:trunkfrom
balodesecurity wants to merge 1 commit intoapache:trunkfrom
Conversation
…ReentrantReadWriteLock. ExcessRedundancyMap uses a single coarse-grained `synchronized` monitor for all operations. Because `contains()`, `getSize4Testing()`, and `getExcessRedundancyMap()` are read-only, they serialize unnecessarily against each other. Replace the monitor with a `ReentrantReadWriteLock`: read operations acquire the read lock (allowing concurrent reads), while mutating operations (`add`, `remove`, `clear`) acquire the write lock. The `size` counter is already an `AtomicLong` and needs no additional locking. Add TestExcessRedundancyMap with four unit tests covering basic semantics, clear(), concurrent-reader throughput, and concurrent-write correctness. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
🎊 +1 overall
This message was automatically generated. |
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.
Summary
ExcessRedundancyMapuses a single coarse-grainedsynchronizedmonitor for all operations. Becausecontains(),getSize4Testing(), andgetExcessRedundancyMap()are purely read-only, they unnecessarily serialize against each other under the block management write lock, reducing throughput on read-heavy workloads.Changes
synchronizedon every method with an explicitReentrantReadWriteLock:contains(),getSize4Testing(),getExcessRedundancyMap()add(),remove(),clear()sizecounter is already anAtomicLongand requires no additional locking.Test
Added
TestExcessRedundancyMapwith 4 unit tests:testAddContainsRemove— basic correctness of add/contains/removetestClear— clear resets map and size countertestConcurrentReads— 8 concurrent readers all complete within 10 s (no deadlock)testConcurrentWritesProduceCorrectSize— 10 concurrent writers produce a consistent final sizeAll 4 tests pass.
Test plan
TestExcessRedundancyMap(4 tests) — PASSblockmanagementtest suite (CI)