Skip to content

HADOOP-19847. Move logAllocatedBlock out of lock in FSNamesystem.getAdditionalBlock to reduce latency#8359

Closed
CapMoon wants to merge 1 commit intoapache:trunkfrom
CapMoon:HADOOP-19847
Closed

HADOOP-19847. Move logAllocatedBlock out of lock in FSNamesystem.getAdditionalBlock to reduce latency#8359
CapMoon wants to merge 1 commit intoapache:trunkfrom
CapMoon:HADOOP-19847

Conversation

@CapMoon
Copy link

@CapMoon CapMoon commented Mar 20, 2026

HADOOP-19847. Move logAllocatedBlock out of lock in FSNamesystem.getAdditionalBlock to reduce latency

Description of PR

The logAllocatedBlock method in FSNamesystem.getAdditionalBlock is currently called while holding global lock. Flame graph analysis shows this logging path (via SLF4J/Log4j appenders) contributes non-trivial latency, blocking other NameNode operations.
 
Since logAllocatedBlock is only for audit/diagnostic logging and does not modify shared state, we can safely move it after releasing global lock to reduce lock hold time and improve write throughput.
 
This change preserves all existing logging behavior while eliminating unnecessary lock contention from I/O-bound logging operations.

How was this patch tested?

N/A
logAllocatedBlock takes lots of time

@pan3793
Copy link
Member

pan3793 commented Mar 20, 2026

I think this makes sense. cc @cnauroth, who is the author of this part of the code.

@haiyang1987
Copy link
Contributor

@CapMoon thanks report, please first create HDFS-XXX issue, thanks

@hadoop-yetus
Copy link

🎊 +1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 35s 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 42m 6s trunk passed
+1 💚 compile 1m 47s trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 compile 1m 51s trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 checkstyle 1m 51s trunk passed
+1 💚 mvnsite 1m 56s trunk passed
+1 💚 javadoc 1m 35s trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 javadoc 1m 30s trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 spotbugs 4m 15s trunk passed
+1 💚 shadedclient 31m 35s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 1m 23s the patch passed
+1 💚 compile 1m 17s the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 javac 1m 17s the patch passed
+1 💚 compile 1m 19s the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 javac 1m 19s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
-0 ⚠️ checkstyle 1m 16s /results-checkstyle-hadoop-hdfs-project_hadoop-hdfs.txt hadoop-hdfs-project/hadoop-hdfs: The patch generated 1 new + 138 unchanged - 0 fixed = 139 total (was 138)
+1 💚 mvnsite 1m 25s the patch passed
+1 💚 javadoc 0m 59s the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 javadoc 1m 1s the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 spotbugs 3m 48s the patch passed
+1 💚 shadedclient 30m 26s patch has no errors when building and testing our client artifacts.
_ Other Tests _
+1 💚 unit 219m 23s hadoop-hdfs in the patch passed.
+1 💚 asflicense 0m 46s The patch does not generate ASF License warnings.
350m 15s
Subsystem Report/Notes
Docker ClientAPI=1.54 ServerAPI=1.54 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8359/1/artifact/out/Dockerfile
GITHUB PR #8359
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets
uname Linux 8f5724073926 5.15.0-173-generic #183-Ubuntu SMP Fri Mar 6 13:29:34 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / a72517b
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-8359/1/testReport/
Max. process+thread count 3490 (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-8359/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.

@CapMoon
Copy link
Author

CapMoon commented Mar 20, 2026

"please first create HDFS-XXX issue, thanks"


My bad....Will migrate to #8360 and https://issues.apache.org/jira/browse/HDFS-17896 @pan3793 @haiyang1987 @cnauroth

@CapMoon CapMoon closed this Mar 20, 2026
Copy link
Contributor

@edwardcapriolo edwardcapriolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non binding. But I believe you do away with the atomic -ref. Some favor atomic ref over volatile. Could add a test for sure

try {
newBlock = FSDirWriteFileOp.storeAllocatedBlock(ns, src,
HdfsConstants.GRANDFATHER_INODE_ID, "clientName", null, targets);
HdfsConstants.GRANDFATHER_INODE_ID, "clientName", null, targets, new AtomicReference<>());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test should use like a mockito-spy or verify to show that the logging happens as as side effect, and possibly when it doesn't happen, (eror etc)

@pan3793
Copy link
Member

pan3793 commented Mar 20, 2026

he just wants to use an atomic ref to carry another return value?

or maybe it can be changed to

- LocatedBlock storeAllocatedBlock(args ...)
+ Pair<LocatedBlock, BlockInfo> storeAllocatedBlock (args ...)

I think either is fine

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.

5 participants