Skip to content

HDFS-18034. FsDatasetImpl#createTemporary should use the block pool read lock instead of the write lock - #8989

Open
cxzl25 wants to merge 2 commits into
apache:trunkfrom
cxzl25:HDFS-18034
Open

cxzl25 wants to merge 2 commits into
apache:trunkfrom
cxzl25:HDFS-18034

Conversation

@cxzl25

@cxzl25 cxzl25 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Description of PR

JIRA: HDFS-18034. FsDatasetImpl#createTemporary should use the block pool read lock instead of the write lock

FsDatasetImpl#createTemporary takes the block pool write lock only to look up the existing replica in the replica map. Nothing is modified under it.

After HDFS-17496, the DIR level operations (createRbw, finalizeBlock, removeReplicaFromMem, ...) hold the block pool read lock while doing disk IO. The write lock in createTemporary has to wait for all of them, and since dfs.datanode.lock.fair is true by default, the readers arriving later queue behind the waiting writer. One slow disk operation plus one incoming replica transfer (re-replication, Balancer, Mover, EC reconstruction) therefore stalls the whole block pool.

This PR changes it to the block pool read lock. This is safe because:

  • The section only reads the replica map and the state / generation stamp of the replica.
  • ReplicaMap#add and ReplicaMap#remove already run under the block pool read lock, and LightWeightResizableGSet is synchronized.
  • createRbw already does the same existence check under the block pool read lock.
  • The lock is released before stopWriter() and before the DIR lock is taken, and the loop re-checks the replica, so the method does not rely on the exclusion of the write lock.

The creation of the temporary file and volumeMap.add are still done under the DIR write lock and are not changed.

How was this patch tested?

Added TestFsDatasetImpl#testCreateTemporaryNotBlockedByBlockPoolReadLock: the test thread holds the block pool read lock while another thread calls createTemporary, which must return. The test times out without the fix and passes with it.

Ran TestFsDatasetImpl and TestWriteToReplica locally.

For code changes:

  • Does the title of this PR start with the corresponding JIRA issue id (e.g. 'HADOOP-17799. Your PR title ...')?
  • Object storage: Have the integration tests been executed and the endpoint
    declared according to the connector-specific documentation? Note: Automated CI
    testing doesn't cover all cases so manual testing with cloud storage is still
    required.
  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?
  • If applicable, have you updated the LICENSE, LICENSE-binary, NOTICE-binary files?

AI Tooling

If an AI tool was used:

@Hexiaoqiao Hexiaoqiao left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. +1.

@hadoop-yetus

Copy link
Copy Markdown

🎊 +1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 23m 7s 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 54m 42s trunk passed
+1 💚 compile 2m 0s trunk passed with JDK Ubuntu-21.0.13.0.3+1-1-24.04.1-Ubuntu
+1 💚 compile 1m 57s trunk passed with JDK Ubuntu-17.0.21.0.3+1-1-24.04.1-Ubuntu
+1 💚 checkstyle 1m 55s trunk passed
+1 💚 mvnsite 2m 38s trunk passed
+1 💚 javadoc 2m 42s trunk passed with JDK Ubuntu-21.0.13.0.3+1-1-24.04.1-Ubuntu
+1 💚 javadoc 2m 17s trunk passed with JDK Ubuntu-17.0.21.0.3+1-1-24.04.1-Ubuntu
+1 💚 spotbugs 4m 45s trunk passed
+1 💚 shadedclient 41m 37s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 1m 36s the patch passed
+1 💚 compile 1m 23s the patch passed with JDK Ubuntu-21.0.13.0.3+1-1-24.04.1-Ubuntu
+1 💚 javac 1m 23s the patch passed
+1 💚 compile 1m 31s the patch passed with JDK Ubuntu-17.0.21.0.3+1-1-24.04.1-Ubuntu
+1 💚 javac 1m 31s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 checkstyle 1m 23s the patch passed
+1 💚 mvnsite 1m 42s the patch passed
+1 💚 javadoc 1m 6s the patch passed with JDK Ubuntu-21.0.13.0.3+1-1-24.04.1-Ubuntu
+1 💚 javadoc 1m 13s the patch passed with JDK Ubuntu-17.0.21.0.3+1-1-24.04.1-Ubuntu
+1 💚 spotbugs 4m 38s the patch passed
+1 💚 shadedclient 40m 27s patch has no errors when building and testing our client artifacts.
_ Other Tests _
+1 💚 unit 273m 43s hadoop-hdfs in the patch passed.
+1 💚 asflicense 0m 54s The patch does not generate ASF License warnings.
464m 48s
Subsystem Report/Notes
Docker ClientAPI=1.57 ServerAPI=1.57 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8989/1/artifact/out/Dockerfile
GITHUB PR #8989
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets
uname Linux 474231b572c0 5.15.0-198-generic #208-Ubuntu SMP Fri Sep 4 10:22:38 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / 7a69ce8
Default Java Ubuntu-17.0.21.0.3+1-1-24.04.1-Ubuntu
Multi-JDK versions /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.13.0.3+1-1-24.04.1-Ubuntu /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.21.0.3+1-1-24.04.1-Ubuntu
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8989/1/testReport/
Max. process+thread count 2171 (vs. ulimit of 10000)
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-8989/1/console
versions git=2.43.0 maven=3.9.15 spotbugs=4.9.7
Powered by Apache Yetus 0.14.1 https://yetus.apache.org

This message was automatically generated.

boolean isInPipeline = false;
do {
try (AutoCloseableLock lock = lockManager.writeLock(LockLevel.BLOCK_POOl,
try (AutoCloseableLock lock = lockManager.readLock(LockLevel.BLOCK_POOl,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we protect the generation-stamp check with the existing replica’s DIR lock?

recoverRbw() can update the stamp in place under that lock and roll it back if the metadata rename fails.

With a shared block-pool lock, createTemporary() can see the intermediate value and reject the request.

@hadoop-yetus

Copy link
Copy Markdown

🎊 +1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 20m 5s 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 54m 5s trunk passed
+1 💚 compile 1m 56s trunk passed with JDK Ubuntu-21.0.13.1+2-1-24.04.1-Ubuntu
+1 💚 compile 1m 50s trunk passed with JDK Ubuntu-17.0.21.1+2-1-24.04.1-Ubuntu
+1 💚 checkstyle 1m 51s trunk passed
+1 💚 mvnsite 2m 1s trunk passed
+1 💚 javadoc 1m 31s trunk passed with JDK Ubuntu-21.0.13.1+2-1-24.04.1-Ubuntu
+1 💚 javadoc 1m 36s trunk passed with JDK Ubuntu-17.0.21.1+2-1-24.04.1-Ubuntu
+1 💚 spotbugs 4m 39s trunk passed
+1 💚 shadedclient 39m 16s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 1m 34s the patch passed
+1 💚 compile 1m 24s the patch passed with JDK Ubuntu-21.0.13.1+2-1-24.04.1-Ubuntu
+1 💚 javac 1m 24s the patch passed
+1 💚 compile 1m 31s the patch passed with JDK Ubuntu-17.0.21.1+2-1-24.04.1-Ubuntu
+1 💚 javac 1m 31s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 checkstyle 1m 27s the patch passed
+1 💚 mvnsite 1m 42s the patch passed
+1 💚 javadoc 1m 0s the patch passed with JDK Ubuntu-21.0.13.1+2-1-24.04.1-Ubuntu
+1 💚 javadoc 1m 4s the patch passed with JDK Ubuntu-17.0.21.1+2-1-24.04.1-Ubuntu
+1 💚 spotbugs 4m 8s the patch passed
+1 💚 shadedclient 38m 34s patch has no errors when building and testing our client artifacts.
_ Other Tests _
+1 💚 unit 267m 40s hadoop-hdfs in the patch passed.
+1 💚 asflicense 0m 56s The patch does not generate ASF License warnings.
448m 10s
Subsystem Report/Notes
Docker ClientAPI=1.57 ServerAPI=1.57 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8989/2/artifact/out/Dockerfile
GITHUB PR #8989
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets
uname Linux 3fd039b3394d 5.15.0-198-generic #208-Ubuntu SMP Fri Sep 4 10:22:38 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / 2f9a135
Default Java Ubuntu-17.0.21.1+2-1-24.04.1-Ubuntu
Multi-JDK versions /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.13.1+2-1-24.04.1-Ubuntu /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.21.1+2-1-24.04.1-Ubuntu
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8989/2/testReport/
Max. process+thread count 2434 (vs. ulimit of 10000)
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-8989/2/console
versions git=2.43.0 maven=3.9.15 spotbugs=4.9.7
Powered by Apache Yetus 0.14.1 https://yetus.apache.org

This message was automatically generated.

@hadoop-yetus

Copy link
Copy Markdown

🎊 +1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 24s 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 30m 50s trunk passed
+1 💚 compile 1m 4s trunk passed with JDK Ubuntu-21.0.13.1+2-1-24.04.1-Ubuntu
+1 💚 compile 1m 0s trunk passed with JDK Ubuntu-17.0.21.1+2-1-24.04.1-Ubuntu
+1 💚 checkstyle 1m 8s trunk passed
+1 💚 mvnsite 1m 14s trunk passed
+1 💚 javadoc 1m 0s trunk passed with JDK Ubuntu-21.0.13.1+2-1-24.04.1-Ubuntu
+1 💚 javadoc 0m 57s trunk passed with JDK Ubuntu-17.0.21.1+2-1-24.04.1-Ubuntu
+1 💚 spotbugs 2m 26s trunk passed
+1 💚 shadedclient 18m 58s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 0m 51s the patch passed
+1 💚 compile 0m 46s the patch passed with JDK Ubuntu-21.0.13.1+2-1-24.04.1-Ubuntu
+1 💚 javac 0m 46s the patch passed
+1 💚 compile 0m 50s the patch passed with JDK Ubuntu-17.0.21.1+2-1-24.04.1-Ubuntu
+1 💚 javac 0m 50s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 checkstyle 0m 46s the patch passed
+1 💚 mvnsite 0m 52s the patch passed
+1 💚 javadoc 0m 39s the patch passed with JDK Ubuntu-21.0.13.1+2-1-24.04.1-Ubuntu
+1 💚 javadoc 0m 40s the patch passed with JDK Ubuntu-17.0.21.1+2-1-24.04.1-Ubuntu
+1 💚 spotbugs 2m 15s the patch passed
+1 💚 shadedclient 18m 23s patch has no errors when building and testing our client artifacts.
_ Other Tests _
+1 💚 unit 183m 1s hadoop-hdfs in the patch passed.
+1 💚 asflicense 0m 34s The patch does not generate ASF License warnings.
268m 4s
Subsystem Report/Notes
Docker ClientAPI=1.57 ServerAPI=1.57 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8989/3/artifact/out/Dockerfile
GITHUB PR #8989
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets
uname Linux 9dd500657b16 5.15.0-204-generic #214-Ubuntu SMP Fri Nov 6 00:52:52 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / f5ee64a
Default Java Ubuntu-17.0.21.1+2-1-24.04.1-Ubuntu
Multi-JDK versions /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.13.1+2-1-24.04.1-Ubuntu /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.21.1+2-1-24.04.1-Ubuntu
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8989/3/testReport/
Max. process+thread count 4940 (vs. ulimit of 10000)
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-8989/3/console
versions git=2.43.0 maven=3.9.15 spotbugs=4.9.7
Powered by Apache Yetus 0.14.1 https://yetus.apache.org

This message was automatically generated.

This branch has not been deployed

No deployments
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.

4 participants