Skip to content

HDFS-17639. hasStorageType() allocates array unnecessarily on every call#8316

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

HDFS-17639. hasStorageType() allocates array unnecessarily on every call#8316
balodesecurity wants to merge 1 commit intoapache:trunkfrom
balodesecurity:HDFS-17639

Conversation

@balodesecurity
Copy link

Problem

DatanodeDescriptor.hasStorageType() delegates to getStorageInfos() which:

  1. Acquires the storageMap lock
  2. Copies all storage values into a new DatanodeStorageInfo[] array
  3. Releases the lock
  4. Returns the array

hasStorageType() then iterates the returned array. This means every call allocates a new array and acquires the lock twice (the second time is reentrant since callers like injectStorage() already hold the lock). The same pattern exists in getStorageTypes().

On large clusters with many storages per DataNode, hasStorageType() is called frequently — during block placement, heartbeat processing, and topology updates — making this allocation and double-lock pattern a measurable source of lock contention and GC pressure.

Fix

In both hasStorageType() and getStorageTypes(), iterate storageMap.values() directly under a single synchronized (storageMap) block, eliminating the array allocation entirely. Callers that already hold the lock (e.g. injectStorage(), updateStorage()) benefit from Java's reentrant semantics — a single lock acquisition instead of two.

Testing

Added TestDatanodeDescriptor#testHasStorageTypeAndGetStorageTypes:

  • Creates a DatanodeDescriptor and verifies no type is present before any storage is injected
  • Injects a DISK storage and asserts hasStorageType(DISK) returns true and hasStorageType(SSD) returns false
  • Injects an SSD storage and asserts both types are now present via both hasStorageType() and getStorageTypes()
Tests run: 1, Failures: 0, Errors: 0
testHasStorageTypeAndGetStorageTypes — PASSED (0.058s)

@hadoop-yetus
Copy link

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 19m 42s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 codespell 0m 0s codespell was not available.
+0 🆗 detsecrets 0m 0s 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 49m 56s trunk passed
+1 💚 compile 1m 50s trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 compile 1m 49s trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 checkstyle 1m 48s trunk passed
+1 💚 mvnsite 1m 59s trunk passed
+1 💚 javadoc 1m 29s trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 javadoc 1m 31s trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 spotbugs 4m 35s trunk passed
+1 💚 shadedclient 38m 13s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 1m 27s the patch passed
+1 💚 compile 1m 21s the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 javac 1m 21s the patch passed
+1 💚 compile 1m 24s the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 javac 1m 24s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 checkstyle 1m 23s the patch passed
+1 💚 mvnsite 1m 33s the patch passed
+1 💚 javadoc 1m 2s the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 javadoc 1m 6s the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 spotbugs 4m 20s the patch passed
+1 💚 shadedclient 37m 26s patch has no errors when building and testing our client artifacts.
_ Other Tests _
-1 ❌ unit 294m 25s /patch-unit-hadoop-hdfs-project_hadoop-hdfs.txt hadoop-hdfs in the patch failed.
+1 💚 asflicense 1m 0s The patch does not generate ASF License warnings.
467m 0s
Subsystem Report/Notes
Docker ClientAPI=1.54 ServerAPI=1.54 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8316/1/artifact/out/Dockerfile
GITHUB PR #8316
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets
uname Linux 48b39b11adf4 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 / 3f9cbfc
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-8316/1/testReport/
Max. process+thread count 3284 (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-8316/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