Skip to content

Comments

HDFS-16600. Fix deadlock of fine-grain lock for FsDatastImpl of DataNode.#4367

Merged
Hexiaoqiao merged 1 commit intoapache:trunkfrom
ZanderXu:HDFS-16600
Jun 17, 2022
Merged

HDFS-16600. Fix deadlock of fine-grain lock for FsDatastImpl of DataNode.#4367
Hexiaoqiao merged 1 commit intoapache:trunkfrom
ZanderXu:HDFS-16600

Conversation

@ZanderXu
Copy link
Contributor

@ZanderXu ZanderXu commented May 28, 2022

Detail info please refer to HDFS-16600.
The UT org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.TestLazyPersistReplicaPlacement.testSynchronousEviction failed, because happened deadlock, which is introduced by HDFS-16534.

// org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.createRbw line 1588 need a read lock
try (AutoCloseableLock lock = lockManager.readLock(LockLevel.BLOCK_POOl,
        b.getBlockPoolId()))
// org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.evictBlocks line 3526 need a write lock
try (AutoCloseableLock lock = lockManager.writeLock(LockLevel.BLOCK_POOl, bpid))

@ZanderXu
Copy link
Contributor Author

@Hexiaoqiao @ayushtkn This bug was introduced by HDFS-16534. Please help me review it, thanks

Copy link
Member

@ayushtkn ayushtkn left a comment

Choose a reason for hiding this comment

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

Well the reason of Deadlock seems valid, but won't we be taking the write lock now for other purpose as well, where we actually could have lived with read lock? We should take write lock where we actually require, like the case we are chasing now. for other cases we should stay with read lock only, may be try some refactoring and restrict the write lock for this particular case only

@ZanderXu
Copy link
Contributor Author

Got it. I will gain a deep understanding of the scope of this BP lock and try to solve this case with ReadLock.

@hadoop-yetus
Copy link

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 47s 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 doesn't appear to include any new or modified tests. Please justify why no new tests are needed for this patch. Also please list what manual steps were performed to verify this patch.
_ trunk Compile Tests _
+1 💚 mvninstall 36m 51s trunk passed
+1 💚 compile 1m 27s trunk passed with JDK Private Build-11.0.15+10-Ubuntu-0ubuntu0.20.04.1
+1 💚 compile 1m 20s trunk passed with JDK Private Build-1.8.0_312-8u312-b07-0ubuntu1~20.04-b07
+1 💚 checkstyle 1m 5s trunk passed
+1 💚 mvnsite 1m 26s trunk passed
+1 💚 javadoc 1m 9s trunk passed with JDK Private Build-11.0.15+10-Ubuntu-0ubuntu0.20.04.1
+1 💚 javadoc 1m 29s trunk passed with JDK Private Build-1.8.0_312-8u312-b07-0ubuntu1~20.04-b07
+1 💚 spotbugs 3m 22s trunk passed
+1 💚 shadedclient 22m 11s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 1m 12s the patch passed
+1 💚 compile 1m 18s the patch passed with JDK Private Build-11.0.15+10-Ubuntu-0ubuntu0.20.04.1
+1 💚 javac 1m 18s the patch passed
+1 💚 compile 1m 8s the patch passed with JDK Private Build-1.8.0_312-8u312-b07-0ubuntu1~20.04-b07
+1 💚 javac 1m 8s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 checkstyle 0m 52s the patch passed
+1 💚 mvnsite 1m 17s the patch passed
+1 💚 javadoc 0m 50s the patch passed with JDK Private Build-11.0.15+10-Ubuntu-0ubuntu0.20.04.1
+1 💚 javadoc 1m 23s the patch passed with JDK Private Build-1.8.0_312-8u312-b07-0ubuntu1~20.04-b07
+1 💚 spotbugs 3m 15s the patch passed
+1 💚 shadedclient 21m 41s patch has no errors when building and testing our client artifacts.
_ Other Tests _
+1 💚 unit 236m 34s hadoop-hdfs in the patch passed.
+1 💚 asflicense 0m 50s The patch does not generate ASF License warnings.
339m 3s
Subsystem Report/Notes
Docker ClientAPI=1.41 ServerAPI=1.41 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-4367/1/artifact/out/Dockerfile
GITHUB PR #4367
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets
uname Linux 8e8fbc25f7bf 4.15.0-169-generic #177-Ubuntu SMP Thu Feb 3 10:50:38 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / d477636990330ffb7029eb22ec41f99d6dc67fdf
Default Java Private Build-1.8.0_312-8u312-b07-0ubuntu1~20.04-b07
Multi-JDK versions /usr/lib/jvm/java-11-openjdk-amd64:Private Build-11.0.15+10-Ubuntu-0ubuntu0.20.04.1 /usr/lib/jvm/java-8-openjdk-amd64:Private Build-1.8.0_312-8u312-b07-0ubuntu1~20.04-b07
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-4367/1/testReport/
Max. process+thread count 2717 (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-4367/1/console
versions git=2.25.1 maven=3.6.3 spotbugs=4.2.2
Powered by Apache Yetus 0.14.0 https://yetus.apache.org

This message was automatically generated.

@ZanderXu
Copy link
Contributor Author

I learned from the implementation of moveBlockAcrossStorage and used BP ReadLock to fix this bug.
@ayushtkn please help me review this patch again, thanks.

@hadoop-yetus
Copy link

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 44s 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 doesn't appear to include any new or modified tests. Please justify why no new tests are needed for this patch. Also please list what manual steps were performed to verify this patch.
_ trunk Compile Tests _
+1 💚 mvninstall 37m 48s trunk passed
+1 💚 compile 1m 28s trunk passed with JDK Private Build-11.0.15+10-Ubuntu-0ubuntu0.20.04.1
+1 💚 compile 1m 18s trunk passed with JDK Private Build-1.8.0_312-8u312-b07-0ubuntu1~20.04-b07
+1 💚 checkstyle 1m 9s trunk passed
+1 💚 mvnsite 1m 35s trunk passed
+1 💚 javadoc 1m 6s trunk passed with JDK Private Build-11.0.15+10-Ubuntu-0ubuntu0.20.04.1
+1 💚 javadoc 1m 29s trunk passed with JDK Private Build-1.8.0_312-8u312-b07-0ubuntu1~20.04-b07
+1 💚 spotbugs 3m 26s trunk passed
+1 💚 shadedclient 22m 38s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 1m 17s the patch passed
+1 💚 compile 1m 26s the patch passed with JDK Private Build-11.0.15+10-Ubuntu-0ubuntu0.20.04.1
+1 💚 javac 1m 26s the patch passed
+1 💚 compile 1m 13s the patch passed with JDK Private Build-1.8.0_312-8u312-b07-0ubuntu1~20.04-b07
+1 💚 javac 1m 13s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 checkstyle 0m 54s the patch passed
+1 💚 mvnsite 1m 19s the patch passed
+1 💚 javadoc 0m 50s the patch passed with JDK Private Build-11.0.15+10-Ubuntu-0ubuntu0.20.04.1
+1 💚 javadoc 1m 24s the patch passed with JDK Private Build-1.8.0_312-8u312-b07-0ubuntu1~20.04-b07
+1 💚 spotbugs 3m 19s the patch passed
+1 💚 shadedclient 22m 17s patch has no errors when building and testing our client artifacts.
_ Other Tests _
-1 ❌ unit 241m 46s /patch-unit-hadoop-hdfs-project_hadoop-hdfs.txt hadoop-hdfs in the patch passed.
+1 💚 asflicense 0m 51s The patch does not generate ASF License warnings.
346m 57s
Reason Tests
Failed junit tests hadoop.hdfs.TestRollingUpgrade
Subsystem Report/Notes
Docker ClientAPI=1.41 ServerAPI=1.41 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-4367/2/artifact/out/Dockerfile
GITHUB PR #4367
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets
uname Linux 0c52856a8f1c 4.15.0-169-generic #177-Ubuntu SMP Thu Feb 3 10:50:38 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / 0100f4917d24e4db256e5032f75a8f64bb76391a
Default Java Private Build-1.8.0_312-8u312-b07-0ubuntu1~20.04-b07
Multi-JDK versions /usr/lib/jvm/java-11-openjdk-amd64:Private Build-11.0.15+10-Ubuntu-0ubuntu0.20.04.1 /usr/lib/jvm/java-8-openjdk-amd64:Private Build-1.8.0_312-8u312-b07-0ubuntu1~20.04-b07
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-4367/2/testReport/
Max. process+thread count 3704 (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-4367/2/console
versions git=2.25.1 maven=3.6.3 spotbugs=4.2.2
Powered by Apache Yetus 0.14.0 https://yetus.apache.org

This message was automatically generated.

@hadoop-yetus
Copy link

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 49s 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 doesn't appear to include any new or modified tests. Please justify why no new tests are needed for this patch. Also please list what manual steps were performed to verify this patch.
_ trunk Compile Tests _
+1 💚 mvninstall 38m 55s trunk passed
+1 💚 compile 1m 41s trunk passed with JDK Private Build-11.0.15+10-Ubuntu-0ubuntu0.20.04.1
+1 💚 compile 1m 32s trunk passed with JDK Private Build-1.8.0_312-8u312-b07-0ubuntu1~20.04-b07
+1 💚 checkstyle 1m 17s trunk passed
+1 💚 mvnsite 1m 42s trunk passed
+1 💚 javadoc 1m 18s trunk passed with JDK Private Build-11.0.15+10-Ubuntu-0ubuntu0.20.04.1
+1 💚 javadoc 1m 45s trunk passed with JDK Private Build-1.8.0_312-8u312-b07-0ubuntu1~20.04-b07
+1 💚 spotbugs 3m 54s trunk passed
+1 💚 shadedclient 26m 12s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 1m 26s the patch passed
+1 💚 compile 1m 29s the patch passed with JDK Private Build-11.0.15+10-Ubuntu-0ubuntu0.20.04.1
+1 💚 javac 1m 29s the patch passed
+1 💚 compile 1m 23s the patch passed with JDK Private Build-1.8.0_312-8u312-b07-0ubuntu1~20.04-b07
+1 💚 javac 1m 23s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 checkstyle 1m 1s the patch passed
+1 💚 mvnsite 1m 28s the patch passed
+1 💚 javadoc 0m 59s the patch passed with JDK Private Build-11.0.15+10-Ubuntu-0ubuntu0.20.04.1
+1 💚 javadoc 1m 30s the patch passed with JDK Private Build-1.8.0_312-8u312-b07-0ubuntu1~20.04-b07
+1 💚 spotbugs 3m 38s the patch passed
+1 💚 shadedclient 25m 28s patch has no errors when building and testing our client artifacts.
_ Other Tests _
-1 ❌ unit 336m 31s /patch-unit-hadoop-hdfs-project_hadoop-hdfs.txt hadoop-hdfs in the patch passed.
+1 💚 asflicense 0m 59s The patch does not generate ASF License warnings.
452m 24s
Reason Tests
Failed junit tests hadoop.hdfs.tools.TestDFSAdmin
hadoop.hdfs.server.sps.TestExternalStoragePolicySatisfier
Subsystem Report/Notes
Docker ClientAPI=1.41 ServerAPI=1.41 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-4367/3/artifact/out/Dockerfile
GITHUB PR #4367
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets
uname Linux 6d2952785abf 4.15.0-175-generic #184-Ubuntu SMP Thu Mar 24 17:48:36 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / f08e25d
Default Java Private Build-1.8.0_312-8u312-b07-0ubuntu1~20.04-b07
Multi-JDK versions /usr/lib/jvm/java-11-openjdk-amd64:Private Build-11.0.15+10-Ubuntu-0ubuntu0.20.04.1 /usr/lib/jvm/java-8-openjdk-amd64:Private Build-1.8.0_312-8u312-b07-0ubuntu1~20.04-b07
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-4367/3/testReport/
Max. process+thread count 2138 (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-4367/3/console
versions git=2.25.1 maven=3.6.3 spotbugs=4.2.2
Powered by Apache Yetus 0.14.0 https://yetus.apache.org

This message was automatically generated.

Copy link
Contributor

@Hexiaoqiao Hexiaoqiao left a comment

Choose a reason for hiding this comment

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

@ZanderXu Thanks for great catch here. It makes sense to me. I am confused it will be safe to process following logic if obtain BLOCK_POOL lock first as expected, but why it leads deadlock.
cc @MingXiangLi Please take another review.

@Hexiaoqiao Hexiaoqiao requested a review from ayushtkn June 1, 2022 05:02
@ZanderXu
Copy link
Contributor Author

ZanderXu commented Jun 1, 2022

Thanks @Hexiaoqiao for your review.

I am confused it will be safe to process following logic if obtain BLOCK_POOL lock first as expected, but why it leads deadlock.

Deadlock is trigged when evictLazyPersistBlocks is required in createRbw. Because createRbw hold BLOCK_POOL read lock, but evictLazyPersistBlocks try to hold BLOCK_POOL write lock.

org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.testSynchronousEviction is failed because the DeadLock.

@MingXiangLi
Copy link
Contributor

@ZanderXu LGTM.The core logic in HDFS-16534 is change block pool write lock to read lock and add volume lock for each replica under this block pool.And we didn't change this method in HDFS-16534 because it's not a heavy call. So this commit is makes sense to me.

@ZanderXu
Copy link
Contributor Author

ZanderXu commented Jun 5, 2022

Thanks @MingXiangLi for your review. HDFS-16534 means a lot to me and I learned a lot from it.

@slfan1989
Copy link
Contributor

@ZanderXu I found that some tests of Junit Test of HDFS (DN) sometimes succeed and sometimes fail, but there is no way to judge whether it is related to DeadLock. How do you judge the occurrence of DeadLock?

@MingXiangLi HDFS-16534 is a very big change, which will greatly help the performance improvement of DN, but ZanderXu has already proposed 2 Jiras for this change. Can you help to re-examine this HDFS-16534, if it is separate each time The commit fixes pr, worried that it will bring more problems.

@ZanderXu
Copy link
Contributor Author

ZanderXu commented Jun 5, 2022

@slfan1989 org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.TestLazyPersistReplicaPlacement.testSynchronousEviction sometimes succeed? I have run it several times locally and all fail.

How do you judge the occurrence of DeadLock?

Deadlock is trigged when evictLazyPersistBlocks is required in createRbw. Because createRbw hold BLOCK_POOL read lock, but evictLazyPersistBlocks try to hold BLOCK_POOL write lock.

@slfan1989
Copy link
Contributor

Thank you for your contribution, but I still have some concerns about HDFS-16534. I feel that for a new feature, multiple prs should not be used to fix the problem separately, which makes the code very difficult to read. I recommend creating it under HDFS-15382 A subtask to fix HDFS-16598 and HDFS-16600 together, @ZanderXu @MingXiangLi.

Copy link
Contributor

@Hexiaoqiao Hexiaoqiao left a comment

Choose a reason for hiding this comment

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

LGTM. +1.

@Hexiaoqiao
Copy link
Contributor

Hexiaoqiao commented Jun 7, 2022

@ZanderXu Thanks for the great catch here.
It is indeed missed method which need to improve. cc @MingXiangLi @ZanderXu would you mind to check if other methods also leave this issues?

Thank you for your contribution, but I still have some concerns about HDFS-16534. I feel that for a new feature, multiple prs should not be used to fix the problem separately, which makes the code very difficult to read. I recommend creating it under HDFS-15382 A subtask to fix HDFS-16598 and HDFS-16600 together.

@slfan1989 Thansk for your suggestions. IMO, this is not the blocker issue. Any tickets will be collected to subtask of HDFS-16534 before checkin for committers. -1 to combine HDFS-16598 and HDFS-16600 together. IIUC, it is recommended to add/fix one issue for one ticket. Welcome to any more discussions.
@ZanderXu @slfan1989 Thanks again.

@ZanderXu
Copy link
Contributor Author

ZanderXu commented Jun 7, 2022

Thanks @Hexiaoqiao for your review, and I will check other methods.

@slfan1989
Copy link
Contributor

slfan1989 commented Jun 7, 2022

@ZanderXu @Hexiaoqiao Thank you very much everyone, I learned a lot from the discussion, I didn't pay attention to this pr, because the description information is too short. I will summarize the calling process in the comment area of ​​HDFS-16600 Leave a message (ASAP), and I hope @ZanderXu @Hexiaoqiao you can help me check it too.

Another suggestion, can you write the junit test? @ZanderXu

@ZanderXu
Copy link
Contributor Author

ZanderXu commented Jun 7, 2022

Another suggestion, can you write the junit test?

you can see the UT org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.TestLazyPersistReplicaPlacement.testSynchronousEviction.

Copy link
Member

@ayushtkn ayushtkn left a comment

Choose a reason for hiding this comment

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

Changes LGTM. If possible would be good if a test can be added.
Regarding:

Thansk for your suggestions. IMO, this is not the blocker issue. Any tickets will be collected to subtask of HDFS-16534 before checkin for committers. -1 to combine HDFS-16598 and HDFS-16600 together. IIUC, it is recommended to add/fix one issue for one ticket. Welcome to any more discussions.

Moving as subtask, yes we should do that, I too don't think we should merge issues unless they are same or extension of one. Separate issues should be tackled separately only, else if one gets screwed we need to revert both.

Regarding having one PR for all, don't know how we can achieve that once merged. you have to revert it and redo all the work. doesn't look something required here though. I am ok with whatever @Hexiaoqiao feel is good

@ZanderXu
Copy link
Contributor Author

ZanderXu commented Jun 9, 2022

Thanks @ayushtkn for your comment.

If possible would be good if a test can be added.

I found this issues because the UT org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.TestLazyPersistReplicaPlacement.testSynchronousEviction failed, so I thinks it's a nice UT to verify this issue.

@Hexiaoqiao
Copy link
Contributor

Thanks all for the further discussion. About the unit test, I did not retrieve this one, org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.testSynchronousEviction. Anything I missed? @ZanderXu Would mind to check if this test really located at hadoop-hdfs module now? Please correct me if I am wrong. Thanks again.

@ZanderXu
Copy link
Contributor Author

ZanderXu commented Jun 9, 2022

Oh, I'm sorry, the failed UT is org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.TestLazyPersistReplicaPlacement.testSynchronousEviction.

@Hexiaoqiao
Copy link
Contributor

Oh, I'm sorry, the failed UT is org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.TestLazyPersistReplicaPlacement.testSynchronousEviction.

Thanks @ZanderXu for your information. I think it can cover this case, let's wait what Ayush think about it.
Just find the latest build not clean. Try to trigger jenkins again, let's wait what it will say.

@ayushtkn
Copy link
Member

Makes sense to me. Thanx everyone

@slfan1989
Copy link
Contributor

slfan1989 commented Jun 11, 2022

@Hexiaoqiao @ZanderXu @MingXiangLi

I still have questions to ask.

  1. I still hope ZanderXu Can provide deadlock exception stack error information, I will continue to try to reproduce this problem in this part.

  2. I read the code of testSynchronousEviction carefully, this code uses the special storage strategy LAZY_PERSIST, This strategy will asynchronously flush memory blocks to disk. LazyWriter takes care of this work.
    Part of the code is as follows

private boolean saveNextReplica() {
      RamDiskReplica block = null;
      FsVolumeReference targetReference;
      FsVolumeImpl targetVolume;
      ReplicaInfo replicaInfo;
      boolean succeeded = false;

      try {
        block = ramDiskReplicaTracker.dequeueNextReplicaToPersist();
        if (block != null) {
          try (AutoCloseableLock lock = lockManager.writeLock(LockLevel.BLOCK_POOl,
              block.getBlockPoolId())) {
            replicaInfo = volumeMap.get(block.getBlockPoolId(), block.getBlockId());
  .....

If ZanderXu's judgment is correct, will this code also deadlock?

3.I always have a question, why we first add blockpool readlock, and then add volume write lock, how is the order of this lock derived?

4.I checked lockManager.writeLock(LockLevel.BLOCK_POOl, block.getBlockPoolId()), and I found that when adding volume, the writeLock of BLOCK_POOl is also used, so will it also deadlock(When createRbw And addVolume are done at the same time)?

in conclusion

I don't think this is a deadlock. Is it because createRow got the read lock, which caused evictBlocks to get the write lock for a long time, and then exceeded the waiting time of the junit test, which eventually led to an error?

I think to solve this problem completely, we also need to look at the processing logic of LazyWriter. It should not be enough to just modify evictBlocks.

@ZanderXu
Copy link
Contributor Author

ZanderXu commented Jun 11, 2022

Thanks @slfan1989 for your comment.
I'm sorry and I feel that you don't get the root cause of the failure of org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.TestLazyPersistReplicaPlacement.testSynchronousEviction.

Please refer to the stack:

"DataXceiver for client DFSClient_NONMAPREDUCE_-1350116008_11 at /127.0.0.1:51273 [Receiving block BP-1502139676-192.168
.3.4-1654943490123:blk_1073741826_1002]" #146 daemon prio=5 os_prio=31 tid=0x00007fb5cee2d800 nid=0x11507 waiting on con
dition [0x000070000c8ed000]
   java.lang.Thread.State: WAITING (parking)
        at sun.misc.Unsafe.park(Native Method)
        - parking to wait for  <0x00000007a14b6330> (a java.util.concurrent.locks.ReentrantReadWriteLock$FairSync)
        at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:8
36)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(AbstractQueuedSynchronizer.java:870)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1199)
        at java.util.concurrent.locks.ReentrantReadWriteLock$WriteLock.lock(ReentrantReadWriteLock.java:943)
        at org.apache.hadoop.hdfs.server.common.AutoCloseDataSetLock.lock(AutoCloseDataSetLock.java:62)
        at org.apache.hadoop.hdfs.server.datanode.DataSetLockManager.getWriteLock(DataSetLockManager.java:214)
        at org.apache.hadoop.hdfs.server.datanode.DataSetLockManager.writeLock(DataSetLockManager.java:170)
        at org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.FsDatasetImpl$LazyWriter.evictBlocks(FsDatasetImpl.java:3526)
        at org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.FsDatasetImpl.evictLazyPersistBlocks(FsDatasetImpl.java:3656)
        at org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.FsDatasetImpl.reserveLockedMemory(FsDatasetImpl.java:3675)
        at org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.FsDatasetImpl.createRbw(FsDatasetImpl.java:1606)
        at org.apache.hadoop.hdfs.server.datanode.BlockReceiver.<init>(BlockReceiver.java:219)
        at org.apache.hadoop.hdfs.server.datanode.DataXceiver.getBlockReceiver(DataXceiver.java:1319)
        at org.apache.hadoop.hdfs.server.datanode.DataXceiver.writeBlock(DataXceiver.java:767)
        at org.apache.hadoop.hdfs.protocol.datatransfer.Receiver.opWriteBlock(Receiver.java:176)
        at org.apache.hadoop.hdfs.protocol.datatransfer.Receiver.processOp(Receiver.java:110)
        at org.apache.hadoop.hdfs.server.datanode.DataXceiver.run(DataXceiver.java:293)
        at java.lang.Thread.run(Thread.java:748)

Is it because createRbw got the read lock, which caused evictBlocks to get the write lock for a long time

evictBlocks could not successfully acquire the write lock, since createRBW_logic holds the read lock of this block pool. And createRBW_logic is waiting for evictBlocks to finish. so it's deadlock.

so will it also deadlock(When createRbw And addVolume are done at the same time)?

I'm interested in this deadlock, can you provide a reproduction process? thanks~

@slfan1989
Copy link
Contributor

slfan1989 commented Jun 11, 2022

@ZanderXu

Please refer to the stack:

Thank you very much, I have understood that this is indeed a deadlock, because the same thread needs to use both a read lock and a write lock.

evictBlocks could not successfully acquire the write lock, since createRBW_logic holds the read lock of this block pool. And createRBW_logic is waiting for evictBlocks to finish. so it's deadlock.

very good explanation.

I'm interested in this deadlock, can you provide a reproduction process? thanks~

Thanks for your patience in explaining, this is my guess, now it looks like this won't happen(deadlock) because createRbw And addVolume won't be executed in the same thread, and createRbw And LazyWriter won't deadlock because they're not executed in one thread.

LGTM +1

The last question is

why we first add blockpool readlock, and then add volume write lock, how is the order of this lock derived?

@MingXiangLi
Copy link
Contributor

MingXiangLi commented Jun 11, 2022

@slfan1989 You can refer this https://issues.apache.org/jira/browse/HDFS-15382 jira which may answer your question.

@ZanderXu ZanderXu requested a review from ayushtkn June 11, 2022 13:58
@ZanderXu
Copy link
Contributor Author

Yeah, about last question, @slfan1989 you can prefer to HDFS-15382. If you have any questions, feel free to concat me and discuss it.

@Hexiaoqiao
Copy link
Contributor

Retrigger jenkins and wait to another build result.
Thanks everyone's helpful discussion. I would like to checkin for a while if no more other comments and build clean.

@hadoop-yetus
Copy link

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 39m 57s 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 doesn't appear to include any new or modified tests. Please justify why no new tests are needed for this patch. Also please list what manual steps were performed to verify this patch.
_ trunk Compile Tests _
+1 💚 mvninstall 40m 26s trunk passed
+1 💚 compile 1m 21s trunk passed
+1 💚 checkstyle 1m 8s trunk passed
+1 💚 mvnsite 1m 32s trunk passed
+1 💚 javadoc 1m 43s trunk passed
+1 💚 spotbugs 3m 43s trunk passed
+1 💚 shadedclient 22m 52s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 1m 25s the patch passed
+1 💚 compile 1m 19s the patch passed
+1 💚 javac 1m 19s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 checkstyle 0m 54s the patch passed
+1 💚 mvnsite 1m 25s the patch passed
+1 💚 javadoc 1m 20s the patch passed
+1 💚 spotbugs 3m 21s the patch passed
+1 💚 shadedclient 22m 2s patch has no errors when building and testing our client artifacts.
_ Other Tests _
+1 💚 unit 258m 9s hadoop-hdfs in the patch passed.
+1 💚 asflicense 0m 52s The patch does not generate ASF License warnings.
400m 10s
Subsystem Report/Notes
Docker ClientAPI=1.41 ServerAPI=1.41 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-4367/8/artifact/out/Dockerfile
GITHUB PR #4367
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets
uname Linux c020b276eba7 4.15.0-169-generic #177-Ubuntu SMP Thu Feb 3 10:50:38 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / f08e25d
Default Java Red Hat, Inc.-1.8.0_332-b09
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-4367/8/testReport/
Max. process+thread count 3757 (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-4367/8/console
versions git=2.9.5 maven=3.6.3 spotbugs=4.2.2
Powered by Apache Yetus 0.14.0 https://yetus.apache.org

This message was automatically generated.

@Hexiaoqiao Hexiaoqiao changed the title HDFS-16600. Fix deadlock on DataNode side. HDFS-16600. Fix deadlock of fine-grain lock for FsDatastImpl of DataNode. Jun 17, 2022
@Hexiaoqiao Hexiaoqiao merged commit 4893f00 into apache:trunk Jun 17, 2022
@Hexiaoqiao
Copy link
Contributor

The latest build looks good to me. Committed to trunk.
Thanks @ZanderXu for your report and contributions! Thanks @ayushtkn / @MingXiangLi / @slfan1989 for your warm discussions and helpful suggestions!

@ZanderXu
Copy link
Contributor Author

Thanks @Hexiaoqiao @ayushtkn @MingXiangLi @slfan1989 for your warm discussions and review.

HarshitGupta11 pushed a commit to HarshitGupta11/hadoop that referenced this pull request Nov 28, 2022
…ode. (apache#4367). Contributed by ZanderXu.

Reviewed-by: Mingxiang Li <liaiphag0@gmail.com>
Reviewed-by: Ayush Saxena <ayushsaxena@apache.org>
Signed-off-by: He Xiaoqiao <hexiaoqiao@apache.org>
LiuGuH pushed a commit to LiuGuH/hadoop that referenced this pull request Mar 26, 2024
…ode. (apache#4367). Contributed by ZanderXu.

Reviewed-by: Mingxiang Li <liaiphag0@gmail.com>
Reviewed-by: Ayush Saxena <ayushsaxena@apache.org>
Signed-off-by: He Xiaoqiao <hexiaoqiao@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants