Skip to content

HDFS-17777. Replace synchronized methods in ExcessRedundancyMap with ReentrantReadWriteLock#8325

Open
balodesecurity wants to merge 1 commit intoapache:trunkfrom
balodesecurity:HDFS-17777
Open

HDFS-17777. Replace synchronized methods in ExcessRedundancyMap with ReentrantReadWriteLock#8325
balodesecurity wants to merge 1 commit intoapache:trunkfrom
balodesecurity:HDFS-17777

Conversation

@balodesecurity
Copy link

Summary

ExcessRedundancyMap uses a single coarse-grained synchronized monitor for all operations. Because contains(), getSize4Testing(), and getExcessRedundancyMap() are purely read-only, they unnecessarily serialize against each other under the block management write lock, reducing throughput on read-heavy workloads.

Changes

  • Replace synchronized on every method with an explicit ReentrantReadWriteLock:
    • Read lock: contains(), getSize4Testing(), getExcessRedundancyMap()
    • Write lock: add(), remove(), clear()
  • The size counter is already an AtomicLong and requires no additional locking.

Test

Added TestExcessRedundancyMap with 4 unit tests:

  • testAddContainsRemove — basic correctness of add/contains/remove
  • testClear — clear resets map and size counter
  • testConcurrentReads — 8 concurrent readers all complete within 10 s (no deadlock)
  • testConcurrentWritesProduceCorrectSize — 10 concurrent writers produce a consistent final size

All 4 tests pass.

Test plan

  • TestExcessRedundancyMap (4 tests) — PASS
  • Full blockmanagement test suite (CI)

…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>
@hadoop-yetus
Copy link

🎊 +1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 34s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 codespell 0m 1s codespell was not available.
+0 🆗 detsecrets 0m 1s detect-secrets was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
+1 💚 test4tests 0m 0s The patch appears to include 1 new or modified test files.
_ trunk Compile Tests _
+1 💚 mvninstall 42m 50s trunk passed
+1 💚 compile 1m 44s trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 compile 1m 42s trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 checkstyle 1m 45s trunk passed
+1 💚 mvnsite 1m 51s trunk passed
+1 💚 javadoc 1m 29s trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 javadoc 1m 26s trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 spotbugs 4m 3s trunk passed
+1 💚 shadedclient 31m 46s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 1m 22s the patch passed
+1 💚 compile 1m 16s the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 javac 1m 16s the patch passed
+1 💚 compile 1m 14s the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 javac 1m 14s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 checkstyle 1m 14s the patch passed
+1 💚 mvnsite 1m 24s the patch passed
+1 💚 javadoc 0m 59s the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 javadoc 1m 0s the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 spotbugs 3m 47s the patch passed
+1 💚 shadedclient 31m 37s patch has no errors when building and testing our client artifacts.
_ Other Tests _
+1 💚 unit 217m 3s hadoop-hdfs in the patch passed.
+1 💚 asflicense 0m 46s The patch does not generate ASF License warnings.
349m 12s
Subsystem Report/Notes
Docker ClientAPI=1.54 ServerAPI=1.54 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8325/1/artifact/out/Dockerfile
GITHUB PR #8325
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets
uname Linux 4d845e87b2c1 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / 74c59a2
Default Java Ubuntu-17.0.18+8-Ubuntu-124.04.1
Multi-JDK versions /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.10+7-Ubuntu-124.04 /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.18+8-Ubuntu-124.04.1
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8325/1/testReport/
Max. process+thread count 3472 (vs. ulimit of 5500)
modules C: hadoop-hdfs-project/hadoop-hdfs U: hadoop-hdfs-project/hadoop-hdfs
Console output https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8325/1/console
versions git=2.43.0 maven=3.9.11 spotbugs=4.9.7
Powered by Apache Yetus 0.14.1 https://yetus.apache.org

This message was automatically generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants