You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by za...@apache.org on 2024/04/23 01:53:41 UTC
(hadoop) branch HDFS-17384 updated (49ab698478d6 -> 14153f07aab8)
This is an automated email from the ASF dual-hosted git repository.
zanderxu pushed a change to branch HDFS-17384
in repository https://gitbox.apache.org/repos/asf/hadoop.git
discard 49ab698478d6 HDFS-17457. [FGL] UTs support fine-grained locking (#6741)
discard d6617ff8afd2 HDFS-17459. [FGL] Add documentation (#6737)
discard 5614b6934b88 HDFS-17472. [FGL] gcDeletedSnapshot and getDelegationToken support FGL (#6743)
omit 1e45a04b5c14 HDFS-17424 [FGL] DelegationTokenSecretManager supports fine-grained lock (#6696)
omit 27ed48ef7f04 HDFS-17445. [FGL] some operations support fine-grained locking (#6715)
omit 62685b61c19a HDFS-17411. [FGL] Client RPCs involving snapshot support fine-grained lock (#6714)
omit 6c894321e4d7 HDFS-17389. [FGL] Client RPCs involving read process supports fine-grained lock (#6590)
omit 6c34ad883dc5 HDFS-17388. [FGL] Client RPCs involving write process supports fine-grained lock (#6589)
omit f7045818a6d9 HDFS-17420. EditLogTailer and FSEditLogLoader support FGL (#6679)
omit ae11d05aedcf HDFS-17412. [FGL] Client RPCs involving maintenance supports fine-grained lock (#6667)
omit 313f7058507a HDFS-17417. [FGL] HeartbeatManager and DatanodeAdminMonitor support fine-grained locking (#6656)
omit 3ad137d90e25 HDFS-17415. [FGL] RPCs in NamenodeProtocol support fine-grained lock (#6654)
omit 123915508b61 HDFS-17410. [FGL] Client RPCs that changes file attributes supports fine-grained lock (#6634)
omit e21c43e74dd9 HDFS-17423. [FGL] BlockManagerSafeMode supports fine-grained lock (#6645)
omit 77d32aa136e2 HDFS-17416. [FGL] Monitor threads in BlockManager.class support fine-grained lock (#6647)
omit 46dda50b49a9 HDFS-17414. [FGL] RPCs in DatanodeProtocol support fine-grained lock (#6649)
omit 213f478f58cb HDFS-17413. [FGL] CacheReplicationMonitor supports fine-grained lock (#6641)
omit 3214795bce19 HDFS-17395. [FGL] Use FSLock to protect ErasureCodingPolicy related operations (#6579)
omit a60b05b3fbf8 HDFS-17390. [FGL] FSDirectory supports this fine-grained locking (#6573)
omit 794b5aa57836 HDFS-17405. [FGL] Using different metric name to trace performance for FGL and Global lock (#6600)
omit b688ac8c185c HDFS-17398. [FGL] Implement the FGL lock for FSNLockManager (#6599)
omit 9b9ac73b431e HDFS-17387. [FGL] Abstract the configuration locking mode (#6572)
omit 551683d4bd55 HDFS-17394. [FGL] Remove unused WriteHoldCount of FSNamesystemLock (#6571)
add c4fa1b65fbca HADOOP-19089: [ABFS] Reverting Back Support of setXAttr() and getXAttr() on root path (#6592)
add 7653f968e5e4 HADOOP-19116. Update to zookeeper client 3.8.4 due to CVE-2024-23944. (#6638)
add 44a249e32a0d Exclude files from Apache RAT (#6671)
add 76489e579bb5 HADOOP-19127. Do not run unit tests on Windows pre-commit CI (#6672)
add c4f7a3625b5e HDFS-17435. Fix TestRouterRpc failed (#6650)
add 8bc4939ee206 HDFS-17441. Fix junit dependency by adding missing library in hadoop-hdfs-rbf. (#6669)
add 37f9ccdc868c HDFS-17368. HA: Standby should exit safemode when resources are available. (#6518). Contributed by Zilong Zhu.
add 9fe371aa151a HADOOP-18980. Invalid inputs for getTrimmedStringCollectionSplitByEquals (ADDENDUM) (#6546)
add 032796a0fb21 HADOOP-19047: S3A: Support in-memory tracking of Magic Commit data (#6468)
add 50370769cd56 HDFS-17429. Fixing wrong log file name in datatransfer Sender.java (#6670) Contributed by Zhongkun Wu.
add 5bfca6569259 HADOOP-19115. Upgrade to nimbus-jose-jwt 9.37.2 due to CVE-2023-52428. (#6637)
add 8528d5783d14 HDFS-17216. Distcp: When handle the small files, the bandwidth parameter will be invalid, fix this bug. (#6138)
add f3f63407468f HDFS-17443. add null check for fileSys and cluster before shutting down (#6683)
add f1f2abe64183 YARN-11668. Fix RM crash for potential concurrent modification exception when updating node attributes (#6681) Contributed by Junfan Zhang.
add 347521c95d49 HADOOP-19124. Update org.ehcache from 3.3.1 to 3.8.2. (#6665)
add 97c5a6efbaf0 HADOOP-19041. Use StandardCharsets in more places (#6449)
add aabf31f6fa8c HDFS-17103. Fix file system cleanup in TestNameEditsConfigs (#6071). Contributed by ConfX.
add 06db6289cb40 HADOOP-19024. Use bouncycastle jdk18 1.77 (#6410). Contributed
add 4807815e1cb4 HDFS-17448. Enhance the stability of the unit test TestDiskBalancerCommand (#6690). Contributed by Haiyang Hu
add 59976f1be277 HDFS-17450. Add explicit dependency on httpclient jar (#6130). Contributed by PJ Fanning
add f7d1ec2d9e43 HADOOP-19077. Remove use of javax.ws.rs.core.HttpHeaders (#6554). Contributed by PJ Fanning
add 5f3eb446f768 YARN-11663. [Federation] Add Cache Entity Nums Limit. (#6662) Contributed by Shilun Fan.
add 36c22400b223 HDFS-17408:Reduce the number of quota calculations in FSDirRenameOp (#6653). Contributed by lei w.
add ba7faf90c804 HADOOP-19098. Vector IO: Specify and validate ranges consistently.
add 1357bb162dfe HADOOP-19123. Update to commons-configuration2 2.10.1 due to CVE (#6661). Contributed by PJ Fanning
add b4f9d8e6fa47 Revert "HADOOP-19098. Vector IO: Specify and validate ranges consistently."
add 87fb97777745 HADOOP-19098. Vector IO: Specify and validate ranges consistently. #6604
add eede5b131575 HADOOP-19114. Upgrade to commons-compress 1.26.1 due to CVEs. (#6636)
add 62182b1f744d HADOOP-19098. Vector IO: test failure followup (#6701)
add d7157b4aa907 HADOOP-19141. Vector IO: Update default values consistently (#6702)
add 6ed73896f6e8 HADOOP-18656. [ABFS] Add Support for Paginated Delete for Large Directories in HNS Account (#6409)
add a1ae35e69164 HADOOP-19135. Remove Jcache 1.0-alpha. (#6695) Contributed by Shilun Fan.
add 73e6931ed05e HDFS-17449. Fix ill-formed decommission host name and port pair triggers IndexOutOfBound error (#6691). Contributed by ConfX
add 8c378d1ea1d6 YARN-11444. Improve YARN md documentation format. (#6711) Contributed by Shilun Fan.
add 3f8af73913a2 YARN-11670. Add CallerContext in NodeManager (#6688)
add f7bb4f159566 HADOOP-18135. Produce Windows binaries of Hadoop (#6673)
add 281e2d288df7 Revert "HADOOP-16822. Provide source artifacts for hadoop-client-api. Contributed by Karel Kolman." (#6458)
add dbe2d612586d HADOOP-19096. [ABFS] [CST Optimization] Enhance Client-Side Throttling Metrics Logic (#6276)
add 05964ad07ac0 HDFS-17453. IncrementalBlockReport can have race condition with Edit Log Tailer (#6708)
add 81b05977f259 HDFS-17455. Fix Client throw IndexOutOfBoundsException in DFSInputStream#fetchBlockAt (#6710). Contributed by Haiyang Hu.
add d194ad02426d HADOOP-19079. HttpExceptionUtils to verify that loaded class is really an exception before instantiation (#6557)
add 6ccb223c9c98 HDFS-17461. Fix spotbugs in PeerCache#getInternal (#6721). Contributed by Haiyang Hu.
add bd1a08b2cfba HADOOP-19129: [ABFS] Test Fixes and Test Script Bug Fixes (#6676)
add f49a4df797dd HDFS-17383:Datanode current block token should come from active NameNode in HA mode (#6562). Contributed by lei w.
add 87cc2f1a1f92 HDFS-17465. RBF: Use ProportionRouterRpcFairnessPolicyController get “'ava.Lang. Error: Maximum permit count exceeded' (#6727)
add 922c44a339e9 HADOOP-19130. FTPFileSystem rename with full qualified path broken (#6678). Contributed by shawn
add 0c35cf0982c2 HDFS-17477. IncrementalBlockReport race condition additional edge cases (#6748)
add e8b2c28dec1d HDFS-17478. FSPermissionChecker optimization by initializing AccessControlEnforcer in constructor (#6749)
add a386ac1f5632 YARN-11684. Fix general contract violation in PriorityQueueComparator. (#6725) Contributed by Tamas Domok.
add eec9cd299707 HADOOP-19107. Drop support for HBase v1 & upgrade HBase v2 (#6629). Contributed by Ayush Saxena
add 6404692c0973 HADOOP-19102. [ABFS] FooterReadBufferSize should not be greater than readBufferSize (#6617)
new c4ba19c23b4f HDFS-17394. [FGL] Remove unused WriteHoldCount of FSNamesystemLock (#6571)
new ca902d1212e7 HDFS-17387. [FGL] Abstract the configuration locking mode (#6572)
new 03170885c133 HDFS-17398. [FGL] Implement the FGL lock for FSNLockManager (#6599)
new f733d942d105 HDFS-17405. [FGL] Using different metric name to trace performance for FGL and Global lock (#6600)
new 0c512c0db00c HDFS-17390. [FGL] FSDirectory supports this fine-grained locking (#6573)
new 19f2c773df45 HDFS-17395. [FGL] Use FSLock to protect ErasureCodingPolicy related operations (#6579)
new 5c7719b9e60b HDFS-17413. [FGL] CacheReplicationMonitor supports fine-grained lock (#6641)
new f64cb049ad06 HDFS-17414. [FGL] RPCs in DatanodeProtocol support fine-grained lock (#6649)
new 1d2b15d9079c HDFS-17416. [FGL] Monitor threads in BlockManager.class support fine-grained lock (#6647)
new 24139acc8652 HDFS-17423. [FGL] BlockManagerSafeMode supports fine-grained lock (#6645)
new a55cd3bb9f45 HDFS-17410. [FGL] Client RPCs that changes file attributes supports fine-grained lock (#6634)
new ea3cbae809ac HDFS-17415. [FGL] RPCs in NamenodeProtocol support fine-grained lock (#6654)
new 07c4b73dc500 HDFS-17417. [FGL] HeartbeatManager and DatanodeAdminMonitor support fine-grained locking (#6656)
new 771ec5a3df13 HDFS-17412. [FGL] Client RPCs involving maintenance supports fine-grained lock (#6667)
new 132a63f4ad2c HDFS-17420. [FGL] EditLogTailer and FSEditLogLoader support FGL (#6679)
new f0da5122e6d8 HDFS-17388. [FGL] Client RPCs involving write process supports fine-grained lock (#6589)
new ee0beaee40b2 HDFS-17389. [FGL] Client RPCs involving read process supports fine-grained lock (#6590)
new 4f7160853c7c HDFS-17411. [FGL] Client RPCs involving snapshot support fine-grained lock (#6714)
new 724b9fd5cfd4 HDFS-17445. [FGL] some operations support fine-grained locking (#6715)
new 02de6df9d443 HDFS-17424. [FGL] DelegationTokenSecretManager supports fine-grained lock (#6696)
new 43aa4f905ecd HDFS-17472. [FGL] gcDeletedSnapshot and getDelegationToken support FGL (#6743)
new 39e0ac082555 HDFS-17459. [FGL] Add documentation (#6737)
new 14153f07aab8 HDFS-17457. [FGL] UTs support fine-grained locking (#6741)
This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version. This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:
* -- * -- B -- O -- O -- O (49ab698478d6)
\
N -- N -- N refs/heads/HDFS-17384 (14153f07aab8)
You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.
Any revisions marked "omit" are not gone; other references still
refer to them. Any revisions marked "discard" are gone forever.
The 23 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
BUILDING.txt | 23 +-
LICENSE-binary | 26 +-
dev-support/bin/create-release | 19 +-
dev-support/bin/hadoop.sh | 5 +
dev-support/docker/Dockerfile_windows_10 | 21 +-
dev-support/docker/pkg-resolver/install-pip.ps1 | 44 ++
dev-support/docker/pkg-resolver/install-python.ps1 | 54 ++
.../main/resources/assemblies/hadoop-yarn-dist.xml | 2 +-
hadoop-client-modules/hadoop-client-api/pom.xml | 4 -
.../hadoop-client-check-test-invariants/pom.xml | 1 +
.../resources/ensure-jars-have-correct-contents.sh | 6 +
.../hadoop-client-integration-tests/pom.xml | 4 +-
.../src/site/markdown/cloud-storage/index.md | 2 +-
hadoop-common-project/hadoop-auth/pom.xml | 2 +-
.../security/authentication/util/KerberosUtil.java | 11 +-
hadoop-common-project/hadoop-common/pom.xml | 7 +-
.../java/org/apache/hadoop/conf/ConfServlet.java | 2 +-
.../java/org/apache/hadoop/conf/Configuration.java | 2 +-
.../org/apache/hadoop/fs/ChecksumFileSystem.java | 37 +-
.../org/apache/hadoop/fs/PositionedReadable.java | 1 +
.../org/apache/hadoop/fs/RawLocalFileSystem.java | 7 +-
.../org/apache/hadoop/fs/VectoredReadUtils.java | 185 +++--
.../main/java/org/apache/hadoop/fs/XAttrCodec.java | 7 +-
.../org/apache/hadoop/fs/ftp/FTPFileSystem.java | 8 +-
.../apache/hadoop/fs/impl/CombinedFileRange.java | 43 +-
.../org/apache/hadoop/fs/impl/FileRangeImpl.java | 3 +-
.../org/apache/hadoop/util/HttpExceptionUtils.java | 17 +-
.../java/org/apache/hadoop/util/StringUtils.java | 28 +-
.../apache/hadoop/util/functional/FutureIO.java | 79 ++
.../site/markdown/filesystem/fsdatainputstream.md | 145 +++-
.../org/apache/hadoop/conf/TestConfServlet.java | 2 +-
.../org/apache/hadoop/conf/TestConfiguration.java | 2 +-
.../org/apache/hadoop/fs/TestLocalFileSystem.java | 3 +-
.../apache/hadoop/fs/TestVectoredReadUtils.java | 487 -------------
.../contract/AbstractContractVectoredReadTest.java | 395 ++++++----
.../apache/hadoop/fs/contract/ContractOptions.java | 5 +
.../hadoop/fs/contract/ContractTestUtils.java | 68 +-
.../localfs/TestLocalFSContractVectoredRead.java | 22 +-
.../apache/hadoop/fs/ftp/TestFTPFileSystem.java | 49 +-
.../hadoop/fs/impl/TestVectoredReadUtils.java | 804 +++++++++++++++++++++
.../hadoop/fs/impl/prefetch/TestBlockCache.java | 2 +-
.../org/apache/hadoop/test/LambdaTestUtils.java | 117 ++-
.../apache/hadoop/util/TestHttpExceptionUtils.java | 89 ++-
.../org/apache/hadoop/util/TestPreconditions.java | 5 -
.../org/apache/hadoop/util/TestStringUtils.java | 58 +-
.../src/test/resources/contract/localfs.xml | 5 +
hadoop-common-project/hadoop-kms/pom.xml | 2 +-
hadoop-hdfs-project/hadoop-hdfs-client/pom.xml | 10 +
.../apache/hadoop/hdfs/DFSClientFaultInjector.java | 2 +
.../org/apache/hadoop/hdfs/DFSInputStream.java | 9 +
.../java/org/apache/hadoop/hdfs/PeerCache.java | 4 -
.../hadoop/hdfs/protocol/datatransfer/Sender.java | 5 +
.../apache/hadoop/hdfs/web/WebHdfsFileSystem.java | 2 +-
.../ConfRefreshTokenBasedAccessTokenProvider.java | 2 +-
.../oauth2/CredentialBasedAccessTokenProvider.java | 2 +-
hadoop-hdfs-project/hadoop-hdfs-httpfs/pom.xml | 2 +-
.../apache/hadoop/fs/http/client/HttpFSUtils.java | 2 +-
hadoop-hdfs-project/hadoop-hdfs-nfs/pom.xml | 2 +-
hadoop-hdfs-project/hadoop-hdfs-rbf/pom.xml | 12 +-
...roportionRouterRpcFairnessPolicyController.java | 3 +-
.../server/federation/router/TestDFSRouter.java | 49 ++
.../server/federation/router/TestRouterRpc.java | 46 --
hadoop-hdfs-project/hadoop-hdfs/pom.xml | 2 +-
.../token/block/BlockPoolTokenSecretManager.java | 6 +-
.../token/block/BlockTokenSecretManager.java | 12 +-
.../hdfs/server/blockmanagement/BlockManager.java | 16 +-
.../server/blockmanagement/DatanodeManager.java | 7 +-
.../blockmanagement/PendingDataNodeMessages.java | 24 +
.../blockaliasmap/impl/TextFileRegionAliasMap.java | 5 +-
.../hdfs/server/datanode/BPOfferService.java | 8 +-
.../hdfs/server/datanode/BPServiceActor.java | 1 +
.../hadoop/hdfs/server/datanode/BlockReceiver.java | 3 +-
.../datanode/fsdataset/impl/BlockPoolSlice.java | 3 +-
.../datanode/fsdataset/impl/FsVolumeImpl.java | 3 +-
.../server/datanode/metrics/DataNodeMetrics.java | 2 +-
.../org/apache/hadoop/hdfs/server/mover/Mover.java | 3 +-
.../hadoop/hdfs/server/namenode/FSDirMkdirOp.java | 6 +-
.../hadoop/hdfs/server/namenode/FSDirRenameOp.java | 100 ++-
.../hadoop/hdfs/server/namenode/FSDirectory.java | 28 +-
.../hadoop/hdfs/server/namenode/FSNamesystem.java | 13 +-
.../hdfs/server/namenode/FSPermissionChecker.java | 18 +-
.../server/namenode/NetworkTopologyServlet.java | 2 +-
.../java/org/apache/hadoop/hdfs/tools/DFSck.java | 5 +-
.../OfflineImageReconstructor.java | 14 +-
.../hdfs/TestHDFSContractVectoredRead.java | 54 ++
.../java/org/apache/hadoop/hdfs/DFSTestUtil.java | 2 +-
.../org/apache/hadoop/hdfs/TestDFSInputStream.java | 72 ++
.../java/org/apache/hadoop/hdfs/TestDFSShell.java | 3 +-
.../hadoop/hdfs/TestDistributedFileSystem.java | 3 +-
.../java/org/apache/hadoop/hdfs/TestGetBlocks.java | 2 +-
.../org/apache/hadoop/hdfs/UpgradeUtilities.java | 8 +-
.../hdfs/security/token/block/TestBlockToken.java | 4 +-
.../token/block/TestUpdateDataNodeCurrentKey.java | 122 ++++
.../server/blockmanagement/TestBlockManager.java | 2 +-
.../TestCorruptionWithFailover.java | 4 +-
.../TestPendingDataNodeMessages.java | 68 +-
.../datanode/TestIncrementalBlockReports.java | 306 ++++++++
.../datanode/fsdataset/impl/TestProvidedImpl.java | 3 +-
.../command/TestDiskBalancerCommand.java | 9 +-
.../TestCorrectnessOfQuotaAfterRenameOp.java | 161 +++++
.../server/namenode/TestFSPermissionChecker.java | 7 +-
.../hdfs/server/namenode/TestNameEditsConfigs.java | 8 +-
.../hdfs/server/namenode/ha/TestDNFencing.java | 26 +-
.../hdfs/server/namenode/ha/TestHASafeMode.java | 7 +
.../namenode/snapshot/TestRenameWithSnapshots.java | 2 +-
.../apache/hadoop/hdfs/util/HostsFileWriter.java | 4 +
.../hdfs/web/TestWebHdfsFileSystemContract.java | 4 +-
.../hadoop-mapreduce-client-app/pom.xml | 8 +-
.../hadoop/mapreduce/v2/app/rm/RMCommunicator.java | 2 +-
.../mapreduce/v2/app/webapp/dao/JobInfo.java | 2 +-
.../mapreduce/v2/app/webapp/TestAMWebApp.java | 2 +-
.../TestJobResourceUploaderWithSharedCache.java | 25 +-
.../hadoop-mapreduce-client-jobclient/pom.xml | 4 +-
.../mapred/TestConcatenatedCompressedInput.java | 2 +-
.../apache/hadoop/mapred/TestFieldSelection.java | 3 +-
.../hadoop/mapred/TestKeyValueTextInputFormat.java | 5 +-
.../apache/hadoop/mapred/TestTextInputFormat.java | 9 +-
.../mapred/lib/aggregate/TestAggregates.java | 7 +-
.../lib/aggregate/TestMapReduceAggregates.java | 7 +-
.../lib/input/TestMRKeyValueTextInputFormat.java | 5 +-
.../hadoop/mapred/uploader/FrameworkUploader.java | 4 +-
.../hadoop/maven/plugin/cmakebuilder/TestMojo.java | 3 +-
hadoop-project/pom.xml | 89 +--
.../org/apache/hadoop/tools/HadoopArchives.java | 2 +-
hadoop-tools/hadoop-aws/pom.xml | 4 +-
.../java/org/apache/hadoop/fs/s3a/Constants.java | 4 +-
.../org/apache/hadoop/fs/s3a/S3AFileSystem.java | 18 +
.../org/apache/hadoop/fs/s3a/S3AInputStream.java | 196 +++--
.../hadoop/fs/s3a/commit/CommitConstants.java | 16 +
.../fs/s3a/commit/MagicCommitIntegration.java | 20 +-
.../commit/magic/InMemoryMagicCommitTracker.java | 146 ++++
.../fs/s3a/commit/magic/MagicCommitTracker.java | 106 +--
.../s3a/commit/magic/MagicCommitTrackerUtils.java | 64 ++
.../fs/s3a/commit/magic/MagicS3GuardCommitter.java | 108 ++-
...ommitTracker.java => S3MagicCommitTracker.java} | 109 +--
.../hadoop/fs/s3a/impl/SDKStreamDrainer.java | 7 +-
.../site/markdown/tools/hadoop-aws/committers.md | 7 +
.../contract/s3a/ITestS3AContractVectoredRead.java | 126 ++--
.../fs/s3a/TestS3AAWSCredentialsProvider.java | 77 +-
.../fs/s3a/commit/AbstractITCommitProtocol.java | 15 +-
.../fs/s3a/commit/TestMagicCommitTrackerUtils.java | 64 ++
.../s3a/commit/magic/ITestMagicCommitProtocol.java | 30 +
.../fs/s3a/commit/terasort/ITestTerasortOnS3A.java | 17 +-
.../fs/s3a/performance/ITestS3AOpenCost.java | 3 +-
.../fs/s3a/scale/AbstractSTestS3AHugeFiles.java | 110 ++-
.../fs/s3a/scale/ITestS3AHugeFilesDiskBlocks.java | 6 +
.../hadoop-aws/src/test/resources/contract/s3a.xml | 5 +
.../dev-support/testrun-scripts/testsupport.sh | 58 +-
hadoop-tools/hadoop-azure/pom.xml | 4 +-
.../hadoop/fs/azurebfs/AbfsConfiguration.java | 13 +-
.../hadoop/fs/azurebfs/AzureBlobFileSystem.java | 32 +-
.../fs/azurebfs/AzureBlobFileSystemStore.java | 28 +-
.../fs/azurebfs/constants/AbfsHttpConstants.java | 33 +-
.../fs/azurebfs/constants/ConfigurationKeys.java | 5 +
.../constants/FileSystemConfigurations.java | 1 +
.../fs/azurebfs/constants/HttpQueryParams.java | 1 +
.../contracts/services/AzureServiceErrorCode.java | 10 +-
.../hadoop/fs/azurebfs/services/AbfsClient.java | 64 +-
.../fs/azurebfs/services/AbfsInputStream.java | 5 +-
.../fs/azurebfs/services/AbfsOutputStream.java | 4 +-
.../fs/azurebfs/services/AbfsRestOperation.java | 95 ++-
.../fs/azurebfs/services/RetryReasonConstants.java | 4 +-
.../fs/azurebfs/services/SharedKeyCredentials.java | 8 +-
.../ServerErrorRetryReason.java | 14 +-
.../hadoop-azure/src/site/markdown/abfs.md | 5 +
.../src/site/markdown/testing_azure.md | 82 ++-
.../fs/azurebfs/AbstractAbfsIntegrationTest.java | 90 ++-
.../apache/hadoop/fs/azurebfs/ITestAbfsClient.java | 62 +-
.../fs/azurebfs/ITestAbfsCustomEncryption.java | 3 +-
.../fs/azurebfs/ITestAbfsStreamStatistics.java | 4 +-
.../ITestAzureBlobFileSystemAttributes.java | 41 +-
.../ITestAzureBlobFileSystemCheckAccess.java | 14 +-
.../azurebfs/ITestAzureBlobFileSystemChecksum.java | 28 +-
.../ITestAzureBlobFileSystemDelegationSAS.java | 2 +-
.../azurebfs/ITestAzureBlobFileSystemDelete.java | 8 +-
.../ITestAzureBlobFileSystemFileStatus.java | 2 -
.../fs/azurebfs/ITestAzureBlobFileSystemLease.java | 5 +-
.../fs/azurebfs/ITestGetNameSpaceEnabled.java | 3 +
.../azurebfs/commit/AbstractAbfsClusterITest.java | 25 +-
.../azurebfs/constants/TestConfigurationKeys.java | 1 +
.../ITestAbfsFileSystemContractVectoredRead.java | 54 ++
.../fs/azurebfs/services/AbfsClientUtils.java | 11 +
.../services/AbfsInputStreamTestUtils.java | 295 ++++++++
.../fs/azurebfs/services/ITestAbfsClient.java | 2 +-
.../fs/azurebfs/services/ITestAbfsInputStream.java | 133 +---
.../services/ITestAbfsInputStreamReadFooter.java | 376 +++++++---
.../ITestAbfsInputStreamSmallFileReads.java | 87 ++-
.../services/ITestAbfsPaginatedDelete.java | 333 +++++++++
.../azurebfs/services/ITestAbfsRestOperation.java | 6 +
.../services/ITestExponentialRetryPolicy.java | 2 +-
.../TestAbfsRestOperationMockFailures.java | 72 +-
.../fs/azurebfs/services/TestRetryReason.java | 8 +-
.../accountName_settings.xml.template | 29 +-
hadoop-tools/hadoop-distcp/pom.xml | 6 +
.../hadoop/tools/util/ThrottledInputStream.java | 9 +-
.../tools/util/TestThrottledInputStream.java | 75 +-
hadoop-tools/hadoop-extras/pom.xml | 4 +-
.../namenode/ITestProvidedImplementation.java | 3 +-
hadoop-tools/hadoop-gridmix/pom.xml | 4 +-
.../hadoop/mapred/gridmix/ExecutionSummarizer.java | 2 +-
hadoop-tools/hadoop-streaming/pom.xml | 4 +-
.../org/apache/hadoop/streaming/StreamUtil.java | 2 +-
.../hadoop/streaming/TestStreamDataProtocol.java | 7 +-
.../hadoop/streaming/TestStreamReduceNone.java | 7 +-
.../streaming/TestStreamXmlRecordReader.java | 7 +-
.../org/apache/hadoop/streaming/TestStreaming.java | 3 +-
.../hadoop/streaming/TestStreamingKeyValue.java | 3 +-
.../hadoop/streaming/TestStreamingSeparator.java | 7 +-
.../hadoop/streaming/TestTypedBytesStreaming.java | 3 +-
.../mapreduce/TestStreamXmlRecordReader.java | 6 +-
.../apache/hadoop/yarn/conf/YarnConfiguration.java | 4 +
.../yarn/service/client/ApiServiceClient.java | 4 +-
.../apache/hadoop/yarn/service/utils/HttpUtil.java | 2 +-
.../apache/hadoop/yarn/client/cli/TestTopCLI.java | 3 +-
.../apache/hadoop/yarn/client/cli/TestYarnCLI.java | 3 +-
.../hadoop-yarn/hadoop-yarn-common/pom.xml | 2 +-
.../src/main/resources/yarn-default.xml | 9 +
.../logaggregation/TestAggregatedLogFormat.java | 5 +-
.../pom.xml | 2 +-
.../TestApplicationHistoryServer.java | 3 +-
.../hadoop-yarn-server-common/pom.xml | 12 +-
.../federation/cache/FederationGuavaCache.java | 12 +-
.../server/federation/cache/FederationJCache.java | 60 +-
.../utils/TestFederationStateStoreFacade.java | 4 +-
.../yarn/server/nodemanager/NodeManager.java | 4 +
.../amrmproxy/FederationInterceptor.java | 7 +-
.../resources/CGroupsBlkioResourceHandlerImpl.java | 5 +-
.../resources/CGroupsCpuResourceHandlerImpl.java | 3 +-
.../linux/resources/CGroupsHandlerImpl.java | 9 +-
.../linux/resources/TrafficController.java | 7 +-
.../runtime/DefaultLinuxContainerRuntime.java | 7 +-
.../linux/runtime/docker/DockerClient.java | 9 +-
.../gpu/NvidiaDockerV1CommandPlugin.java | 3 +-
.../util/CgroupsLCEResourcesHandler.java | 7 +-
.../nodemanager/util/ProcessIdFileReader.java | 5 +-
.../nodelabels/NodeAttributesManagerImpl.java | 2 +-
.../PriorityUtilizationQueueOrderingPolicy.java | 78 +-
.../converter/FSConfigToCSConfigConverter.java | 2 +-
.../resourcemanager/webapp/RMWebServices.java | 2 +-
...TestPriorityUtilizationQueueOrderingPolicy.java | 91 +++
.../resourcemanager/webapp/TestRMWebServices.java | 2 +-
.../webapp/TestRMWebServicesAppsModification.java | 6 +-
...RMWebServicesDelegationTokenAuthentication.java | 9 +-
...TestRMWebServicesHttpStaticUserPermissions.java | 3 +-
.../router/webapp/FederationInterceptorREST.java | 2 +-
.../server/router/webapp/RouterWebServiceUtil.java | 2 +-
.../webapp/MockDefaultRequestInterceptorREST.java | 2 +-
.../hadoop-yarn-server-tests/pom.xml | 2 +-
.../pom.xml | 131 +---
.../reader/DummyTimelineReaderMetrics.java | 39 -
.../TestTimelineReaderWebServicesHBaseStorage.java | 11 -
.../storage/TestTimelineReaderHBaseDown.java | 4 +
.../pom.xml | 18 -
.../pom.xml | 18 -
.../pom.xml | 211 ------
.../src/assembly/coprocessor.xml | 38 -
.../storage/common/HBaseTimelineServerUtils.java | 222 ------
.../storage/common/package-info.java | 28 -
.../storage/flow/FlowRunCoprocessor.java | 278 -------
.../timelineservice/storage/flow/FlowScanner.java | 721 ------------------
.../storage/flow/FlowScannerOperation.java | 46 --
.../timelineservice/storage/flow/package-info.java | 29 -
.../timelineservice/storage/package-info.java | 28 -
.../pom.xml | 30 +-
.../pom.xml | 62 +-
.../metrics/TimelineReaderMetrics.java | 5 +-
.../hadoop-yarn-server-web-proxy/pom.xml | 4 +-
.../hadoop-yarn/hadoop-yarn-server/pom.xml | 1 +
.../src/site/markdown/CapacityScheduler.md | 4 +-
.../site/markdown/DevelopYourOwnDevicePlugin.md | 2 +-
.../src/site/markdown/DockerContainers.md | 6 +-
.../src/site/markdown/GracefulDecommission.md | 4 +-
.../src/site/markdown/NodeManager.md | 2 +-
.../src/site/markdown/NodeManagerCGroupsMemory.md | 2 +-
.../src/site/markdown/PluggableDeviceFramework.md | 2 +-
.../src/site/markdown/ReservationSystem.md | 2 +-
.../src/site/markdown/ResourceModel.md | 2 +-
.../src/site/markdown/RuncContainers.md | 2 +-
.../src/site/markdown/TimelineServer.md | 6 +-
.../src/site/markdown/UsingGpus.md | 2 +-
.../src/site/markdown/WebServicesIntro.md | 6 +-
.../src/site/markdown/YarnApplicationSecurity.md | 2 +-
hadoop-yarn-project/pom.xml | 31 +-
283 files changed, 6185 insertions(+), 4183 deletions(-)
create mode 100644 dev-support/docker/pkg-resolver/install-pip.ps1
create mode 100644 dev-support/docker/pkg-resolver/install-python.ps1
delete mode 100644 hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestVectoredReadUtils.java
create mode 100644 hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/impl/TestVectoredReadUtils.java
create mode 100644 hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/contract/hdfs/TestHDFSContractVectoredRead.java
create mode 100644 hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/security/token/block/TestUpdateDataNodeCurrentKey.java
create mode 100644 hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCorrectnessOfQuotaAfterRenameOp.java
create mode 100644 hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/commit/magic/InMemoryMagicCommitTracker.java
create mode 100644 hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/commit/magic/MagicCommitTrackerUtils.java
copy hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/commit/magic/{MagicCommitTracker.java => S3MagicCommitTracker.java} (56%)
create mode 100644 hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/commit/TestMagicCommitTrackerUtils.java
create mode 100644 hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/contract/ITestAbfsFileSystemContractVectoredRead.java
create mode 100644 hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/AbfsInputStreamTestUtils.java
create mode 100644 hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsPaginatedDelete.java
delete mode 100644 hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase-tests/src/test/java/org/apache/hadoop/yarn/server/timelineservice/reader/DummyTimelineReaderMetrics.java
delete mode 100644 hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase/hadoop-yarn-server-timelineservice-hbase-server/hadoop-yarn-server-timelineservice-hbase-server-1/pom.xml
delete mode 100644 hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase/hadoop-yarn-server-timelineservice-hbase-server/hadoop-yarn-server-timelineservice-hbase-server-1/src/assembly/coprocessor.xml
delete mode 100644 hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase/hadoop-yarn-server-timelineservice-hbase-server/hadoop-yarn-server-timelineservice-hbase-server-1/src/main/java/org/apache/hadoop/yarn/server/timelineservice/storage/common/HBaseTimelineServerUtils.java
delete mode 100644 hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase/hadoop-yarn-server-timelineservice-hbase-server/hadoop-yarn-server-timelineservice-hbase-server-1/src/main/java/org/apache/hadoop/yarn/server/timelineservice/storage/common/package-info.java
delete mode 100644 hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase/hadoop-yarn-server-timelineservice-hbase-server/hadoop-yarn-server-timelineservice-hbase-server-1/src/main/java/org/apache/hadoop/yarn/server/timelineservice/storage/flow/FlowRunCoprocessor.java
delete mode 100644 hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase/hadoop-yarn-server-timelineservice-hbase-server/hadoop-yarn-server-timelineservice-hbase-server-1/src/main/java/org/apache/hadoop/yarn/server/timelineservice/storage/flow/FlowScanner.java
delete mode 100644 hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase/hadoop-yarn-server-timelineservice-hbase-server/hadoop-yarn-server-timelineservice-hbase-server-1/src/main/java/org/apache/hadoop/yarn/server/timelineservice/storage/flow/FlowScannerOperation.java
delete mode 100644 hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase/hadoop-yarn-server-timelineservice-hbase-server/hadoop-yarn-server-timelineservice-hbase-server-1/src/main/java/org/apache/hadoop/yarn/server/timelineservice/storage/flow/package-info.java
delete mode 100644 hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase/hadoop-yarn-server-timelineservice-hbase-server/hadoop-yarn-server-timelineservice-hbase-server-1/src/main/java/org/apache/hadoop/yarn/server/timelineservice/storage/package-info.java
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org
(hadoop) 17/23: HDFS-17389. [FGL] Client RPCs involving read process supports fine-grained lock (#6590)
Posted by za...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zanderxu pushed a commit to branch HDFS-17384
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit ee0beaee40b25202bca75b302a51a5aceef4ebd3
Author: ZanderXu <za...@apache.org>
AuthorDate: Fri Mar 29 18:18:14 2024 +0800
HDFS-17389. [FGL] Client RPCs involving read process supports fine-grained lock (#6590)
---
.../hadoop/hdfs/server/namenode/FSNamesystem.java | 50 +++++++++++-----------
.../hadoop/hdfs/server/namenode/LeaseManager.java | 3 +-
2 files changed, 27 insertions(+), 26 deletions(-)
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
index 8eefe98383ea..1899f1da2c9f 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
@@ -2047,7 +2047,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
BatchedListEntries<OpenFileEntry> batchedListEntries;
String normalizedPath = new Path(path).toString(); // normalize path.
try {
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.READ);
if (openFilesTypes.contains(OpenFilesType.ALL_OPEN_FILES)) {
@@ -2062,7 +2062,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
}
}
} finally {
- readUnlock(operationName, getLockReportInfoSupplier(null));
+ readUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(null));
}
} catch (AccessControlException e) {
logAuditEvent(false, operationName, null);
@@ -2074,7 +2074,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
public BatchedListEntries<OpenFileEntry> getFilesBlockingDecom(long prevId,
String path) {
- assert hasReadLock();
+ assert hasReadLock(FSNamesystemLockMode.FS);
final List<OpenFileEntry> openFileEntries = Lists.newArrayList();
LightWeightHashSet<Long> openFileIds = new LightWeightHashSet<>();
for (DatanodeDescriptor dataNode :
@@ -2214,7 +2214,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
FSPermissionChecker.setOperationType(operationName);
final INode inode;
try {
- readLock();
+ readLock(FSNamesystemLockMode.GLOBAL);
try {
checkOperation(OperationCategory.READ);
res = FSDirStatAndListingOp.getBlockLocations(
@@ -2239,7 +2239,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
checkBlockLocationsWhenObserver(res.blocks, srcArg);
}
} finally {
- readUnlock(operationName, getLockReportInfoSupplier(srcArg));
+ readUnlock(FSNamesystemLockMode.GLOBAL, operationName, getLockReportInfoSupplier(srcArg));
}
} catch (AccessControlException e) {
logAuditEvent(false, operationName, srcArg);
@@ -2252,7 +2252,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
String src = srcArg;
checkOperation(OperationCategory.WRITE);
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
final long now = now();
try {
checkOperation(OperationCategory.WRITE);
@@ -2269,7 +2269,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
}
}
} finally {
- writeUnlock(operationName, getLockReportInfoSupplier(srcArg));
+ writeUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(srcArg));
}
} catch (Throwable e) {
LOG.warn("Failed to update the access time of " + src, e);
@@ -2671,12 +2671,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
checkOperation(OperationCategory.READ);
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(null);
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.READ);
return FSDirAttrOp.getPreferredBlockSize(dir, pc, src);
} finally {
- readUnlock("getPreferredBlockSize");
+ readUnlock(FSNamesystemLockMode.FS, "getPreferredBlockSize");
}
}
@@ -3490,13 +3490,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
try {
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.READ);
stat = FSDirStatAndListingOp.getFileInfo(
dir, pc, src, resolveLink, needLocation, needBlockToken);
} finally {
- readUnlock(operationName, getLockReportInfoSupplier(src));
+ readUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(src));
}
} catch (AccessControlException e) {
logAuditEvent(false, operationName, src);
@@ -3520,12 +3520,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
FSPermissionChecker.setOperationType(operationName);
boolean success = false;
try {
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.READ);
success = FSDirStatAndListingOp.isFileClosed(dir, pc, src);
} finally {
- readUnlock(operationName, getLockReportInfoSupplier(src));
+ readUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(src));
}
} catch (AccessControlException e) {
logAuditEvent(false, operationName, src);
@@ -3588,12 +3588,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
try {
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.READ);
cs = FSDirStatAndListingOp.getContentSummary(dir, pc, src);
} finally {
- readUnlock(operationName, getLockReportInfoSupplier(src));
+ readUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(src));
}
} catch (AccessControlException ace) {
logAuditEvent(false, operationName, src);
@@ -4221,12 +4221,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
try {
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
checkOperation(NameNode.OperationCategory.READ);
dl = getListingInt(dir, pc, src, startAfter, needLocation);
} finally {
- readUnlock(operationName, getLockReportInfoSupplier(src));
+ readUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(src));
}
} catch (AccessControlException e) {
logAuditEvent(false, operationName, src);
@@ -4292,7 +4292,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
BatchedDirectoryListing bdl;
checkOperation(OperationCategory.READ);
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
checkOperation(NameNode.OperationCategory.READ);
@@ -4379,7 +4379,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
returnedStartAfter);
}
} finally {
- readUnlock(operationName,
+ readUnlock(FSNamesystemLockMode.FS, operationName,
getLockReportInfoSupplier(Arrays.toString(srcs)));
}
for (int i = startSrcsIndex; i < srcsIndex; i++) {
@@ -6229,7 +6229,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
return corruptFiles;
}
- readLock();
+ readLock(FSNamesystemLockMode.GLOBAL);
try {
checkOperation(OperationCategory.READ);
if (!blockManager.isPopulatingReplQueues()) {
@@ -6278,7 +6278,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
LOG.debug("list corrupt file blocks returned: {}", count);
return corruptFiles;
} finally {
- readUnlock("listCorruptFileBlocks");
+ readUnlock(FSNamesystemLockMode.GLOBAL, "listCorruptFileBlocks");
}
}
@@ -8155,14 +8155,14 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
keyName, src);
final FSPermissionChecker pc = getPermissionChecker();
checkOperation(OperationCategory.WRITE);
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot create encryption zone on " + src);
resultingStat = FSDirEncryptionZoneOp.createEncryptionZone(dir, src,
pc, metadata.getCipher(), keyName, logRetryCache);
} finally {
- writeUnlock(operationName,
+ writeUnlock(FSNamesystemLockMode.FS, operationName,
getLockReportInfoSupplier(src, null, resultingStat));
}
} catch (AccessControlException e) {
@@ -8760,7 +8760,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
try {
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.READ);
final INodesInPath iip = dir.resolvePath(pc, src, DirOp.READ);
@@ -8773,7 +8773,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
dir.checkPathAccess(pc, iip, mode);
}
} finally {
- readUnlock(operationName, getLockReportInfoSupplier(src));
+ readUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(src));
}
} catch (AccessControlException e) {
logAuditEvent(false, operationName, src);
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java
index b21a34a932af..c2e01ffe266f 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java
@@ -46,6 +46,7 @@ import org.apache.hadoop.hdfs.protocol.OpenFileEntry;
import org.apache.hadoop.hdfs.protocol.OpenFilesIterator;
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo;
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.util.Daemon;
import org.apache.hadoop.util.Lists;
import org.apache.hadoop.util.Time;
@@ -284,7 +285,7 @@ public class LeaseManager {
*/
public BatchedListEntries<OpenFileEntry> getUnderConstructionFiles(
final long prevId, final String path) throws IOException {
- assert fsnamesystem.hasReadLock();
+ assert fsnamesystem.hasReadLock(FSNamesystemLockMode.FS);
SortedMap<Long, Lease> remainingLeases;
synchronized (this) {
remainingLeases = leasesById.tailMap(prevId, false);
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org
(hadoop) 11/23: HDFS-17410. [FGL] Client RPCs that changes file attributes supports fine-grained lock (#6634)
Posted by za...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zanderxu pushed a commit to branch HDFS-17384
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit a55cd3bb9f45a3f2351f7c32f2cd3b4649c5f3cc
Author: ZanderXu <za...@apache.org>
AuthorDate: Wed Mar 27 09:41:17 2024 +0800
HDFS-17410. [FGL] Client RPCs that changes file attributes supports fine-grained lock (#6634)
---
.../namenode/ContentSummaryComputationContext.java | 9 +-
.../server/namenode/EncryptionZoneManager.java | 14 +--
.../server/namenode/FSDirEncryptionZoneOp.java | 7 +-
.../namenode/FSDirSatisfyStoragePolicyOp.java | 3 +-
.../hdfs/server/namenode/FSDirTruncateOp.java | 7 +-
.../hadoop/hdfs/server/namenode/FSNamesystem.java | 116 +++++++++++----------
.../hdfs/server/namenode/ReencryptionHandler.java | 11 +-
.../hdfs/server/namenode/ReencryptionUpdater.java | 7 +-
8 files changed, 92 insertions(+), 82 deletions(-)
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ContentSummaryComputationContext.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ContentSummaryComputationContext.java
index bbebe78fb1f6..c7b510eca565 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ContentSummaryComputationContext.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ContentSummaryComputationContext.java
@@ -17,6 +17,7 @@
*/
package org.apache.hadoop.hdfs.server.namenode;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.util.Preconditions;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
@@ -118,8 +119,8 @@ public class ContentSummaryComputationContext {
boolean hadDirReadLock = dir.hasReadLock();
boolean hadDirWriteLock = dir.hasWriteLock();
- boolean hadFsnReadLock = fsn.hasReadLock();
- boolean hadFsnWriteLock = fsn.hasWriteLock();
+ boolean hadFsnReadLock = fsn.hasReadLock(FSNamesystemLockMode.GLOBAL);
+ boolean hadFsnWriteLock = fsn.hasWriteLock(FSNamesystemLockMode.GLOBAL);
// sanity check.
if (!hadDirReadLock || !hadFsnReadLock || hadDirWriteLock ||
@@ -130,14 +131,14 @@ public class ContentSummaryComputationContext {
// unlock
dir.readUnlock();
- fsn.readUnlock("contentSummary");
+ fsn.readUnlock(FSNamesystemLockMode.GLOBAL, "contentSummary");
try {
Thread.sleep(sleepMilliSec, sleepNanoSec);
} catch (InterruptedException ie) {
} finally {
// reacquire
- fsn.readLock();
+ fsn.readLock(FSNamesystemLockMode.GLOBAL);
dir.readLock();
}
yieldCount++;
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java
index 7bf587997161..1f75a7734cb4 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java
@@ -48,6 +48,7 @@ import org.apache.hadoop.hdfs.protocol.ZoneReencryptionStatus;
import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos;
import org.apache.hadoop.hdfs.protocolPB.PBHelperClient;
import org.apache.hadoop.hdfs.server.namenode.FSDirectory.DirOp;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot;
import org.apache.hadoop.security.AccessControlException;
import org.apache.hadoop.util.Lists;
@@ -188,11 +189,12 @@ public class EncryptionZoneManager {
final int count) throws IOException {
INodesInPath iip;
final FSPermissionChecker pc = dir.getPermissionChecker();
- dir.getFSNamesystem().readLock();
+ dir.getFSNamesystem().readLock(FSNamesystemLockMode.FS);
try {
iip = dir.resolvePath(pc, zone, DirOp.READ);
} finally {
- dir.getFSNamesystem().readUnlock("pauseForTestingAfterNthCheckpoint");
+ dir.getFSNamesystem().readUnlock(
+ FSNamesystemLockMode.FS, "pauseForTestingAfterNthCheckpoint");
}
reencryptionHandler
.pauseForTestingAfterNthCheckpoint(iip.getLastINode().getId(), count);
@@ -213,7 +215,7 @@ public class EncryptionZoneManager {
throws IOException {
final FSPermissionChecker pc = dir.getPermissionChecker();
final INode inode;
- dir.getFSNamesystem().readLock();
+ dir.getFSNamesystem().readLock(FSNamesystemLockMode.FS);
dir.readLock();
try {
final INodesInPath iip = dir.resolvePath(pc, zone, DirOp.READ);
@@ -224,7 +226,7 @@ public class EncryptionZoneManager {
return getReencryptionStatus().getZoneStatus(inode.getId());
} finally {
dir.readUnlock();
- dir.getFSNamesystem().readUnlock("getZoneStatus");
+ dir.getFSNamesystem().readUnlock(FSNamesystemLockMode.FS, "getZoneStatus");
}
}
@@ -281,11 +283,11 @@ public class EncryptionZoneManager {
if (getProvider() == null || reencryptionHandler == null) {
return;
}
- dir.getFSNamesystem().writeLock();
+ dir.getFSNamesystem().writeLock(FSNamesystemLockMode.FS);
try {
reencryptionHandler.stopThreads();
} finally {
- dir.getFSNamesystem().writeUnlock("stopReencryptThread");
+ dir.getFSNamesystem().writeUnlock(FSNamesystemLockMode.FS, "stopReencryptThread");
}
if (reencryptHandlerExecutor != null) {
reencryptHandlerExecutor.shutdownNow();
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirEncryptionZoneOp.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirEncryptionZoneOp.java
index 2110a408b087..9520139577ba 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirEncryptionZoneOp.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirEncryptionZoneOp.java
@@ -50,6 +50,7 @@ import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.ZoneEncryptionInfoProto;
import org.apache.hadoop.hdfs.protocolPB.PBHelperClient;
import org.apache.hadoop.hdfs.server.namenode.FSDirectory.DirOp;
import org.apache.hadoop.hdfs.server.namenode.ReencryptionUpdater.FileEdekInfo;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.security.SecurityUtil;
import org.apache.hadoop.util.Lists;
import org.apache.hadoop.util.Time;
@@ -382,7 +383,7 @@ final class FSDirEncryptionZoneOp {
*/
static void saveFileXAttrsForBatch(FSDirectory fsd,
List<FileEdekInfo> batch) {
- assert fsd.getFSNamesystem().hasWriteLock();
+ assert fsd.getFSNamesystem().hasWriteLock(FSNamesystemLockMode.FS);
if (batch != null && !batch.isEmpty()) {
for (FileEdekInfo entry : batch) {
final INode inode = fsd.getInode(entry.getInodeId());
@@ -727,13 +728,13 @@ final class FSDirEncryptionZoneOp {
final FSPermissionChecker pc, final String zone) throws IOException {
assert dir.getProvider() != null;
final INodesInPath iip;
- dir.getFSNamesystem().readLock();
+ dir.getFSNamesystem().readLock(FSNamesystemLockMode.FS);
try {
iip = dir.resolvePath(pc, zone, DirOp.READ);
dir.ezManager.checkEncryptionZoneRoot(iip.getLastINode(), zone);
return dir.ezManager.getKeyName(iip);
} finally {
- dir.getFSNamesystem().readUnlock("getKeyNameForZone");
+ dir.getFSNamesystem().readUnlock(FSNamesystemLockMode.FS, "getKeyNameForZone");
}
}
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirSatisfyStoragePolicyOp.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirSatisfyStoragePolicyOp.java
index 81b21964712f..76180b737055 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirSatisfyStoragePolicyOp.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirSatisfyStoragePolicyOp.java
@@ -31,6 +31,7 @@ import org.apache.hadoop.fs.permission.FsAction;
import org.apache.hadoop.hdfs.XAttrHelper;
import org.apache.hadoop.hdfs.server.blockmanagement.BlockManager;
import org.apache.hadoop.hdfs.server.namenode.FSDirectory.DirOp;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.namenode.sps.StoragePolicySatisfyManager;
import org.apache.hadoop.util.Lists;
@@ -64,7 +65,7 @@ final class FSDirSatisfyStoragePolicyOp {
static FileStatus satisfyStoragePolicy(FSDirectory fsd, BlockManager bm,
String src, boolean logRetryCache) throws IOException {
- assert fsd.getFSNamesystem().hasWriteLock();
+ assert fsd.getFSNamesystem().hasWriteLock(FSNamesystemLockMode.FS);
FSPermissionChecker pc = fsd.getPermissionChecker();
INodesInPath iip;
fsd.writeLock();
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirTruncateOp.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirTruncateOp.java
index 337062ec02af..e956f9ca7116 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirTruncateOp.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirTruncateOp.java
@@ -40,6 +40,7 @@ import org.apache.hadoop.hdfs.server.namenode.FSNamesystem.RecoverLeaseOp;
import org.apache.hadoop.hdfs.server.namenode.INode.BlocksMapUpdateInfo;
import org.apache.hadoop.classification.VisibleForTesting;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
/**
* Helper class to perform truncate operation.
@@ -71,7 +72,7 @@ final class FSDirTruncateOp {
final String clientMachine, final long mtime,
final BlocksMapUpdateInfo toRemoveBlocks, final FSPermissionChecker pc)
throws IOException, UnresolvedLinkException {
- assert fsn.hasWriteLock();
+ assert fsn.hasWriteLock(FSNamesystemLockMode.GLOBAL);
FSDirectory fsd = fsn.getFSDirectory();
final String src;
@@ -219,7 +220,7 @@ final class FSDirTruncateOp {
static Block prepareFileForTruncate(FSNamesystem fsn, INodesInPath iip,
String leaseHolder, String clientMachine, long lastBlockDelta,
Block newBlock) throws IOException {
- assert fsn.hasWriteLock();
+ assert fsn.hasWriteLock(FSNamesystemLockMode.GLOBAL);
INodeFile file = iip.getLastINode().asFile();
assert !file.isStriped();
@@ -303,7 +304,7 @@ final class FSDirTruncateOp {
private static boolean unprotectedTruncate(FSNamesystem fsn,
INodesInPath iip, long newLength, BlocksMapUpdateInfo collectedBlocks,
long mtime, QuotaCounts delta) throws IOException {
- assert fsn.hasWriteLock();
+ assert fsn.hasWriteLock(FSNamesystemLockMode.GLOBAL);
INodeFile file = iip.getLastINode().asFile();
int latestSnapshot = iip.getLatestSnapshotId();
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
index f23db6e0f3a8..dbb5cfbf1951 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
@@ -2150,13 +2150,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot set permission for " + src);
auditStat = FSDirAttrOp.setPermission(dir, pc, src, permission);
} finally {
- writeUnlock(operationName,
+ writeUnlock(FSNamesystemLockMode.FS, operationName,
getLockReportInfoSupplier(src, null, auditStat));
}
} catch (AccessControlException e) {
@@ -2182,13 +2182,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot set owner for " + src);
auditStat = FSDirAttrOp.setOwner(dir, pc, src, username, group);
} finally {
- writeUnlock(operationName,
+ writeUnlock(FSNamesystemLockMode.FS, operationName,
getLockReportInfoSupplier(src, null, auditStat));
}
} catch (AccessControlException e) {
@@ -2318,13 +2318,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
checkOperation(OperationCategory.WRITE);
String srcsStr = Arrays.toString(srcs);
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.GLOBAL);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot concat " + target);
stat = FSDirConcatOp.concat(dir, pc, target, srcs, logRetryCache);
} finally {
- writeUnlock(operationName,
+ writeUnlock(FSNamesystemLockMode.GLOBAL, operationName,
getLockReportInfoSupplier(srcsStr, target, stat));
}
} catch (AccessControlException ace) {
@@ -2347,13 +2347,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot set times " + src);
auditStat = FSDirAttrOp.setTimes(dir, pc, src, mtime, atime);
} finally {
- writeUnlock(operationName,
+ writeUnlock(FSNamesystemLockMode.FS, operationName,
getLockReportInfoSupplier(src, null, auditStat));
}
} catch (AccessControlException e) {
@@ -2391,7 +2391,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
checkOperation(OperationCategory.WRITE);
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
- writeLock();
+ writeLock(FSNamesystemLockMode.GLOBAL);
BlocksMapUpdateInfo toRemoveBlocks = new BlocksMapUpdateInfo();
try {
checkOperation(OperationCategory.WRITE);
@@ -2400,7 +2400,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
clientMachine, mtime, toRemoveBlocks, pc);
} finally {
status = r != null ? r.getFileStatus() : null;
- writeUnlock(operationName,
+ writeUnlock(FSNamesystemLockMode.GLOBAL, operationName,
getLockReportInfoSupplier(src, null, status));
}
getEditLog().logSync();
@@ -2471,14 +2471,14 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.GLOBAL);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot set replication for " + src);
success = FSDirAttrOp.setReplication(dir, pc, blockManager, src,
replication);
} finally {
- writeUnlock(operationName, getLockReportInfoSupplier(src));
+ writeUnlock(FSNamesystemLockMode.GLOBAL, operationName, getLockReportInfoSupplier(src));
}
} catch (AccessControlException e) {
logAuditEvent(false, operationName, src);
@@ -2531,14 +2531,14 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
FSPermissionChecker.setOperationType(operationName);
FileStatus auditStat = null;
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot set storage policy for " + src);
auditStat = FSDirAttrOp.setStoragePolicy(dir, pc, blockManager, src,
policyName);
} finally {
- writeUnlock(operationName,
+ writeUnlock(FSNamesystemLockMode.FS, operationName,
getLockReportInfoSupplier(src, null, auditStat));
}
} catch (AccessControlException e) {
@@ -2565,14 +2565,14 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
FileStatus auditStat = null;
validateStoragePolicySatisfy();
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot satisfy storage policy for " + src);
auditStat = FSDirSatisfyStoragePolicyOp.satisfyStoragePolicy(
dir, blockManager, src, logRetryCache);
} finally {
- writeUnlock(operationName,
+ writeUnlock(FSNamesystemLockMode.FS, operationName,
getLockReportInfoSupplier(src, null, auditStat));
}
} catch (AccessControlException e) {
@@ -2613,13 +2613,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
FSPermissionChecker.setOperationType(operationName);
FileStatus auditStat = null;
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot unset storage policy for " + src);
auditStat = FSDirAttrOp.unsetStoragePolicy(dir, pc, blockManager, src);
} finally {
- writeUnlock(operationName,
+ writeUnlock(FSNamesystemLockMode.FS, operationName,
getLockReportInfoSupplier(src, null, auditStat));
}
} catch (AccessControlException e) {
@@ -2641,12 +2641,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
checkOperation(OperationCategory.READ);
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(null);
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.READ);
return FSDirAttrOp.getStoragePolicy(dir, pc, blockManager, src);
} finally {
- readUnlock("getStoragePolicy");
+ readUnlock(FSNamesystemLockMode.FS, "getStoragePolicy");
}
}
@@ -2656,12 +2656,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
*/
BlockStoragePolicy[] getStoragePolicies() throws IOException {
checkOperation(OperationCategory.READ);
- readLock();
+ readLock(FSNamesystemLockMode.BM);
try {
checkOperation(OperationCategory.READ);
return FSDirAttrOp.getStoragePolicies(blockManager);
} finally {
- readUnlock("getStoragePolicies");
+ readUnlock(FSNamesystemLockMode.BM, "getStoragePolicies");
}
}
@@ -2925,7 +2925,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
boolean recoverLeaseInternal(RecoverLeaseOp op, INodesInPath iip,
String src, String holder, String clientMachine, boolean force)
throws IOException {
- assert hasWriteLock();
+ assert hasWriteLock(FSNamesystemLockMode.GLOBAL);
INodeFile file = iip.getLastINode().asFile();
if (file.isUnderConstruction()) {
//
@@ -3267,7 +3267,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
* @param blockType is the file under striping or contiguous layout?
*/
Block createNewBlock(BlockType blockType) throws IOException {
- assert hasWriteLock();
+ assert hasWriteLock(FSNamesystemLockMode.GLOBAL);
Block b = new Block(nextBlockId(blockType), 0, 0);
// Increment the generation stamp for every new block.
b.setGenerationStamp(nextGenerationStamp(false));
@@ -3620,12 +3620,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
try {
- readLock();
+ readLock(FSNamesystemLockMode.GLOBAL);
try {
checkOperation(OperationCategory.READ);
quotaUsage = FSDirStatAndListingOp.getQuotaUsage(dir, pc, src);
} finally {
- readUnlock(operationName, getLockReportInfoSupplier(src));
+ readUnlock(FSNamesystemLockMode.GLOBAL, operationName, getLockReportInfoSupplier(src));
}
} catch (AccessControlException ace) {
logAuditEvent(false, operationName, src);
@@ -3658,14 +3658,15 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
checkSuperuserPrivilege(operationName, src);
}
try {
- writeLock();
+ // Need to compute the curren space usage
+ writeLock(FSNamesystemLockMode.GLOBAL);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot set quota on " + src);
FSDirAttrOp.setQuota(dir, pc, src, nsQuota, ssQuota, type,
allowOwnerSetQuota);
} finally {
- writeUnlock(operationName, getLockReportInfoSupplier(src));
+ writeUnlock(FSNamesystemLockMode.GLOBAL, operationName, getLockReportInfoSupplier(src));
}
} catch (AccessControlException ace) {
logAuditEvent(false, operationName, src);
@@ -5855,7 +5856,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
*/
long nextGenerationStamp(boolean legacyBlock)
throws IOException {
- assert hasWriteLock();
+ assert hasWriteLock(FSNamesystemLockMode.GLOBAL);
checkNameNodeSafeMode("Cannot get next generation stamp");
long gs = blockManager.nextGenerationStamp(legacyBlock);
@@ -7987,13 +7988,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot modify ACL entries on " + src);
auditStat = FSDirAclOp.modifyAclEntries(dir, pc, src, aclSpec);
} finally {
- writeUnlock(operationName,
+ writeUnlock(FSNamesystemLockMode.FS, operationName,
getLockReportInfoSupplier(src, null, auditStat));
}
} catch (AccessControlException e) {
@@ -8012,13 +8013,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot remove ACL entries on " + src);
auditStat = FSDirAclOp.removeAclEntries(dir, pc, src, aclSpec);
} finally {
- writeUnlock(operationName,
+ writeUnlock(FSNamesystemLockMode.FS, operationName,
getLockReportInfoSupplier(src, null, auditStat));
}
} catch (AccessControlException e) {
@@ -8036,13 +8037,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot remove default ACL entries on " + src);
auditStat = FSDirAclOp.removeDefaultAcl(dir, pc, src);
} finally {
- writeUnlock(operationName,
+ writeUnlock(FSNamesystemLockMode.FS, operationName,
getLockReportInfoSupplier(src, null, auditStat));
}
} catch (AccessControlException e) {
@@ -8060,13 +8061,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot remove ACL on " + src);
auditStat = FSDirAclOp.removeAcl(dir, pc, src);
} finally {
- writeUnlock(operationName,
+ writeUnlock(FSNamesystemLockMode.FS, operationName,
getLockReportInfoSupplier(src, null, auditStat));
}
} catch (AccessControlException e) {
@@ -8084,13 +8085,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot set ACL on " + src);
auditStat = FSDirAclOp.setAcl(dir, pc, src, aclSpec);
} finally {
- writeUnlock(operationName,
+ writeUnlock(FSNamesystemLockMode.FS, operationName,
getLockReportInfoSupplier(src, null, auditStat));
}
} catch (AccessControlException e) {
@@ -8108,12 +8109,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
try {
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.READ);
ret = FSDirAclOp.getAclStatus(dir, pc, src);
} finally {
- readUnlock(operationName, getLockReportInfoSupplier(src));
+ readUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(src));
}
} catch(AccessControlException ace) {
logAuditEvent(false, operationName, src);
@@ -8180,7 +8181,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
FSPermissionChecker.setOperationType(operationName);
checkOperation(OperationCategory.READ);
try {
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.READ);
Entry<EncryptionZone, FileStatus> ezForPath = FSDirEncryptionZoneOp
@@ -8188,7 +8189,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
resultingStat = ezForPath.getValue();
encryptionZone = ezForPath.getKey();
} finally {
- readUnlock(operationName,
+ readUnlock(FSNamesystemLockMode.FS, operationName,
getLockReportInfoSupplier(srcArg, null, resultingStat));
}
} catch (AccessControlException ace) {
@@ -8205,7 +8206,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
boolean success = false;
checkOperation(OperationCategory.READ);
checkSuperuserPrivilege(operationName, dir.rootDir.getFullPathName());
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.READ);
final BatchedListEntries<EncryptionZone> ret =
@@ -8213,7 +8214,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
success = true;
return ret;
} finally {
- readUnlock(operationName, getLockReportInfoSupplier(null));
+ readUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(null));
logAuditEvent(success, operationName, null);
}
}
@@ -8242,7 +8243,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
boolean success = false;
checkOperation(OperationCategory.READ);
checkSuperuserPrivilege(operationName, dir.rootDir.getFullPathName());
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.READ);
final BatchedListEntries<ZoneReencryptionStatus> ret =
@@ -8250,7 +8251,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
success = true;
return ret;
} finally {
- readUnlock(operationName, getLockReportInfoSupplier(null));
+ readUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(null));
logAuditEvent(success, operationName, null);
}
}
@@ -8273,7 +8274,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
LOG.info("Re-encryption using key version " + keyVersionName
+ " for zone " + zone);
}
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("NameNode in safemode, cannot " + action
@@ -8305,7 +8306,8 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
getEditLog().logSetXAttrs(zone, xattrs, logRetryCache);
}
} finally {
- writeUnlock(action + "reencryption", getLockReportInfoSupplier(zone));
+ writeUnlock(FSNamesystemLockMode.FS,
+ action + "reencryption", getLockReportInfoSupplier(zone));
}
getEditLog().logSync();
}
@@ -8631,14 +8633,14 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot set XAttr on " + src);
auditStat = FSDirXAttrOp.setXAttr(dir, pc, src, xAttr, flag,
logRetryCache);
} finally {
- writeUnlock(operationName,
+ writeUnlock(FSNamesystemLockMode.FS, operationName,
getLockReportInfoSupplier(src, null, auditStat));
}
} catch (AccessControlException e) {
@@ -8657,12 +8659,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
try {
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.READ);
fsXattrs = FSDirXAttrOp.getXAttrs(dir, pc, src, xAttrs);
} finally {
- readUnlock(operationName, getLockReportInfoSupplier(src));
+ readUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(src));
}
} catch (AccessControlException e) {
logAuditEvent(false, operationName, src);
@@ -8679,12 +8681,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
try {
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.READ);
fsXattrs = FSDirXAttrOp.listXAttrs(dir, pc, src);
} finally {
- readUnlock(operationName, getLockReportInfoSupplier(src));
+ readUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(src));
}
} catch (AccessControlException e) {
logAuditEvent(false, operationName, src);
@@ -8702,14 +8704,14 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot remove XAttr entry on " + src);
auditStat = FSDirXAttrOp.removeXAttr(dir, pc, src, xAttr,
logRetryCache);
} finally {
- writeUnlock(operationName,
+ writeUnlock(FSNamesystemLockMode.FS, operationName,
getLockReportInfoSupplier(src, null, auditStat));
}
} catch (AccessControlException e) {
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ReencryptionHandler.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ReencryptionHandler.java
index 2a7002b5cd2f..860bc7e56695 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ReencryptionHandler.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ReencryptionHandler.java
@@ -18,6 +18,7 @@
package org.apache.hadoop.hdfs.server.namenode;
import org.apache.hadoop.classification.VisibleForTesting;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.util.Preconditions;
import org.apache.hadoop.thirdparty.com.google.common.util.concurrent.ThreadFactoryBuilder;
@@ -338,7 +339,7 @@ public class ReencryptionHandler implements Runnable {
}
final Long zoneId;
- dir.getFSNamesystem().readLock();
+ dir.getFSNamesystem().readLock(FSNamesystemLockMode.FS);
try {
zoneId = getReencryptionStatus().getNextUnprocessedZone();
if (zoneId == null) {
@@ -350,7 +351,7 @@ public class ReencryptionHandler implements Runnable {
getReencryptionStatus().markZoneStarted(zoneId);
resetSubmissionTracker(zoneId);
} finally {
- dir.getFSNamesystem().readUnlock("reEncryptThread");
+ dir.getFSNamesystem().readUnlock(FSNamesystemLockMode.FS, "reEncryptThread");
}
try {
@@ -442,7 +443,7 @@ public class ReencryptionHandler implements Runnable {
List<XAttr> completeReencryption(final INode zoneNode) throws IOException {
assert dir.hasWriteLock();
- assert dir.getFSNamesystem().hasWriteLock();
+ assert dir.getFSNamesystem().hasWriteLock(FSNamesystemLockMode.FS);
final Long zoneId = zoneNode.getId();
ZoneReencryptionStatus zs = getReencryptionStatus().getZoneStatus(zoneId);
assert zs != null;
@@ -613,7 +614,7 @@ public class ReencryptionHandler implements Runnable {
protected void checkPauseForTesting()
throws InterruptedException {
assert !dir.hasReadLock();
- assert !dir.getFSNamesystem().hasReadLock();
+ assert !dir.getFSNamesystem().hasReadLock(FSNamesystemLockMode.FS);
while (shouldPauseForTesting) {
LOG.info("Sleeping in the re-encrypt handler for unit test.");
synchronized (reencryptionHandler) {
@@ -747,7 +748,7 @@ public class ReencryptionHandler implements Runnable {
@Override
protected void throttle() throws InterruptedException {
assert !dir.hasReadLock();
- assert !dir.getFSNamesystem().hasReadLock();
+ assert !dir.getFSNamesystem().hasReadLock(FSNamesystemLockMode.FS);
final int numCores = Runtime.getRuntime().availableProcessors();
if (taskQueue.size() >= numCores) {
LOG.debug("Re-encryption handler throttling because queue size {} is"
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ReencryptionUpdater.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ReencryptionUpdater.java
index 43684a7acccc..dc90817f2ada 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ReencryptionUpdater.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ReencryptionUpdater.java
@@ -25,6 +25,7 @@ import org.apache.hadoop.fs.XAttr;
import org.apache.hadoop.fs.XAttrSetFlag;
import org.apache.hadoop.hdfs.protocol.ZoneReencryptionStatus;
import org.apache.hadoop.hdfs.server.namenode.ReencryptionHandler.ReencryptionBatch;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.ipc.RetriableException;
import org.apache.hadoop.util.Lists;
import org.apache.hadoop.util.StopWatch;
@@ -434,7 +435,7 @@ public final class ReencryptionUpdater implements Runnable {
boolean shouldRetry;
do {
- dir.getFSNamesystem().writeLock();
+ dir.getFSNamesystem().writeLock(FSNamesystemLockMode.FS);
try {
throttleTimerLocked.start();
processTask(task);
@@ -452,7 +453,7 @@ public final class ReencryptionUpdater implements Runnable {
task.processed = true;
shouldRetry = false;
} finally {
- dir.getFSNamesystem().writeUnlock("reencryptUpdater");
+ dir.getFSNamesystem().writeUnlock(FSNamesystemLockMode.FS, "reencryptUpdater");
throttleTimerLocked.stop();
}
// logSync regardless, to prevent edit log buffer overflow triggering
@@ -500,7 +501,7 @@ public final class ReencryptionUpdater implements Runnable {
private synchronized void checkPauseForTesting() throws InterruptedException {
assert !dir.hasWriteLock();
- assert !dir.getFSNamesystem().hasWriteLock();
+ assert !dir.getFSNamesystem().hasWriteLock(FSNamesystemLockMode.FS);
if (pauseAfterNthCheckpoint != 0) {
ZoneSubmissionTracker tracker =
handler.unprotectedGetTracker(pauseZoneId);
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org
(hadoop) 06/23: HDFS-17395. [FGL] Use FSLock to protect ErasureCodingPolicy related operations (#6579)
Posted by za...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zanderxu pushed a commit to branch HDFS-17384
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit 19f2c773df45b103bdefe75dc3614343e908515e
Author: ZanderXu <za...@apache.org>
AuthorDate: Thu Mar 7 14:07:27 2024 +0800
HDFS-17395. [FGL] Use FSLock to protect ErasureCodingPolicy related operations (#6579)
---
.../hdfs/server/namenode/FSDirErasureCodingOp.java | 15 ++++----
.../hadoop/hdfs/server/namenode/FSNamesystem.java | 42 +++++++++++-----------
2 files changed, 30 insertions(+), 27 deletions(-)
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirErasureCodingOp.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirErasureCodingOp.java
index 6628b56a132e..6237862ed4bb 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirErasureCodingOp.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirErasureCodingOp.java
@@ -28,6 +28,7 @@ import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy;
import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicyInfo;
import org.apache.hadoop.hdfs.protocol.NoECPolicySetException;
import org.apache.hadoop.hdfs.server.namenode.FSDirectory.DirOp;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.io.WritableUtils;
import org.apache.hadoop.io.erasurecode.CodecRegistry;
@@ -71,7 +72,7 @@ final class FSDirErasureCodingOp {
*/
static ErasureCodingPolicy getEnabledErasureCodingPolicyByName(
final FSNamesystem fsn, final String ecPolicyName) throws IOException {
- assert fsn.hasReadLock();
+ assert fsn.hasReadLock(FSNamesystemLockMode.FS);
ErasureCodingPolicy ecPolicy = fsn.getErasureCodingPolicyManager()
.getEnabledPolicyByName(ecPolicyName);
if (ecPolicy == null) {
@@ -103,7 +104,7 @@ final class FSDirErasureCodingOp {
*/
static ErasureCodingPolicy getErasureCodingPolicyByName(
final FSNamesystem fsn, final String ecPolicyName) throws IOException {
- assert fsn.hasReadLock();
+ assert fsn.hasReadLock(FSNamesystemLockMode.FS);
ErasureCodingPolicy ecPolicy = fsn.getErasureCodingPolicyManager()
.getErasureCodingPolicyByName(ecPolicyName);
if (ecPolicy == null) {
@@ -132,7 +133,7 @@ final class FSDirErasureCodingOp {
final String srcArg, final String ecPolicyName,
final FSPermissionChecker pc, final boolean logRetryCache)
throws IOException, AccessControlException {
- assert fsn.hasWriteLock();
+ assert fsn.hasWriteLock(FSNamesystemLockMode.FS);
String src = srcArg;
FSDirectory fsd = fsn.getFSDirectory();
@@ -209,7 +210,7 @@ final class FSDirErasureCodingOp {
static FileStatus unsetErasureCodingPolicy(final FSNamesystem fsn,
final String srcArg, final FSPermissionChecker pc,
final boolean logRetryCache) throws IOException {
- assert fsn.hasWriteLock();
+ assert fsn.hasWriteLock(FSNamesystemLockMode.FS);
String src = srcArg;
FSDirectory fsd = fsn.getFSDirectory();
@@ -353,7 +354,7 @@ final class FSDirErasureCodingOp {
static ErasureCodingPolicy getErasureCodingPolicy(final FSNamesystem fsn,
final String src, FSPermissionChecker pc)
throws IOException, AccessControlException {
- assert fsn.hasReadLock();
+ assert fsn.hasReadLock(FSNamesystemLockMode.FS);
if (FSDirectory.isExactReservedName(src)) {
return null;
@@ -416,7 +417,7 @@ final class FSDirErasureCodingOp {
*/
static ErasureCodingPolicy unprotectedGetErasureCodingPolicy(
final FSNamesystem fsn, final INodesInPath iip) throws IOException {
- assert fsn.hasReadLock();
+ assert fsn.hasReadLock(FSNamesystemLockMode.FS);
return getErasureCodingPolicyForPath(fsn.getFSDirectory(), iip);
}
@@ -441,7 +442,7 @@ final class FSDirErasureCodingOp {
*/
static Map<String, String> getErasureCodingCodecs(final FSNamesystem fsn)
throws IOException {
- assert fsn.hasReadLock();
+ assert fsn.hasReadLock(FSNamesystemLockMode.FS);
return CodecRegistry.getInstance().getCodec2CoderCompactMap();
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
index e5372bf1981b..ef6f922c7480 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
@@ -8322,7 +8322,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
FileStatus resultingStat = null;
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot set erasure coding policy on " + srcArg);
@@ -8332,7 +8332,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
logAuditEvent(false, operationName, srcArg);
throw ace;
} finally {
- writeUnlock(operationName,
+ writeUnlock(FSNamesystemLockMode.FS, operationName,
getLockReportInfoSupplier(srcArg, null, resultingStat));
}
getEditLog().logSync();
@@ -8355,7 +8355,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
checkErasureCodingSupported(operationName);
List<AddErasureCodingPolicyResponse> responses =
new ArrayList<>(policies.length);
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot add erasure coding policy");
@@ -8371,7 +8371,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
}
}
} finally {
- writeUnlock(operationName,
+ writeUnlock(FSNamesystemLockMode.FS, operationName,
getLockReportInfoSupplier(addECPolicyNames.toString()));
}
getEditLog().logSync();
@@ -8391,7 +8391,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final String operationName = "removeErasureCodingPolicy";
checkOperation(OperationCategory.WRITE);
checkErasureCodingSupported(operationName);
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot remove erasure coding policy "
@@ -8399,7 +8399,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
FSDirErasureCodingOp.removeErasureCodingPolicy(this, ecPolicyName,
logRetryCache);
} finally {
- writeUnlock(operationName, getLockReportInfoSupplier(ecPolicyName));
+ writeUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(ecPolicyName));
}
getEditLog().logSync();
logAuditEvent(true, operationName, ecPolicyName, null, null);
@@ -8420,7 +8420,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
checkErasureCodingSupported(operationName);
boolean success = false;
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot enable erasure coding policy "
@@ -8428,7 +8428,8 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
success = FSDirErasureCodingOp.enableErasureCodingPolicy(this,
ecPolicyName, logRetryCache);
} finally {
- writeUnlock(operationName, getLockReportInfoSupplier(ecPolicyName));
+ writeUnlock(FSNamesystemLockMode.FS, operationName,
+ getLockReportInfoSupplier(ecPolicyName));
}
} catch (AccessControlException ace) {
logAuditEvent(false, operationName, ecPolicyName);
@@ -8455,7 +8456,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
checkErasureCodingSupported(operationName);
boolean success = false;
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot disable erasure coding policy "
@@ -8463,7 +8464,8 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
success = FSDirErasureCodingOp.disableErasureCodingPolicy(this,
ecPolicyName, logRetryCache);
} finally {
- writeUnlock(operationName, getLockReportInfoSupplier(ecPolicyName));
+ writeUnlock(FSNamesystemLockMode.FS, operationName,
+ getLockReportInfoSupplier(ecPolicyName));
}
} catch (AccessControlException ace) {
logAuditEvent(false, operationName, ecPolicyName);
@@ -8492,14 +8494,14 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
FileStatus resultingStat = null;
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot unset erasure coding policy on " + srcArg);
resultingStat = FSDirErasureCodingOp.unsetErasureCodingPolicy(this,
srcArg, pc, logRetryCache);
} finally {
- writeUnlock(operationName,
+ writeUnlock(FSNamesystemLockMode.FS, operationName,
getLockReportInfoSupplier(srcArg, null, resultingStat));
}
getEditLog().logSync();
@@ -8519,7 +8521,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
checkSuperuserPrivilege(operationName);
checkOperation(OperationCategory.UNCHECKED);
ECTopologyVerifierResult result;
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.UNCHECKED);
// If no policy name is specified return the result
@@ -8542,7 +8544,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
.getECTopologyVerifierResult(numOfRacks, numOfDataNodes, policies);
}
} finally {
- readUnlock(operationName, getLockReportInfoSupplier(null));
+ readUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(null));
}
logAuditEvent(true, operationName, null);
return result;
@@ -8559,7 +8561,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
checkErasureCodingSupported(operationName);
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.READ);
final ErasureCodingPolicy ret =
@@ -8567,7 +8569,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
success = true;
return ret;
} finally {
- readUnlock(operationName, getLockReportInfoSupplier(src));
+ readUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(src));
logAuditEvent(success, operationName, src);
}
}
@@ -8580,7 +8582,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
boolean success = false;
checkOperation(OperationCategory.READ);
checkErasureCodingSupported(operationName);
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.READ);
final ErasureCodingPolicyInfo[] ret =
@@ -8588,7 +8590,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
success = true;
return ret;
} finally {
- readUnlock(operationName, getLockReportInfoSupplier(null));
+ readUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(null));
logAuditEvent(success, operationName, null);
}
}
@@ -8601,7 +8603,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
boolean success = false;
checkOperation(OperationCategory.READ);
checkErasureCodingSupported(operationName);
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.READ);
final Map<String, String> ret =
@@ -8609,7 +8611,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
success = true;
return ret;
} finally {
- readUnlock(operationName, getLockReportInfoSupplier(null));
+ readUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(null));
logAuditEvent(success, operationName, null);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org
(hadoop) 18/23: HDFS-17411. [FGL] Client RPCs involving snapshot support fine-grained lock (#6714)
Posted by za...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zanderxu pushed a commit to branch HDFS-17384
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit 4f7160853c7c538bf5ef36aedfd3b6bdc3c46724
Author: ZanderXu <za...@apache.org>
AuthorDate: Tue Apr 9 09:35:36 2024 +0800
HDFS-17411. [FGL] Client RPCs involving snapshot support fine-grained lock (#6714)
---
.../hadoop/hdfs/server/namenode/FSNamesystem.java | 45 ++++++++++++----------
.../namenode/snapshot/SnapshotDeletionGc.java | 5 ++-
.../hdfs/server/namenode/TestLeaseManager.java | 3 ++
3 files changed, 30 insertions(+), 23 deletions(-)
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
index 1899f1da2c9f..92865b1a7e60 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
@@ -7164,13 +7164,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
checkOperation(OperationCategory.WRITE);
final String operationName = "allowSnapshot";
checkSuperuserPrivilege(operationName, path);
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot allow snapshot for " + path);
FSDirSnapshotOp.allowSnapshot(dir, snapshotManager, path);
} finally {
- writeUnlock(operationName, getLockReportInfoSupplier(path));
+ writeUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(path));
}
getEditLog().logSync();
logAuditEvent(true, operationName, path, null, null);
@@ -7181,13 +7181,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
checkOperation(OperationCategory.WRITE);
final String operationName = "disallowSnapshot";
checkSuperuserPrivilege(operationName, path);
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot disallow snapshot for " + path);
FSDirSnapshotOp.disallowSnapshot(dir, snapshotManager, path);
} finally {
- writeUnlock(operationName, getLockReportInfoSupplier(path));
+ writeUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(path));
}
getEditLog().logSync();
logAuditEvent(true, operationName, path, null, null);
@@ -7206,14 +7206,15 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot create snapshot for " + snapshotRoot);
snapshotPath = FSDirSnapshotOp.createSnapshot(dir, pc,
snapshotManager, snapshotRoot, snapshotName, logRetryCache);
} finally {
- writeUnlock(operationName, getLockReportInfoSupplier(snapshotRoot));
+ writeUnlock(FSNamesystemLockMode.FS, operationName,
+ getLockReportInfoSupplier(snapshotRoot));
}
} catch (AccessControlException ace) {
logAuditEvent(false, operationName, snapshotRoot);
@@ -7243,15 +7244,15 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot rename snapshot for " + path);
FSDirSnapshotOp.renameSnapshot(dir, pc, snapshotManager, path,
snapshotOldName, snapshotNewName, logRetryCache);
} finally {
- writeUnlock(operationName, getLockReportInfoSupplier(oldSnapshotRoot,
- newSnapshotRoot));
+ writeUnlock(FSNamesystemLockMode.FS, operationName,
+ getLockReportInfoSupplier(oldSnapshotRoot, newSnapshotRoot));
}
} catch (AccessControlException ace) {
logAuditEvent(false, operationName, oldSnapshotRoot,
@@ -7278,13 +7279,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
try {
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.READ);
status = FSDirSnapshotOp.getSnapshottableDirListing(dir, pc,
snapshotManager);
} finally {
- readUnlock(operationName, getLockReportInfoSupplier(null));
+ readUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(null));
}
} catch (AccessControlException ace) {
logAuditEvent(false, operationName, null, null, null);
@@ -7309,14 +7310,14 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
try {
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.READ);
status = FSDirSnapshotOp.getSnapshotListing(dir, pc, snapshotManager,
snapshotRoot);
success = true;
} finally {
- readUnlock(operationName, getLockReportInfoSupplier(null));
+ readUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(null));
}
} catch (AccessControlException ace) {
logAuditEvent(success, operationName, snapshotRoot);
@@ -7354,14 +7355,14 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
FSPermissionChecker.setOperationType(operationName);
long actualTime = Time.monotonicNow();
try {
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.READ);
diffs = FSDirSnapshotOp.getSnapshotDiffReport(dir, pc, snapshotManager,
path, fromSnapshot, toSnapshot);
} finally {
- readUnlock(operationName, getLockReportInfoSupplier(fromSnapshotRoot,
- toSnapshotRoot));
+ readUnlock(FSNamesystemLockMode.FS, operationName,
+ getLockReportInfoSupplier(fromSnapshotRoot, toSnapshotRoot));
}
} catch (AccessControlException ace) {
logAuditEvent(false, operationName, fromSnapshotRoot,
@@ -7428,7 +7429,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
try {
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.READ);
diffs = FSDirSnapshotOp
@@ -7436,8 +7437,8 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
fromSnapshot, toSnapshot, startPath, index,
snapshotDiffReportLimit);
} finally {
- readUnlock(operationName, getLockReportInfoSupplier(fromSnapshotRoot,
- toSnapshotRoot));
+ readUnlock(FSNamesystemLockMode.FS, operationName,
+ getLockReportInfoSupplier(fromSnapshotRoot, toSnapshotRoot));
}
} catch (AccessControlException ace) {
logAuditEvent(false, operationName, fromSnapshotRoot, toSnapshotRoot,
@@ -7465,7 +7466,8 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
FSPermissionChecker.setOperationType(operationName);
checkOperation(OperationCategory.WRITE);
try {
- writeLock();
+ // It involves Block while collecting blocks to be deleted.
+ writeLock(FSNamesystemLockMode.GLOBAL);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot delete snapshot for " + snapshotRoot);
@@ -7473,7 +7475,8 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
blocksToBeDeleted = FSDirSnapshotOp.deleteSnapshot(dir, pc,
snapshotManager, snapshotRoot, snapshotName, logRetryCache);
} finally {
- writeUnlock(operationName, getLockReportInfoSupplier(rootPath));
+ writeUnlock(FSNamesystemLockMode.GLOBAL, operationName,
+ getLockReportInfoSupplier(rootPath));
}
} catch (AccessControlException ace) {
logAuditEvent(false, operationName, rootPath, null, null);
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotDeletionGc.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotDeletionGc.java
index c62455c724fe..5b509a7d85f0 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotDeletionGc.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotDeletionGc.java
@@ -19,6 +19,7 @@ package org.apache.hadoop.hdfs.server.namenode.snapshot;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -72,14 +73,14 @@ public class SnapshotDeletionGc {
private void gcDeletedSnapshot(String name) {
final Snapshot.Root deleted;
- namesystem.readLock();
+ namesystem.readLock(FSNamesystemLockMode.FS);
try {
deleted = namesystem.getSnapshotManager().chooseDeletedSnapshot();
} catch (Throwable e) {
LOG.error("Failed to chooseDeletedSnapshot", e);
throw e;
} finally {
- namesystem.readUnlock("gcDeletedSnapshot");
+ namesystem.readUnlock(FSNamesystemLockMode.FS, "gcDeletedSnapshot");
}
if (deleted == null) {
LOG.trace("{}: no snapshots are marked as deleted.", name);
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestLeaseManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestLeaseManager.java
index 2759b9e20d7e..6be34537a050 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestLeaseManager.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestLeaseManager.java
@@ -35,6 +35,7 @@ import org.apache.hadoop.hdfs.protocol.HdfsConstants;
import org.apache.hadoop.hdfs.protocol.OpenFilesIterator;
import org.apache.hadoop.hdfs.protocol.QuotaExceededException;
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot;
import org.apache.hadoop.util.Lists;
@@ -466,6 +467,8 @@ public class TestLeaseManager {
when(fsn.isRunning()).thenReturn(true);
when(fsn.hasReadLock()).thenReturn(true);
when(fsn.hasWriteLock()).thenReturn(true);
+ when(fsn.hasReadLock(FSNamesystemLockMode.FS)).thenReturn(true);
+ when(fsn.hasWriteLock(FSNamesystemLockMode.FS)).thenReturn(true);
when(fsn.getFSDirectory()).thenReturn(dir);
when(fsn.getMaxLockHoldToReleaseLeaseMs()).thenReturn(maxLockHoldToReleaseLeaseMs);
return fsn;
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org
(hadoop) 15/23: HDFS-17420. [FGL] EditLogTailer and FSEditLogLoader support FGL (#6679)
Posted by za...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zanderxu pushed a commit to branch HDFS-17384
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit 132a63f4ad2c8cd8bff1c739e1a41c853a1c9ad4
Author: ZanderXu <za...@apache.org>
AuthorDate: Thu Mar 28 09:51:35 2024 +0800
HDFS-17420. [FGL] EditLogTailer and FSEditLogLoader support FGL (#6679)
---
.../org/apache/hadoop/hdfs/server/namenode/FSEditLogLoader.java | 9 +++++----
.../org/apache/hadoop/hdfs/server/namenode/ha/EditLogTailer.java | 5 +++--
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogLoader.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogLoader.java
index 5158058a0560..4bd3e9eda8df 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogLoader.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogLoader.java
@@ -27,6 +27,7 @@ import java.util.EnumMap;
import java.util.EnumSet;
import java.util.List;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hadoop.classification.InterfaceAudience;
@@ -171,7 +172,7 @@ public class FSEditLogLoader {
StartupProgress prog = NameNode.getStartupProgress();
Step step = createStartupProgressStep(edits);
prog.beginStep(Phase.LOADING_EDITS, step);
- fsNamesys.writeLock();
+ fsNamesys.writeLock(FSNamesystemLockMode.GLOBAL);
try {
long startTime = timer.monotonicNow();
LogAction preLogAction = LOAD_EDITS_LOG_HELPER.record("pre", startTime);
@@ -196,7 +197,7 @@ public class FSEditLogLoader {
return numEdits;
} finally {
edits.close();
- fsNamesys.writeUnlock("loadFSEdits");
+ fsNamesys.writeUnlock(FSNamesystemLockMode.GLOBAL, "loadFSEdits");
prog.endStep(Phase.LOADING_EDITS, step);
}
}
@@ -218,7 +219,7 @@ public class FSEditLogLoader {
LOG.trace("Acquiring write lock to replay edit log");
}
- fsNamesys.writeLock();
+ fsNamesys.writeLock(FSNamesystemLockMode.GLOBAL);
FSDirectory fsDir = fsNamesys.dir;
fsDir.writeLock();
@@ -342,7 +343,7 @@ public class FSEditLogLoader {
in.close();
}
fsDir.writeUnlock();
- fsNamesys.writeUnlock("loadEditRecords");
+ fsNamesys.writeUnlock(FSNamesystemLockMode.GLOBAL, "loadEditRecords");
if (LOG.isTraceEnabled()) {
LOG.trace("replaying edit log finished");
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/EditLogTailer.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/EditLogTailer.java
index d14d8a889220..568c8bbdf8ae 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/EditLogTailer.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/EditLogTailer.java
@@ -34,6 +34,7 @@ import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.thirdparty.com.google.common.collect.Iterators;
import org.apache.hadoop.thirdparty.com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.apache.hadoop.util.Timer;
@@ -355,7 +356,7 @@ public class EditLogTailer {
// transitionToActive RPC takes the write lock before calling
// tailer.stop() -- so if we're not interruptible, it will
// deadlock.
- namesystem.writeLockInterruptibly();
+ namesystem.writeLockInterruptibly(FSNamesystemLockMode.GLOBAL);
try {
long currentLastTxnId = image.getLastAppliedTxId();
if (lastTxnId != currentLastTxnId) {
@@ -386,7 +387,7 @@ public class EditLogTailer {
lastLoadedTxnId = image.getLastAppliedTxId();
return editsLoaded;
} finally {
- namesystem.writeUnlock("doTailEdits");
+ namesystem.writeUnlock(FSNamesystemLockMode.GLOBAL, "doTailEdits");
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org
(hadoop) 14/23: HDFS-17412. [FGL] Client RPCs involving maintenance supports fine-grained lock (#6667)
Posted by za...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zanderxu pushed a commit to branch HDFS-17384
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit 771ec5a3df132c59053e536f522b1bd650acbfd9
Author: ZanderXu <za...@apache.org>
AuthorDate: Wed Mar 27 17:07:38 2024 +0800
HDFS-17412. [FGL] Client RPCs involving maintenance supports fine-grained lock (#6667)
---
.../hdfs/server/blockmanagement/BlockManager.java | 2 +-
.../hadoop/hdfs/server/namenode/FSNamesystem.java | 42 ++++++++++++----------
2 files changed, 24 insertions(+), 20 deletions(-)
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
index 23a864f731b0..cf3ec7964c06 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
@@ -856,7 +856,7 @@ public class BlockManager implements BlockStatsMXBean {
/** Dump meta data to out. */
public void metaSave(PrintWriter out) {
- assert namesystem.hasReadLock(); // TODO: block manager read lock and NS write lock
+ assert namesystem.hasReadLock(FSNamesystemLockMode.BM);
final List<DatanodeDescriptor> live = new ArrayList<DatanodeDescriptor>();
final List<DatanodeDescriptor> dead = new ArrayList<DatanodeDescriptor>();
datanodeManager.fetchDatanodes(live, dead, false);
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
index cbd81c1f5578..fb983974458b 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
@@ -1995,7 +1995,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
String operationName = "metaSave";
checkSuperuserPrivilege(operationName);
checkOperation(OperationCategory.READ);
- readLock();
+ readLock(FSNamesystemLockMode.GLOBAL);
try {
checkOperation(OperationCategory.READ);
synchronized(metaSaveLock) {
@@ -2008,13 +2008,15 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
out.close();
}
} finally {
- readUnlock(operationName, getLockReportInfoSupplier(null));
+ readUnlock(FSNamesystemLockMode.GLOBAL, operationName, getLockReportInfoSupplier(null));
}
logAuditEvent(true, operationName, null);
}
private void metaSave(PrintWriter out) {
- assert hasReadLock();
+ // TODO: Change to hasReadLock(FSNamesystemLockMode.BM)
+ assert hasReadLock(FSNamesystemLockMode.GLOBAL);
+ // Normally FSReadLock is needed here, but I think thread-safe is unnecessary here.
long totalInodes = this.dir.totalInodes();
long totalBlocks = this.getBlocksTotal();
out.println(totalInodes + " files and directories, " + totalBlocks
@@ -4988,14 +4990,14 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
String operationName = "slowDataNodesReport";
DatanodeInfo[] datanodeInfos;
checkOperation(OperationCategory.UNCHECKED);
- readLock();
+ readLock(FSNamesystemLockMode.BM);
try {
checkOperation(OperationCategory.UNCHECKED);
final DatanodeManager dm = getBlockManager().getDatanodeManager();
final List<DatanodeDescriptor> results = dm.getAllSlowDataNodes();
datanodeInfos = getDatanodeInfoFromDescriptors(results);
} finally {
- readUnlock(operationName, getLockReportInfoSupplier(null));
+ readUnlock(FSNamesystemLockMode.BM, operationName, getLockReportInfoSupplier(null));
}
logAuditEvent(true, operationName, null);
return datanodeInfos;
@@ -5016,14 +5018,14 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
DatanodeInfo[] arr;
checkSuperuserPrivilege(operationName);
checkOperation(OperationCategory.UNCHECKED);
- readLock();
+ readLock(FSNamesystemLockMode.BM);
try {
checkOperation(OperationCategory.UNCHECKED);
final DatanodeManager dm = getBlockManager().getDatanodeManager();
final List<DatanodeDescriptor> results = dm.getDatanodeListForReport(type);
arr = getDatanodeInfoFromDescriptors(results);
} finally {
- readUnlock(operationName, getLockReportInfoSupplier(null));
+ readUnlock(FSNamesystemLockMode.BM, operationName, getLockReportInfoSupplier(null));
}
logAuditEvent(true, operationName, null);
return arr;
@@ -5035,13 +5037,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
DatanodeStorageReport[] reports;
checkSuperuserPrivilege(operationName);
checkOperation(OperationCategory.UNCHECKED);
- readLock();
+ readLock(FSNamesystemLockMode.BM);
try {
checkOperation(OperationCategory.UNCHECKED);
final DatanodeManager dm = getBlockManager().getDatanodeManager();
reports = dm.getDatanodeStorageReport(type);
} finally {
- readUnlock(operationName, getLockReportInfoSupplier(null));
+ readUnlock(FSNamesystemLockMode.BM, operationName, getLockReportInfoSupplier(null));
}
logAuditEvent(true, operationName, null);
return reports;
@@ -5060,7 +5062,9 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
boolean saved = false;
cpLock(); // Block if a checkpointing is in progress on standby.
- readLock();
+ // TODO: MileStone2 should change this readLock() to writeLock(FSNamesystemLockMode.FS)
+ // since all directory-tree modification operations will just hold the FSReadLock.
+ readLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.UNCHECKED);
@@ -5070,7 +5074,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
}
saved = getFSImage().saveNamespace(timeWindow, txGap, this);
} finally {
- readUnlock(operationName, getLockReportInfoSupplier(null));
+ readUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(null));
cpUnlock();
}
if (saved) {
@@ -5092,7 +5096,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
checkSuperuserPrivilege(operationName);
checkOperation(OperationCategory.UNCHECKED);
cpLock(); // Block if a checkpointing is in progress on standby.
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.UNCHECKED);
@@ -5104,7 +5108,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
getNNStorage().setRestoreFailedStorage(val);
}
} finally {
- writeUnlock(operationName, getLockReportInfoSupplier(null));
+ writeUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(null));
cpUnlock();
}
logAuditEvent(true, operationName, null);
@@ -5120,12 +5124,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
checkSuperuserPrivilege(operationName);
checkOperation(OperationCategory.UNCHECKED);
cpLock(); // Block if a checkpointing is in progress on standby.
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.UNCHECKED);
getFSImage().finalizeUpgrade(this.isHaEnabled() && inActiveState());
} finally {
- writeUnlock(operationName, getLockReportInfoSupplier(null));
+ writeUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(null));
cpUnlock();
}
logAuditEvent(true, operationName, null);
@@ -7521,7 +7525,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final String operationName = "queryRollingUpgrade";
checkSuperuserPrivilege(operationName);
checkOperation(OperationCategory.READ);
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.READ);
if (!isRollingUpgrade()) {
@@ -7531,7 +7535,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
boolean hasRollbackImage = this.getFSImage().hasRollbackFSImage();
rollingUpgradeInfo.setCreatedRollbackImages(hasRollbackImage);
} finally {
- readUnlock(operationName, getLockReportInfoSupplier(null));
+ readUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(null));
}
logAuditEvent(true, operationName, null, null, null);
return rollingUpgradeInfo;
@@ -7541,7 +7545,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final String operationName = "startRollingUpgrade";
checkSuperuserPrivilege(operationName);
checkOperation(OperationCategory.WRITE);
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
if (isRollingUpgrade()) {
@@ -7561,7 +7565,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
getFSImage().rollEditLog(getEffectiveLayoutVersion());
}
} finally {
- writeUnlock(operationName, getLockReportInfoSupplier(null));
+ writeUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(null));
}
getEditLog().logSync();
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org
(hadoop) 21/23: HDFS-17472. [FGL] gcDeletedSnapshot and getDelegationToken support FGL (#6743)
Posted by za...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zanderxu pushed a commit to branch HDFS-17384
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit 43aa4f905ecde0f634115f73776c444aac0e1150
Author: ZanderXu <za...@apache.org>
AuthorDate: Thu Apr 18 09:33:32 2024 +0800
HDFS-17472. [FGL] gcDeletedSnapshot and getDelegationToken support FGL (#6743)
---
.../java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
index db12d646a671..941959e21fac 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
@@ -6337,7 +6337,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
String tokenId = null;
Token<DelegationTokenIdentifier> token;
checkOperation(OperationCategory.WRITE);
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot issue delegation token");
@@ -6365,7 +6365,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
getEditLog().logGetDelegationToken(dtId, expiryTime);
tokenId = dtId.toStringStable();
} finally {
- writeUnlock(operationName, getLockReportInfoSupplier(tokenId));
+ writeUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(tokenId));
}
getEditLog().logSync();
logAuditEvent(true, operationName, tokenId);
@@ -7500,7 +7500,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final INode.BlocksMapUpdateInfo blocksToBeDeleted;
checkOperation(OperationCategory.WRITE);
- writeLock();
+ writeLock(FSNamesystemLockMode.GLOBAL);
try {
checkOperation(OperationCategory.WRITE);
rootPath = Snapshot.getSnapshotPath(snapshotRoot, snapshotName);
@@ -7512,7 +7512,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
blocksToBeDeleted = FSDirSnapshotOp.deleteSnapshot(
dir, snapshotManager, iip, snapshotName, now, snapshotRoot, false);
} finally {
- writeUnlock(operationName, getLockReportInfoSupplier(rootPath));
+ writeUnlock(FSNamesystemLockMode.GLOBAL, operationName, getLockReportInfoSupplier(rootPath));
}
blockManager.addBLocksToMarkedDeleteQueue(
blocksToBeDeleted.getToDeleteList());
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org
(hadoop) 13/23: HDFS-17417. [FGL] HeartbeatManager and DatanodeAdminMonitor support fine-grained locking (#6656)
Posted by za...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zanderxu pushed a commit to branch HDFS-17384
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit 07c4b73dc5008e4d3815a0b77e9528049b519d5c
Author: ZanderXu <za...@apache.org>
AuthorDate: Wed Mar 27 09:45:17 2024 +0800
HDFS-17417. [FGL] HeartbeatManager and DatanodeAdminMonitor support fine-grained locking (#6656)
---
.../hdfs/server/blockmanagement/BlockManager.java | 10 +++---
.../DatanodeAdminBackoffMonitor.java | 38 ++++++++++++----------
.../DatanodeAdminDefaultMonitor.java | 11 ++++---
.../server/blockmanagement/DatanodeManager.java | 5 +--
.../server/blockmanagement/HeartbeatManager.java | 9 ++---
5 files changed, 41 insertions(+), 32 deletions(-)
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
index 82b82433e70e..23a864f731b0 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
@@ -1825,7 +1825,7 @@ public class BlockManager implements BlockStatsMXBean {
/** Remove the blocks associated to the given DatanodeStorageInfo. */
void removeBlocksAssociatedTo(final DatanodeStorageInfo storageInfo) {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
final Iterator<BlockInfo> it = storageInfo.getBlockIterator();
DatanodeDescriptor node = storageInfo.getDatanodeDescriptor();
while(it.hasNext()) {
@@ -4876,6 +4876,7 @@ public class BlockManager implements BlockStatsMXBean {
NumberReplicas num = countNodes(block);
if (shouldProcessExtraRedundancy(num, expectedReplication)) {
// extra redundancy block
+ // Here involves storage policy ID.
processExtraRedundancyBlock(block, (short) expectedReplication, null,
null);
numExtraRedundancy++;
@@ -4884,14 +4885,15 @@ public class BlockManager implements BlockStatsMXBean {
// When called by tests like TestDefaultBlockPlacementPolicy.
// testPlacementWithLocalRackNodesDecommissioned, it is not protected by
// lock, only when called by DatanodeManager.refreshNodes have writeLock
- if (namesystem.hasWriteLock()) {
- namesystem.writeUnlock("processExtraRedundancyBlocksOnInService");
+ if (namesystem.hasWriteLock(FSNamesystemLockMode.GLOBAL)) {
+ namesystem.writeUnlock(FSNamesystemLockMode.GLOBAL,
+ "processExtraRedundancyBlocksOnInService");
try {
Thread.sleep(1);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.GLOBAL);
}
}
LOG.info("Invalidated {} extra redundancy blocks on {} after "
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeAdminBackoffMonitor.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeAdminBackoffMonitor.java
index 79d5a065b08a..d212d142d441 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeAdminBackoffMonitor.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeAdminBackoffMonitor.java
@@ -17,6 +17,7 @@
*/
package org.apache.hadoop.hdfs.server.blockmanagement;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.thirdparty.com.google.common.collect.Iterables;
import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.server.namenode.INode;
@@ -170,7 +171,7 @@ public class DatanodeAdminBackoffMonitor extends DatanodeAdminMonitorBase
numBlocksChecked = 0;
// Check decommission or maintenance progress.
try {
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.BM);
try {
/**
* Other threads can modify the pendingNode list and the cancelled
@@ -208,7 +209,7 @@ public class DatanodeAdminBackoffMonitor extends DatanodeAdminMonitorBase
processPendingNodes();
} finally {
- namesystem.writeUnlock("DatanodeAdminMonitorV2Thread");
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "DatanodeAdminMonitorV2Thread");
}
// After processing the above, various parts of the check() method will
// take and drop the read / write lock as needed. Aside from the
@@ -326,7 +327,7 @@ public class DatanodeAdminBackoffMonitor extends DatanodeAdminMonitorBase
*/
private void processMaintenanceNodes() {
// Check for any maintenance state nodes which need to be expired
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.GLOBAL);
try {
for (DatanodeDescriptor dn : outOfServiceNodeBlocks.keySet()) {
if (dn.isMaintenance() && dn.maintenanceExpired()) {
@@ -338,12 +339,12 @@ public class DatanodeAdminBackoffMonitor extends DatanodeAdminMonitorBase
// which added the node to the cancelled list. Therefore expired
// maintenance nodes do not need to be added to the toRemove list.
dnAdmin.stopMaintenance(dn);
- namesystem.writeUnlock("processMaintenanceNodes");
- namesystem.writeLock();
+ namesystem.writeUnlock(FSNamesystemLockMode.GLOBAL, "processMaintenanceNodes");
+ namesystem.writeLock(FSNamesystemLockMode.GLOBAL);
}
}
} finally {
- namesystem.writeUnlock("processMaintenanceNodes");
+ namesystem.writeUnlock(FSNamesystemLockMode.GLOBAL, "processMaintenanceNodes");
}
}
@@ -360,7 +361,7 @@ public class DatanodeAdminBackoffMonitor extends DatanodeAdminMonitorBase
// taking the write lock at all.
return;
}
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.BM);
try {
for (DatanodeDescriptor dn : toRemove) {
final boolean isHealthy =
@@ -402,7 +403,7 @@ public class DatanodeAdminBackoffMonitor extends DatanodeAdminMonitorBase
}
}
} finally {
- namesystem.writeUnlock("processCompletedNodes");
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "processCompletedNodes");
}
}
@@ -486,7 +487,7 @@ public class DatanodeAdminBackoffMonitor extends DatanodeAdminMonitorBase
return;
}
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.GLOBAL);
try {
long repQueueSize = blockManager.getLowRedundancyBlocksCount();
@@ -524,8 +525,8 @@ public class DatanodeAdminBackoffMonitor extends DatanodeAdminMonitorBase
// replication
if (blocksProcessed >= blocksPerLock) {
blocksProcessed = 0;
- namesystem.writeUnlock("moveBlocksToPending");
- namesystem.writeLock();
+ namesystem.writeUnlock(FSNamesystemLockMode.GLOBAL, "moveBlocksToPending");
+ namesystem.writeLock(FSNamesystemLockMode.GLOBAL);
}
blocksProcessed++;
if (nextBlockAddedToPending(blockIt, dn)) {
@@ -546,7 +547,7 @@ public class DatanodeAdminBackoffMonitor extends DatanodeAdminMonitorBase
}
}
} finally {
- namesystem.writeUnlock("moveBlocksToPending");
+ namesystem.writeUnlock(FSNamesystemLockMode.GLOBAL, "moveBlocksToPending");
}
LOG.debug("{} blocks are now pending replication", pendingCount);
}
@@ -626,15 +627,16 @@ public class DatanodeAdminBackoffMonitor extends DatanodeAdminMonitorBase
}
DatanodeStorageInfo[] storage;
- namesystem.readLock();
+ namesystem.readLock(FSNamesystemLockMode.BM);
try {
storage = dn.getStorageInfos();
} finally {
- namesystem.readUnlock("scanDatanodeStorage");
+ namesystem.readUnlock(FSNamesystemLockMode.BM, "scanDatanodeStorage");
}
for (DatanodeStorageInfo s : storage) {
- namesystem.readLock();
+ // isBlockReplicatedOk involves FS.
+ namesystem.readLock(FSNamesystemLockMode.GLOBAL);
try {
// As the lock is dropped and re-taken between each storage, we need
// to check the storage is still present before processing it, as it
@@ -660,7 +662,7 @@ public class DatanodeAdminBackoffMonitor extends DatanodeAdminMonitorBase
numBlocksChecked++;
}
} finally {
- namesystem.readUnlock("scanDatanodeStorage");
+ namesystem.readUnlock(FSNamesystemLockMode.GLOBAL, "scanDatanodeStorage");
}
}
}
@@ -683,7 +685,7 @@ public class DatanodeAdminBackoffMonitor extends DatanodeAdminMonitorBase
* namenode write lock while it runs.
*/
private void processPendingReplication() {
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.GLOBAL);
try {
for (Iterator<Map.Entry<DatanodeDescriptor, List<BlockInfo>>>
entIt = pendingRep.entrySet().iterator(); entIt.hasNext();) {
@@ -715,7 +717,7 @@ public class DatanodeAdminBackoffMonitor extends DatanodeAdminMonitorBase
suspectBlocks.getOutOfServiceBlockCount());
}
} finally {
- namesystem.writeUnlock("processPendingReplication");
+ namesystem.writeUnlock(FSNamesystemLockMode.GLOBAL, "processPendingReplication");
}
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeAdminDefaultMonitor.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeAdminDefaultMonitor.java
index 94049b35dc48..cf06d53b8bae 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeAdminDefaultMonitor.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeAdminDefaultMonitor.java
@@ -17,6 +17,7 @@
*/
package org.apache.hadoop.hdfs.server.blockmanagement;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.util.Preconditions;
import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.protocol.DatanodeID;
@@ -182,7 +183,9 @@ public class DatanodeAdminDefaultMonitor extends DatanodeAdminMonitorBase
numBlocksCheckedPerLock = 0;
numNodesChecked = 0;
// Check decommission or maintenance progress.
- namesystem.writeLock();
+ // dnAdmin.stopMaintenance(dn) needs FSReadLock
+ // since processExtraRedundancyBlock involves storage policy and isSufficient involves bc.
+ namesystem.writeLock(FSNamesystemLockMode.GLOBAL);
try {
processCancelledNodes();
processPendingNodes();
@@ -191,7 +194,7 @@ public class DatanodeAdminDefaultMonitor extends DatanodeAdminMonitorBase
LOG.warn("DatanodeAdminMonitor caught exception when processing node.",
e);
} finally {
- namesystem.writeUnlock("DatanodeAdminMonitorThread");
+ namesystem.writeUnlock(FSNamesystemLockMode.GLOBAL, "DatanodeAdminMonitorThread");
}
if (numBlocksChecked + numNodesChecked > 0) {
LOG.info("Checked {} blocks and {} nodes this tick. {} nodes are now " +
@@ -426,7 +429,7 @@ public class DatanodeAdminDefaultMonitor extends DatanodeAdminMonitorBase
// lock.
// Yielding is required in case of block number is greater than the
// configured per-iteration-limit.
- namesystem.writeUnlock("processBlocksInternal");
+ namesystem.writeUnlock(FSNamesystemLockMode.GLOBAL, "processBlocksInternal");
try {
LOG.debug("Yielded lock during decommission/maintenance check");
Thread.sleep(0, 500);
@@ -435,7 +438,7 @@ public class DatanodeAdminDefaultMonitor extends DatanodeAdminMonitorBase
}
// reset
numBlocksCheckedPerLock = 0;
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.GLOBAL);
}
numBlocksChecked++;
numBlocksCheckedPerLock++;
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java
index dc22fe22c96e..392f86d79fd5 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java
@@ -1335,12 +1335,13 @@ public class DatanodeManager {
*/
public void refreshNodes(final Configuration conf) throws IOException {
refreshHostsReader(conf);
- namesystem.writeLock();
+ // processExtraRedundancyBlocksOnInService involves FS in stopMaintenance and stopDecommission.
+ namesystem.writeLock(FSNamesystemLockMode.GLOBAL);
try {
refreshDatanodes();
countSoftwareVersions();
} finally {
- namesystem.writeUnlock("refreshNodes");
+ namesystem.writeUnlock(FSNamesystemLockMode.GLOBAL, "refreshNodes");
}
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/HeartbeatManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/HeartbeatManager.java
index 429d40d9fbdd..6961e9912c55 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/HeartbeatManager.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/HeartbeatManager.java
@@ -28,6 +28,7 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.StorageType;
import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.server.namenode.Namesystem;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.protocol.StorageReport;
import org.apache.hadoop.hdfs.server.protocol.VolumeFailureSummary;
import org.apache.hadoop.util.Daemon;
@@ -514,20 +515,20 @@ class HeartbeatManager implements DatanodeStatistics {
for (DatanodeDescriptor dead : deadDatanodes) {
// acquire the fsnamesystem lock, and then remove the dead node.
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.BM);
try {
dm.removeDeadDatanode(dead, !dead.isMaintenance());
} finally {
- namesystem.writeUnlock("removeDeadDatanode");
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "removeDeadDatanode");
}
}
for (DatanodeStorageInfo failedStorage : failedStorages) {
// acquire the fsnamesystem lock, and remove blocks on the storage.
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.BM);
try {
blockManager.removeBlocksAssociatedTo(failedStorage);
} finally {
- namesystem.writeUnlock("removeBlocksAssociatedTo");
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "removeBlocksAssociatedTo");
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org
(hadoop) 07/23: HDFS-17413. [FGL] CacheReplicationMonitor supports fine-grained lock (#6641)
Posted by za...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zanderxu pushed a commit to branch HDFS-17384
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit 5c7719b9e60bb1bbc77bc7d9ca604b0e95af7cf2
Author: ZanderXu <za...@apache.org>
AuthorDate: Fri Mar 22 10:08:46 2024 +0800
HDFS-17413. [FGL] CacheReplicationMonitor supports fine-grained lock (#6641)
---
.../blockmanagement/CacheReplicationMonitor.java | 13 +++++----
.../hadoop/hdfs/server/namenode/CacheManager.java | 33 +++++++++++-----------
.../hadoop/hdfs/server/namenode/FSNamesystem.java | 32 ++++++++++-----------
3 files changed, 40 insertions(+), 38 deletions(-)
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/CacheReplicationMonitor.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/CacheReplicationMonitor.java
index f9036c550e85..fad9f4248b4f 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/CacheReplicationMonitor.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/CacheReplicationMonitor.java
@@ -48,6 +48,7 @@ import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
import org.apache.hadoop.hdfs.server.namenode.INode;
import org.apache.hadoop.hdfs.server.namenode.INodeDirectory;
import org.apache.hadoop.hdfs.server.namenode.INodeFile;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot;
import org.apache.hadoop.hdfs.util.ReadOnlyList;
import org.apache.hadoop.util.GSet;
@@ -223,7 +224,7 @@ public class CacheReplicationMonitor extends Thread implements Closeable {
* after are not atomic.
*/
public void waitForRescanIfNeeded() {
- Preconditions.checkArgument(!namesystem.hasWriteLock(),
+ Preconditions.checkArgument(!namesystem.hasWriteLock(FSNamesystemLockMode.FS),
"Must not hold the FSN write lock when waiting for a rescan.");
Preconditions.checkArgument(lock.isHeldByCurrentThread(),
"Must hold the CRM lock when waiting for a rescan.");
@@ -268,7 +269,7 @@ public class CacheReplicationMonitor extends Thread implements Closeable {
*/
@Override
public void close() throws IOException {
- Preconditions.checkArgument(namesystem.hasWriteLock());
+ Preconditions.checkArgument(namesystem.hasWriteLock(FSNamesystemLockMode.GLOBAL));
lock.lock();
try {
if (shutdown) return;
@@ -291,7 +292,7 @@ public class CacheReplicationMonitor extends Thread implements Closeable {
scannedBlocks = 0;
lastScanTimeMs = Time.monotonicNow();
try {
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.GLOBAL);
try {
lock.lock();
if (shutdown) {
@@ -308,7 +309,7 @@ public class CacheReplicationMonitor extends Thread implements Closeable {
rescanCachedBlockMap();
blockManager.getDatanodeManager().resetLastCachingDirectiveSentTime();
} finally {
- namesystem.writeUnlock("cacheReplicationMonitorRescan");
+ namesystem.writeUnlock(FSNamesystemLockMode.GLOBAL, "cacheReplicationMonitorRescan");
}
}
@@ -325,11 +326,11 @@ public class CacheReplicationMonitor extends Thread implements Closeable {
long now = Time.monotonicNow();
if (now - last > cacheManager.getMaxLockTimeMs()) {
try {
- namesystem.writeUnlock();
+ namesystem.writeUnlock(FSNamesystemLockMode.GLOBAL, "cacheReplicationMonitorRescan");
Thread.sleep(cacheManager.getSleepTimeMs());
} catch (InterruptedException e) {
} finally {
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.GLOBAL);
}
}
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/CacheManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/CacheManager.java
index 24ccf45b91d2..d296ff278b5e 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/CacheManager.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/CacheManager.java
@@ -80,6 +80,7 @@ import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor.CachedBl
import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor.CachedBlocksList.Type;
import org.apache.hadoop.hdfs.server.namenode.FSDirectory.DirOp;
import org.apache.hadoop.hdfs.server.namenode.FsImageProto.CacheManagerSection;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.namenode.metrics.NameNodeMetrics;
import org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot;
import org.apache.hadoop.hdfs.server.namenode.startupprogress.Phase;
@@ -317,7 +318,7 @@ public class CacheManager {
}
public void clearDirectiveStats() {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.FS);
for (CacheDirective directive : directivesById.values()) {
directive.resetStatistics();
}
@@ -327,7 +328,7 @@ public class CacheManager {
* @return Unmodifiable view of the collection of CachePools.
*/
public Collection<CachePool> getCachePools() {
- assert namesystem.hasReadLock();
+ assert namesystem.hasReadLock(FSNamesystemLockMode.FS);
return Collections.unmodifiableCollection(cachePools.values());
}
@@ -335,18 +336,18 @@ public class CacheManager {
* @return Unmodifiable view of the collection of CacheDirectives.
*/
public Collection<CacheDirective> getCacheDirectives() {
- assert namesystem.hasReadLock();
+ assert namesystem.hasReadLock(FSNamesystemLockMode.FS);
return Collections.unmodifiableCollection(directivesById.values());
}
@VisibleForTesting
public GSet<CachedBlock, CachedBlock> getCachedBlocks() {
- assert namesystem.hasReadLock();
+ assert namesystem.hasReadLock(FSNamesystemLockMode.BM);
return cachedBlocks;
}
private long getNextDirectiveId() throws IOException {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.FS);
if (nextDirectiveId >= Long.MAX_VALUE - 1) {
throw new IOException("No more available IDs.");
}
@@ -574,7 +575,7 @@ public class CacheManager {
public CacheDirectiveInfo addDirective(
CacheDirectiveInfo info, FSPermissionChecker pc, EnumSet<CacheFlag> flags)
throws IOException {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.FS);
CacheDirective directive;
try {
CachePool pool = getCachePool(validatePoolName(info));
@@ -652,7 +653,7 @@ public class CacheManager {
public void modifyDirective(CacheDirectiveInfo info,
FSPermissionChecker pc, EnumSet<CacheFlag> flags) throws IOException {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.FS);
String idString =
(info.getId() == null) ?
"(null)" : info.getId().toString();
@@ -703,7 +704,7 @@ public class CacheManager {
private void removeInternal(CacheDirective directive)
throws InvalidRequestException {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.FS);
// Remove the corresponding entry in directivesByPath.
String path = directive.getPath();
if (!directivesByPath.remove(path, directive)) {
@@ -724,7 +725,7 @@ public class CacheManager {
public void removeDirective(long id, FSPermissionChecker pc)
throws IOException {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.FS);
try {
CacheDirective directive = getById(id);
checkWritePermission(pc, directive.getPool());
@@ -740,7 +741,7 @@ public class CacheManager {
listCacheDirectives(long prevId,
CacheDirectiveInfo filter,
FSPermissionChecker pc) throws IOException {
- assert namesystem.hasReadLock();
+ assert namesystem.hasReadLock(FSNamesystemLockMode.FS);
final int NUM_PRE_ALLOCATED_ENTRIES = 16;
String filterPath = null;
if (filter.getPath() != null) {
@@ -815,7 +816,7 @@ public class CacheManager {
*/
public CachePoolInfo addCachePool(CachePoolInfo info)
throws IOException {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.FS);
CachePool pool;
try {
CachePoolInfo.validate(info);
@@ -845,7 +846,7 @@ public class CacheManager {
*/
public void modifyCachePool(CachePoolInfo info)
throws IOException {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.FS);
StringBuilder bld = new StringBuilder();
try {
CachePoolInfo.validate(info);
@@ -915,7 +916,7 @@ public class CacheManager {
*/
public void removeCachePool(String poolName)
throws IOException {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.FS);
try {
CachePoolInfo.validateName(poolName);
CachePool pool = cachePools.remove(poolName);
@@ -941,7 +942,7 @@ public class CacheManager {
public BatchedListEntries<CachePoolEntry>
listCachePools(FSPermissionChecker pc, String prevKey) {
- assert namesystem.hasReadLock();
+ assert namesystem.hasReadLock(FSNamesystemLockMode.FS);
final int NUM_PRE_ALLOCATED_ENTRIES = 16;
ArrayList<CachePoolEntry> results =
new ArrayList<CachePoolEntry>(NUM_PRE_ALLOCATED_ENTRIES);
@@ -1008,7 +1009,7 @@ public class CacheManager {
datanodeID, DFS_NAMENODE_CACHING_ENABLED_KEY, blockIds.size());
return;
}
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.BM);
final long startTime = Time.monotonicNow();
final long endTime;
try {
@@ -1022,7 +1023,7 @@ public class CacheManager {
processCacheReportImpl(datanode, blockIds);
} finally {
endTime = Time.monotonicNow();
- namesystem.writeUnlock("processCacheReport");
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "processCacheReport");
}
// Log the block report processing stats from Namenode perspective
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
index ef6f922c7480..e97444b7db25 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
@@ -7770,7 +7770,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
checkOperation(OperationCategory.WRITE);
FSPermissionChecker.setOperationType(operationName);
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot add cache directive");
@@ -7779,7 +7779,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
} finally {
effectiveDirectiveStr = effectiveDirective != null ?
effectiveDirective.toString() : null;
- writeUnlock(operationName,
+ writeUnlock(FSNamesystemLockMode.FS, operationName,
getLockReportInfoSupplier(effectiveDirectiveStr));
}
} catch (AccessControlException ace) {
@@ -7803,14 +7803,14 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
FSPermissionChecker.setOperationType(operationName);
checkOperation(OperationCategory.WRITE);
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot add cache directive");
FSNDNCacheOp.modifyCacheDirective(this, cacheManager, directive, flags,
logRetryCache);
} finally {
- writeUnlock(operationName,
+ writeUnlock(FSNamesystemLockMode.FS, operationName,
getLockReportInfoSupplier(idStr, directive.toString()));
}
} catch (AccessControlException ace) {
@@ -7829,14 +7829,14 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
checkOperation(OperationCategory.WRITE);
FSPermissionChecker.setOperationType(operationName);
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot remove cache directives");
FSNDNCacheOp.removeCacheDirective(this, cacheManager, id,
logRetryCache);
} finally {
- writeUnlock(operationName, getLockReportInfoSupplier(idStr));
+ writeUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(idStr));
}
} catch (AccessControlException ace) {
logAuditEvent(false, operationName, idStr, null, null);
@@ -7854,13 +7854,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
BatchedListEntries<CacheDirectiveEntry> results;
cacheManager.waitForRescanIfNeeded();
try {
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.READ);
results = FSNDNCacheOp.listCacheDirectives(this, cacheManager, startId,
filter);
} finally {
- readUnlock(operationName,
+ readUnlock(FSNamesystemLockMode.FS, operationName,
getLockReportInfoSupplier(filter.toString()));
}
} catch (AccessControlException ace) {
@@ -7879,7 +7879,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
String poolName = req == null ? null : req.getPoolName();
checkSuperuserPrivilege(operationName, poolName);
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot add cache pool"
@@ -7888,7 +7888,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
logRetryCache);
poolInfoStr = info.toString();
} finally {
- writeUnlock(operationName, getLockReportInfoSupplier(poolInfoStr));
+ writeUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(poolInfoStr));
}
} catch (AccessControlException ace) {
logAuditEvent(false, operationName, poolInfoStr);
@@ -7906,14 +7906,14 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
(req == null ? null : req.getPoolName()) + "}";
checkSuperuserPrivilege(operationName, poolNameStr);
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot modify cache pool"
+ (req == null ? null : req.getPoolName()));
FSNDNCacheOp.modifyCachePool(this, cacheManager, req, logRetryCache);
} finally {
- writeUnlock(operationName, getLockReportInfoSupplier(poolNameStr,
+ writeUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(poolNameStr,
req == null ? null : req.toString()));
}
} catch (AccessControlException ace) {
@@ -7933,14 +7933,14 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
String poolNameStr = "{poolName: " + cachePoolName + "}";
checkSuperuserPrivilege(operationName, poolNameStr);
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot modify cache pool" + cachePoolName);
FSNDNCacheOp.removeCachePool(this, cacheManager, cachePoolName,
logRetryCache);
} finally {
- writeUnlock(operationName, getLockReportInfoSupplier(poolNameStr));
+ writeUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(poolNameStr));
}
} catch (AccessControlException ace) {
logAuditEvent(false, operationName, poolNameStr);
@@ -7958,12 +7958,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
FSPermissionChecker.setOperationType(operationName);
cacheManager.waitForRescanIfNeeded();
try {
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.READ);
results = FSNDNCacheOp.listCachePools(this, cacheManager, prevKey);
} finally {
- readUnlock(operationName, getLockReportInfoSupplier(null));
+ readUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(null));
}
} catch (AccessControlException ace) {
logAuditEvent(false, operationName, null);
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org
(hadoop) 02/23: HDFS-17387. [FGL] Abstract the configuration locking mode (#6572)
Posted by za...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zanderxu pushed a commit to branch HDFS-17384
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit ca902d1212e77d3855b696124b9ca648b730f3d0
Author: ZanderXu <za...@apache.org>
AuthorDate: Mon Mar 4 18:00:18 2024 +0800
HDFS-17387. [FGL] Abstract the configuration locking mode (#6572)
* HDFS-17387. [FGL] Abstract the configurable locking mode
---
.../java/org/apache/hadoop/hdfs/DFSConfigKeys.java | 6 +
.../hadoop/hdfs/server/namenode/FSNamesystem.java | 96 +++++++----
.../hdfs/server/namenode/FSNamesystemLock.java | 12 +-
.../hdfs/server/namenode/fgl/FSNLockManager.java | 184 +++++++++++++++++++++
.../server/namenode/fgl/FSNamesystemLockMode.java | 24 +++
.../namenode/fgl/GlobalFSNamesystemLock.java | 149 +++++++++++++++++
.../hdfs/server/namenode/fgl/package-info.java | 18 ++
.../java/org/apache/hadoop/hdfs/util/RwLock.java | 78 +++++++--
.../src/main/resources/hdfs-default.xml | 9 +
9 files changed, 525 insertions(+), 51 deletions(-)
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSConfigKeys.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSConfigKeys.java
index f92a2ad56581..337980ac5200 100755
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSConfigKeys.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSConfigKeys.java
@@ -29,6 +29,8 @@ import org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicyRackFau
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants;
import org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.RamDiskReplicaLruTracker;
import org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.ReservedSpaceCalculator;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNLockManager;
+import org.apache.hadoop.hdfs.server.namenode.fgl.GlobalFSNamesystemLock;
import org.apache.hadoop.hdfs.web.URLConnectionFactory;
import org.apache.hadoop.http.HttpConfig;
@@ -1051,6 +1053,10 @@ public class DFSConfigKeys extends CommonConfigurationKeys {
public static final String DFS_NAMENODE_INODE_ATTRIBUTES_PROVIDER_KEY = "dfs.namenode.inode.attributes.provider.class";
public static final String DFS_NAMENODE_INODE_ATTRIBUTES_PROVIDER_BYPASS_USERS_KEY = "dfs.namenode.inode.attributes.provider.bypass.users";
public static final String DFS_NAMENODE_INODE_ATTRIBUTES_PROVIDER_BYPASS_USERS_DEFAULT = "";
+ public static final String DFS_NAMENODE_LOCK_MODEL_PROVIDER_KEY =
+ "dfs.namenode.lock.model.provider.class";
+ public static final Class<? extends FSNLockManager> DFS_NAMENODE_LOCK_MODEL_PROVIDER_DEFAULT =
+ GlobalFSNamesystemLock.class;
public static final String DFS_DATANODE_BP_READY_TIMEOUT_KEY = "dfs.datanode.bp-ready.timeout";
public static final long DFS_DATANODE_BP_READY_TIMEOUT_DEFAULT = 20;
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
index 8470eac05f83..e5372bf1981b 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
@@ -34,6 +34,8 @@ import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_BLOCK_SIZE_DEFAULT;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_BLOCK_SIZE_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_WITH_REMOTE_PORT_DEFAULT;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_WITH_REMOTE_PORT_KEY;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_LOCK_MODEL_PROVIDER_DEFAULT;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_LOCK_MODEL_PROVIDER_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_STORAGE_POLICY_ENABLED_DEFAULT;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_STORAGE_POLICY_PERMISSIONS_SUPERUSER_ONLY_DEFAULT;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_STORAGE_POLICY_PERMISSIONS_SUPERUSER_ONLY_KEY;
@@ -96,6 +98,7 @@ import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_SNAPSHOT_DIFF_LI
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_SNAPSHOT_DIFF_LISTING_LIMIT_DEFAULT;
import static org.apache.hadoop.hdfs.DFSUtil.isParentEntry;
+import java.lang.reflect.Constructor;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.atomic.AtomicLong;
@@ -114,6 +117,8 @@ import static org.apache.hadoop.ha.HAServiceProtocol.HAServiceState.OBSERVER;
import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicyInfo;
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfoStriped;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNLockManager;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.thirdparty.com.google.common.collect.Maps;
import org.apache.hadoop.hdfs.server.namenode.snapshot.SnapshotDeletionGc;
import org.apache.hadoop.thirdparty.protobuf.ByteString;
@@ -621,7 +626,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
private final int numCommittedAllowed;
/** Lock to protect FSNamesystem. */
- private final FSNamesystemLock fsLock;
+ private final FSNLockManager fsLock;
/**
* Checkpoint lock to protect FSNamesystem modification on standby NNs.
@@ -871,7 +876,10 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
this.contextFieldSeparator =
conf.get(HADOOP_CALLER_CONTEXT_SEPARATOR_KEY,
HADOOP_CALLER_CONTEXT_SEPARATOR_DEFAULT);
- fsLock = new FSNamesystemLock(conf, detailedLockHoldTimeMetrics);
+ Class<? extends FSNLockManager> lockKlass = conf.getClass(
+ DFS_NAMENODE_LOCK_MODEL_PROVIDER_KEY, DFS_NAMENODE_LOCK_MODEL_PROVIDER_DEFAULT,
+ FSNLockManager.class);
+ fsLock = createLock(lockKlass, conf, detailedLockHoldTimeMetrics);
cpLock = new ReentrantLock();
this.fsImage = fsImage;
@@ -1077,6 +1085,18 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
}
}
+ private <T> T createLock(Class<T> theClass, Configuration conf,
+ MutableRatesWithAggregation mutableRatesMetrics) {
+ try {
+ Constructor<T> meth = theClass.getDeclaredConstructor(
+ Configuration.class, MutableRatesWithAggregation.class);
+ meth.setAccessible(true);
+ return meth.newInstance(conf, mutableRatesMetrics);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
private static void checkForAsyncLogEnabledByOldConfigs(Configuration conf) {
// dfs.namenode.audit.log.async is no longer in use. Use log4j properties instead.
if (conf.getBoolean("dfs.namenode.audit.log.async", false)) {
@@ -1787,70 +1807,74 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
}
@Override
- public void readLock() {
- this.fsLock.readLock();
- }
-
- @Override
- public void readLockInterruptibly() throws InterruptedException {
- this.fsLock.readLockInterruptibly();
+ public void readLock(FSNamesystemLockMode lockMode) {
+ this.fsLock.readLock(lockMode);
}
@Override
- public void readUnlock() {
- this.fsLock.readUnlock();
+ public void readLockInterruptibly(FSNamesystemLockMode lockMode) throws InterruptedException {
+ this.fsLock.readLockInterruptibly(lockMode);
}
@Override
- public void readUnlock(String opName) {
- this.fsLock.readUnlock(opName);
+ public void readUnlock(FSNamesystemLockMode lockMode, String opName) {
+ this.fsLock.readUnlock(lockMode, opName);
}
public void readUnlock(String opName,
Supplier<String> lockReportInfoSupplier) {
- this.fsLock.readUnlock(opName, lockReportInfoSupplier);
+ readUnlock(FSNamesystemLockMode.GLOBAL, opName, lockReportInfoSupplier);
}
- @Override
- public void writeLock() {
- this.fsLock.writeLock();
+ public void readUnlock(FSNamesystemLockMode lockMode, String opName,
+ Supplier<String> lockReportInfoSupplier) {
+ this.fsLock.readUnlock(lockMode, opName, lockReportInfoSupplier);
}
@Override
- public void writeLockInterruptibly() throws InterruptedException {
- this.fsLock.writeLockInterruptibly();
+ public void writeLock(FSNamesystemLockMode lockMode) {
+ this.fsLock.writeLock(lockMode);
}
@Override
- public void writeUnlock() {
- this.fsLock.writeUnlock();
+ public void writeLockInterruptibly(FSNamesystemLockMode lockMode) throws InterruptedException {
+ this.fsLock.writeLockInterruptibly(lockMode);
}
@Override
- public void writeUnlock(String opName) {
- this.fsLock.writeUnlock(opName);
+ public void writeUnlock(FSNamesystemLockMode lockMode, String opName) {
+ this.fsLock.writeUnlock(lockMode, opName);
}
public void writeUnlock(String opName, boolean suppressWriteLockReport) {
- this.fsLock.writeUnlock(opName, suppressWriteLockReport);
+ writeUnlock(FSNamesystemLockMode.GLOBAL, opName, suppressWriteLockReport);
+ }
+
+ public void writeUnlock(FSNamesystemLockMode lockMode, String opName,
+ boolean suppressWriteLockReport) {
+ this.fsLock.writeUnlock(lockMode, opName, suppressWriteLockReport);
+ }
+
+ public void writeUnlock(String opName, Supplier<String> lockReportInfoSupplier) {
+ writeUnlock(FSNamesystemLockMode.GLOBAL, opName, lockReportInfoSupplier);
}
- public void writeUnlock(String opName,
+ public void writeUnlock(FSNamesystemLockMode lockMode, String opName,
Supplier<String> lockReportInfoSupplier) {
- this.fsLock.writeUnlock(opName, lockReportInfoSupplier);
+ this.fsLock.writeUnlock(lockMode, opName, lockReportInfoSupplier);
}
@Override
- public boolean hasWriteLock() {
- return this.fsLock.isWriteLockedByCurrentThread();
+ public boolean hasWriteLock(FSNamesystemLockMode lockMode) {
+ return this.fsLock.hasWriteLock(lockMode);
}
@Override
- public boolean hasReadLock() {
- return this.fsLock.getReadHoldCount() > 0 || hasWriteLock();
+ public boolean hasReadLock(FSNamesystemLockMode lockMode) {
+ return this.fsLock.hasReadLock(lockMode);
}
public int getReadHoldCount() {
- return this.fsLock.getReadHoldCount();
+ return this.fsLock.getReadHoldCount(FSNamesystemLockMode.GLOBAL);
}
/** Lock the checkpoint lock */
@@ -4931,21 +4955,21 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
@Metric({"LockQueueLength", "Number of threads waiting to " +
"acquire FSNameSystemLock"})
public int getFsLockQueueLength() {
- return fsLock.getQueueLength();
+ return fsLock.getQueueLength(FSNamesystemLockMode.FS);
}
@Metric(value = {"ReadLockLongHoldCount", "The number of time " +
"the read lock has been held for longer than the threshold"},
type = Metric.Type.COUNTER)
public long getNumOfReadLockLongHold() {
- return fsLock.getNumOfReadLockLongHold();
+ return fsLock.getNumOfReadLockLongHold(FSNamesystemLockMode.FS);
}
@Metric(value = {"WriteLockLongHoldCount", "The number of time " +
"the write lock has been held for longer than the threshold"},
type = Metric.Type.COUNTER)
public long getNumOfWriteLockLongHold() {
- return fsLock.getNumOfWriteLockLongHold();
+ return fsLock.getNumOfWriteLockLongHold(FSNamesystemLockMode.FS);
}
int getNumberOfDatanodes(DatanodeReportType type) {
@@ -7097,12 +7121,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
@VisibleForTesting
void setFsLockForTests(ReentrantReadWriteLock lock) {
- this.fsLock.coarseLock = lock;
+ this.fsLock.setLockForTests(lock);
}
@VisibleForTesting
public ReentrantReadWriteLock getFsLockForTests() {
- return fsLock.coarseLock;
+ return fsLock.getLockForTests();
}
@VisibleForTesting
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystemLock.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystemLock.java
index af641e964f46..abdc80e1e81a 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystemLock.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystemLock.java
@@ -64,7 +64,7 @@ import static org.apache.hadoop.log.LogThrottlingHelper.LogAction;
* {@link MutableRatesWithAggregation}. However since threads are re-used
* between operations this should not generally be an issue.
*/
-class FSNamesystemLock {
+public class FSNamesystemLock {
@VisibleForTesting
protected ReentrantReadWriteLock coarseLock;
@@ -129,7 +129,7 @@ class FSNamesystemLock {
private static final String OVERALL_METRIC_NAME = "Overall";
- FSNamesystemLock(Configuration conf,
+ public FSNamesystemLock(Configuration conf,
MutableRatesWithAggregation detailedHoldTimeMetrics) {
this(conf, detailedHoldTimeMetrics, new Timer());
}
@@ -489,6 +489,14 @@ class FSNamesystemLock {
return writeLockReportingThresholdMs;
}
+ public void setLockForTests(ReentrantReadWriteLock lock) {
+ this.coarseLock = lock;
+ }
+
+ public ReentrantReadWriteLock getLockForTests() {
+ return this.coarseLock;
+ }
+
/**
* Read lock Held Info.
*/
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/fgl/FSNLockManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/fgl/FSNLockManager.java
new file mode 100644
index 000000000000..8956a3461de5
--- /dev/null
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/fgl/FSNLockManager.java
@@ -0,0 +1,184 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hdfs.server.namenode.fgl;
+
+import org.apache.hadoop.classification.VisibleForTesting;
+
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.function.Supplier;
+
+public interface FSNLockManager {
+
+ /**
+ * Acquire read lock for an operation according to the lock mode.
+ * @param lockMode locking mode
+ */
+ void readLock(FSNamesystemLockMode lockMode);
+
+ /**
+ * Acquire read lock according to the lock mode, unless interrupted while waiting.
+ * @param lockMode locking mode
+ */
+ void readLockInterruptibly(FSNamesystemLockMode lockMode) throws InterruptedException;
+
+ /**
+ * Release read lock for the operation according to the lock mode.
+ * @param lockMode locking mode
+ * @param opName operation name
+ */
+ void readUnlock(FSNamesystemLockMode lockMode, String opName);
+
+ /**
+ * Release read lock for the operation according to the lock mode.
+ * @param lockMode locking mode
+ * @param opName operation name
+ * @param lockReportInfoSupplier supplier used to report some information for this lock.
+ */
+ void readUnlock(FSNamesystemLockMode lockMode, String opName,
+ Supplier<String> lockReportInfoSupplier);
+
+ /**
+ * Acquire write lock for an operation according to the lock mode.
+ * @param lockMode locking mode
+ */
+ void writeLock(FSNamesystemLockMode lockMode);
+
+ /**
+ * Release write lock for the operation according to the lock mode.
+ * @param lockMode locking mode
+ * @param opName operation name
+ */
+ void writeUnlock(FSNamesystemLockMode lockMode, String opName);
+
+ /**
+ * Release write lock for the operation according to the lock mode.
+ * @param lockMode locking mode
+ * @param opName operation name
+ * @param suppressWriteLockReport When false, event of write lock being held
+ * for long time will be logged in logs and metrics.
+ */
+ void writeUnlock(FSNamesystemLockMode lockMode, String opName,
+ boolean suppressWriteLockReport);
+
+ /**
+ * Release write lock for the operation according to the lock mode.
+ * @param lockMode locking mode
+ * @param opName operation name
+ * @param lockReportInfoSupplier supplier used to report information for this lock.
+ */
+ void writeUnlock(FSNamesystemLockMode lockMode, String opName,
+ Supplier<String> lockReportInfoSupplier);
+
+ void writeLockInterruptibly(FSNamesystemLockMode lockMode) throws InterruptedException;
+
+ /**
+ * Check if the current thread holds write lock according to the lock mode.
+ * @param lockMode locking mode
+ * @return true if the current thread is holding the write-lock, else false.
+ */
+ boolean hasWriteLock(FSNamesystemLockMode lockMode);
+
+ /**
+ * Check if the current thread holds read lock according to the lock mode.
+ * @param lockMode locking mode
+ * @return true if the current thread is holding the read-lock, else false.
+ */
+ boolean hasReadLock(FSNamesystemLockMode lockMode);
+
+ /**
+ * Queries the number of reentrant read holds on this lock by the
+ * current thread. A reader thread has a hold on a lock for
+ * each lock action that is not matched by an unlock action.
+ *
+ * @param lockMode locking mode
+ * @return the number of holds on the read lock by the current thread,
+ * or zero if the read lock is not held by the current thread
+ */
+ int getReadHoldCount(FSNamesystemLockMode lockMode);
+
+ /**
+ * Returns the QueueLength of waiting threads.
+ * A larger number indicates greater lock contention.
+ *
+ * @param lockMode locking mode
+ * @return int - Number of threads waiting on this lock
+ */
+ int getQueueLength(FSNamesystemLockMode lockMode);
+
+ /**
+ * Returns the number of time the read lock
+ * has been held longer than the threshold.
+ *
+ * @param lockMode locking mode
+ * @return long - Number of time the read lock
+ * has been held longer than the threshold
+ */
+ long getNumOfReadLockLongHold(FSNamesystemLockMode lockMode);
+
+ /**
+ * Returns the number of time the write-lock
+ * has been held longer than the threshold.
+ *
+ * @param lockMode locking mode
+ * @return long - Number of time the write-lock
+ * has been held longer than the threshold.
+ */
+ long getNumOfWriteLockLongHold(FSNamesystemLockMode lockMode);
+
+ /**
+ * Check if the metrics is enabled.
+ * @return true if the metrics is enabled, else false.
+ */
+ boolean isMetricsEnabled();
+
+ /**
+ * Reset the metricsEnabled according to the lock mode.
+ * @param metricsEnabled the new metricsEnabled
+ */
+ void setMetricsEnabled(boolean metricsEnabled);
+
+ /**
+ * Try to set the reporting threshold of the read lock.
+ * @param readLockReportingThresholdMs reporting threshold
+ */
+ void setReadLockReportingThresholdMs(long readLockReportingThresholdMs);
+
+ /**
+ * Try to get the reporting threshold of the read lock.
+ * @return the reporting threshold.
+ */
+ long getReadLockReportingThresholdMs();
+
+ /**
+ * Try to set the reporting threshold for the write lock.
+ * @param writeLockReportingThresholdMs reporting threshold.
+ */
+ void setWriteLockReportingThresholdMs(long writeLockReportingThresholdMs);
+
+ /**
+ * Try to get the reporting threshold for the write lock.
+ * @return reporting threshold.
+ */
+ long getWriteLockReportingThresholdMs();
+
+ @VisibleForTesting
+ void setLockForTests(ReentrantReadWriteLock lock);
+
+ @VisibleForTesting
+ ReentrantReadWriteLock getLockForTests();
+}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/fgl/FSNamesystemLockMode.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/fgl/FSNamesystemLockMode.java
new file mode 100644
index 000000000000..f3b7d570db92
--- /dev/null
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/fgl/FSNamesystemLockMode.java
@@ -0,0 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hdfs.server.namenode.fgl;
+
+public enum FSNamesystemLockMode {
+ GLOBAL,
+ FS,
+ BM
+}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/fgl/GlobalFSNamesystemLock.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/fgl/GlobalFSNamesystemLock.java
new file mode 100644
index 000000000000..c01529fac4c3
--- /dev/null
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/fgl/GlobalFSNamesystemLock.java
@@ -0,0 +1,149 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hdfs.server.namenode.fgl;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hdfs.server.namenode.FSNamesystemLock;
+import org.apache.hadoop.metrics2.lib.MutableRatesWithAggregation;
+
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.function.Supplier;
+
+public class GlobalFSNamesystemLock implements FSNLockManager {
+
+ private final FSNamesystemLock lock;
+
+ public GlobalFSNamesystemLock(Configuration conf, MutableRatesWithAggregation aggregation) {
+ this.lock = new FSNamesystemLock(conf, aggregation);
+ }
+
+ @Override
+ public void readLock(FSNamesystemLockMode lockMode) {
+ this.lock.readLock();
+ }
+
+ public void readLockInterruptibly(FSNamesystemLockMode lockMode) throws InterruptedException {
+ this.lock.readLockInterruptibly();
+ }
+
+ @Override
+ public void readUnlock(FSNamesystemLockMode lockMode, String opName) {
+ this.lock.readUnlock(opName);
+ }
+
+ public void readUnlock(FSNamesystemLockMode lockMode, String opName,
+ Supplier<String> lockReportInfoSupplier) {
+ this.lock.readUnlock(opName, lockReportInfoSupplier);
+ }
+
+ @Override
+ public void writeLock(FSNamesystemLockMode lockMode) {
+ this.lock.writeLock();
+ }
+
+ @Override
+ public void writeUnlock(FSNamesystemLockMode lockMode, String opName) {
+ this.lock.writeUnlock(opName);
+ }
+
+ @Override
+ public void writeUnlock(FSNamesystemLockMode lockMode, String opName,
+ boolean suppressWriteLockReport) {
+ this.lock.writeUnlock(opName, suppressWriteLockReport);
+ }
+
+ public void writeUnlock(FSNamesystemLockMode lockMode, String opName,
+ Supplier<String> lockReportInfoSupplier) {
+ this.lock.writeUnlock(opName, lockReportInfoSupplier);
+ }
+
+ @Override
+ public void writeLockInterruptibly(FSNamesystemLockMode lockMode)
+ throws InterruptedException {
+ this.lock.writeLockInterruptibly();
+ }
+
+ @Override
+ public boolean hasWriteLock(FSNamesystemLockMode lockMode) {
+ return this.lock.isWriteLockedByCurrentThread();
+ }
+
+ @Override
+ public boolean hasReadLock(FSNamesystemLockMode lockMode) {
+ return this.lock.getReadHoldCount() > 0 || hasWriteLock(lockMode);
+ }
+
+ @Override
+ public int getReadHoldCount(FSNamesystemLockMode lockMode) {
+ return this.lock.getReadHoldCount();
+ }
+
+ @Override
+ public int getQueueLength(FSNamesystemLockMode lockMode) {
+ return this.lock.getQueueLength();
+ }
+
+ @Override
+ public long getNumOfReadLockLongHold(FSNamesystemLockMode lockMode) {
+ return this.lock.getNumOfReadLockLongHold();
+ }
+
+ @Override
+ public long getNumOfWriteLockLongHold(FSNamesystemLockMode lockMode) {
+ return this.lock.getNumOfWriteLockLongHold();
+ }
+
+ @Override
+ public boolean isMetricsEnabled() {
+ return this.lock.isMetricsEnabled();
+ }
+
+ public void setMetricsEnabled(boolean metricsEnabled) {
+ this.lock.setMetricsEnabled(metricsEnabled);
+ }
+
+ @Override
+ public void setReadLockReportingThresholdMs(long readLockReportingThresholdMs) {
+ this.lock.setReadLockReportingThresholdMs(readLockReportingThresholdMs);
+ }
+
+ @Override
+ public long getReadLockReportingThresholdMs() {
+ return this.lock.getReadLockReportingThresholdMs();
+ }
+
+ @Override
+ public void setWriteLockReportingThresholdMs(long writeLockReportingThresholdMs) {
+ this.lock.setWriteLockReportingThresholdMs(writeLockReportingThresholdMs);
+ }
+
+ @Override
+ public long getWriteLockReportingThresholdMs() {
+ return this.lock.getWriteLockReportingThresholdMs();
+ }
+
+ @Override
+ public void setLockForTests(ReentrantReadWriteLock testLock) {
+ this.lock.setLockForTests(testLock);
+ }
+
+ @Override
+ public ReentrantReadWriteLock getLockForTests() {
+ return this.lock.getLockForTests();
+ }
+}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/fgl/package-info.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/fgl/package-info.java
new file mode 100644
index 000000000000..57ea1545910a
--- /dev/null
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/fgl/package-info.java
@@ -0,0 +1,18 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hdfs.server.namenode.fgl;
\ No newline at end of file
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/RwLock.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/RwLock.java
index 05c1a06abda2..7398e2a91273 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/RwLock.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/RwLock.java
@@ -17,41 +17,93 @@
*/
package org.apache.hadoop.hdfs.util;
-/** Read-write lock interface. */
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
+
+/** Read-write lock interface for FSNamesystem. */
public interface RwLock {
/** Acquire read lock. */
- public void readLock();
+ default void readLock() {
+ readLock(FSNamesystemLockMode.GLOBAL);
+ }
+
+ /** Acquire read lock. */
+ void readLock(FSNamesystemLockMode lockMode);
- /** Acquire read lock, unless interrupted while waiting */
- void readLockInterruptibly() throws InterruptedException;
+ /** Acquire read lock, unless interrupted while waiting. */
+ default void readLockInterruptibly() throws InterruptedException {
+ readLockInterruptibly(FSNamesystemLockMode.GLOBAL);
+ }
+
+ /** Acquire read lock, unless interrupted while waiting. */
+ void readLockInterruptibly(FSNamesystemLockMode lockMode) throws InterruptedException;
/** Release read lock. */
- public void readUnlock();
+ default void readUnlock() {
+ readUnlock(FSNamesystemLockMode.GLOBAL, "OTHER");
+ }
/**
* Release read lock with operation name.
* @param opName Option name.
*/
- public void readUnlock(String opName);
+ default void readUnlock(String opName) {
+ readUnlock(FSNamesystemLockMode.GLOBAL, opName);
+ }
+
+ /**
+ * Release read lock with operation name.
+ * @param opName Option name.
+ */
+ void readUnlock(FSNamesystemLockMode lockMode, String opName);
+
+ /** Check if the current thread holds read lock. */
+ default boolean hasReadLock() {
+ return hasReadLock(FSNamesystemLockMode.GLOBAL);
+ }
/** Check if the current thread holds read lock. */
- public boolean hasReadLock();
+ boolean hasReadLock(FSNamesystemLockMode lockMode);
/** Acquire write lock. */
- public void writeLock();
+ default void writeLock() {
+ writeLock(FSNamesystemLockMode.GLOBAL);
+ }
+
+ /** Acquire write lock. */
+ void writeLock(FSNamesystemLockMode lockMode);
- /** Acquire write lock, unless interrupted while waiting */
- void writeLockInterruptibly() throws InterruptedException;
+ /** Acquire write lock, unless interrupted while waiting. */
+ default void writeLockInterruptibly() throws InterruptedException {
+ writeLockInterruptibly(FSNamesystemLockMode.GLOBAL);
+ }
+
+ /** Acquire write lock, unless interrupted while waiting. */
+ void writeLockInterruptibly(FSNamesystemLockMode lockMode) throws InterruptedException;
/** Release write lock. */
- public void writeUnlock();
+ default void writeUnlock() {
+ writeUnlock(FSNamesystemLockMode.GLOBAL, "OTHER");
+ }
+
+ /**
+ * Release write lock with operation name.
+ * @param opName Option name.
+ */
+ default void writeUnlock(String opName) {
+ writeUnlock(FSNamesystemLockMode.GLOBAL, opName);
+ }
/**
* Release write lock with operation name.
* @param opName Option name.
*/
- public void writeUnlock(String opName);
+ void writeUnlock(FSNamesystemLockMode lockMode, String opName);
+
+ /** Check if the current thread holds write lock. */
+ default boolean hasWriteLock() {
+ return hasWriteLock(FSNamesystemLockMode.GLOBAL);
+ }
/** Check if the current thread holds write lock. */
- public boolean hasWriteLock();
+ boolean hasWriteLock(FSNamesystemLockMode lockMode);
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/resources/hdfs-default.xml b/hadoop-hdfs-project/hadoop-hdfs/src/main/resources/hdfs-default.xml
index e6dc8c5ba1ac..6fea6444c8fd 100755
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/resources/hdfs-default.xml
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/resources/hdfs-default.xml
@@ -3956,6 +3956,15 @@
</description>
</property>
+<property>
+ <name>dfs.namenode.lock.model.provider.class</name>
+ <value>org.apache.hadoop.hdfs.server.namenode.fgl.GlobalFSNamesystemLock</value>
+ <description>
+ An implementation class of FSNamesystem lock.
+ Defaults to GlobalFSNamesystemLock.class
+ </description>
+</property>
+
<property>
<name>dfs.datanode.bp-ready.timeout</name>
<value>20</value>
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org
(hadoop) 03/23: HDFS-17398. [FGL] Implement the FGL lock for FSNLockManager (#6599)
Posted by za...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zanderxu pushed a commit to branch HDFS-17384
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit 03170885c13321db211bb49f4b5fad04085aea50
Author: ZanderXu <za...@apache.org>
AuthorDate: Tue Mar 5 22:10:59 2024 +0800
HDFS-17398. [FGL] Implement the FGL lock for FSNLockManager (#6599)
---
.../namenode/fgl/FineGrainedFSNamesystemLock.java | 300 +++++++++++++++++++++
.../fgl/TestFineGrainedFSNamesystemLock.java | 275 +++++++++++++++++++
2 files changed, 575 insertions(+)
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/fgl/FineGrainedFSNamesystemLock.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/fgl/FineGrainedFSNamesystemLock.java
new file mode 100644
index 000000000000..c2e3980476a9
--- /dev/null
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/fgl/FineGrainedFSNamesystemLock.java
@@ -0,0 +1,300 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hdfs.server.namenode.fgl;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hdfs.server.namenode.FSNamesystemLock;
+import org.apache.hadoop.metrics2.lib.MutableRatesWithAggregation;
+
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.function.Supplier;
+
+/**
+ * Splitting the global FSN lock into FSLock and BMLock.
+ * FSLock is used to protect directory tree-related operations.
+ * BMLock is used to protect block-related and dn-related operations.
+ * The lock order should be: FSLock,BMLock.
+ */
+public class FineGrainedFSNamesystemLock implements FSNLockManager {
+ private final FSNamesystemLock fsLock;
+ private final FSNamesystemLock bmLock;
+
+ public FineGrainedFSNamesystemLock(Configuration conf, MutableRatesWithAggregation aggregation) {
+ this.fsLock = new FSNamesystemLock(conf, aggregation);
+ this.bmLock = new FSNamesystemLock(conf, aggregation);
+ }
+
+ @Override
+ public void readLock(FSNamesystemLockMode lockMode) {
+ if (lockMode.equals(FSNamesystemLockMode.GLOBAL)) {
+ this.fsLock.readLock();
+ this.bmLock.readLock();
+ } else if (lockMode.equals(FSNamesystemLockMode.FS)) {
+ this.fsLock.readLock();
+ } else if (lockMode.equals(FSNamesystemLockMode.BM)) {
+ this.bmLock.readLock();
+ }
+ }
+
+ public void readLockInterruptibly(FSNamesystemLockMode lockMode) throws InterruptedException {
+ if (lockMode.equals(FSNamesystemLockMode.GLOBAL)) {
+ this.fsLock.readLockInterruptibly();
+ try {
+ this.bmLock.readLockInterruptibly();
+ } catch (InterruptedException e) {
+ // The held FSLock should be released if the current thread is interrupted
+ // while acquiring the BMLock.
+ this.fsLock.readUnlock("BMReadLockInterruptiblyFailed");
+ throw e;
+ }
+ } else if (lockMode.equals(FSNamesystemLockMode.FS)) {
+ this.fsLock.readLockInterruptibly();
+ } else if (lockMode.equals(FSNamesystemLockMode.BM)) {
+ this.bmLock.readLockInterruptibly();
+ }
+ }
+
+ @Override
+ public void readUnlock(FSNamesystemLockMode lockMode, String opName) {
+ if (lockMode.equals(FSNamesystemLockMode.GLOBAL)) {
+ this.bmLock.readUnlock(opName);
+ this.fsLock.readUnlock(opName);
+ } else if (lockMode.equals(FSNamesystemLockMode.FS)) {
+ this.fsLock.readUnlock(opName);
+ } else if (lockMode.equals(FSNamesystemLockMode.BM)) {
+ this.bmLock.readUnlock(opName);
+ }
+ }
+
+ public void readUnlock(FSNamesystemLockMode lockMode, String opName,
+ Supplier<String> lockReportInfoSupplier) {
+ if (lockMode.equals(FSNamesystemLockMode.GLOBAL)) {
+ this.bmLock.readUnlock(opName, lockReportInfoSupplier);
+ this.fsLock.readUnlock(opName, lockReportInfoSupplier);
+ } else if (lockMode.equals(FSNamesystemLockMode.FS)) {
+ this.fsLock.readUnlock(opName, lockReportInfoSupplier);
+ } else if (lockMode.equals(FSNamesystemLockMode.BM)) {
+ this.bmLock.readUnlock(opName, lockReportInfoSupplier);
+ }
+ }
+
+ @Override
+ public void writeLock(FSNamesystemLockMode lockMode) {
+ if (lockMode.equals(FSNamesystemLockMode.GLOBAL)) {
+ this.fsLock.writeLock();
+ this.bmLock.writeLock();
+ } else if (lockMode.equals(FSNamesystemLockMode.FS)) {
+ this.fsLock.writeLock();
+ } else if (lockMode.equals(FSNamesystemLockMode.BM)) {
+ this.bmLock.writeLock();
+ }
+ }
+
+ @Override
+ public void writeUnlock(FSNamesystemLockMode lockMode, String opName) {
+ if (lockMode.equals(FSNamesystemLockMode.GLOBAL)) {
+ this.bmLock.writeUnlock(opName);
+ this.fsLock.writeUnlock(opName);
+ } else if (lockMode.equals(FSNamesystemLockMode.FS)) {
+ this.fsLock.writeUnlock(opName);
+ } else if (lockMode.equals(FSNamesystemLockMode.BM)) {
+ this.bmLock.writeUnlock(opName);
+ }
+ }
+
+ @Override
+ public void writeUnlock(FSNamesystemLockMode lockMode, String opName,
+ boolean suppressWriteLockReport) {
+ if (lockMode.equals(FSNamesystemLockMode.GLOBAL)) {
+ this.bmLock.writeUnlock(opName, suppressWriteLockReport);
+ this.fsLock.writeUnlock(opName, suppressWriteLockReport);
+ } else if (lockMode.equals(FSNamesystemLockMode.FS)) {
+ this.fsLock.writeUnlock(opName, suppressWriteLockReport);
+ } else if (lockMode.equals(FSNamesystemLockMode.BM)) {
+ this.bmLock.writeUnlock(opName, suppressWriteLockReport);
+ }
+ }
+
+ public void writeUnlock(FSNamesystemLockMode lockMode, String opName,
+ Supplier<String> lockReportInfoSupplier) {
+ if (lockMode.equals(FSNamesystemLockMode.GLOBAL)) {
+ this.bmLock.writeUnlock(opName, lockReportInfoSupplier);
+ this.fsLock.writeUnlock(opName, lockReportInfoSupplier);
+ } else if (lockMode.equals(FSNamesystemLockMode.FS)) {
+ this.fsLock.writeUnlock(opName, lockReportInfoSupplier);
+ } else if (lockMode.equals(FSNamesystemLockMode.BM)) {
+ this.bmLock.writeUnlock(opName, lockReportInfoSupplier);
+ }
+ }
+
+ @Override
+ public void writeLockInterruptibly(FSNamesystemLockMode lockMode)
+ throws InterruptedException {
+ if (lockMode.equals(FSNamesystemLockMode.GLOBAL)) {
+ this.fsLock.writeLockInterruptibly();
+ try {
+ this.bmLock.writeLockInterruptibly();
+ } catch (InterruptedException e) {
+ // The held FSLock should be released if the current thread is interrupted
+ // while acquiring the BMLock.
+ this.fsLock.writeUnlock("BMWriteLockInterruptiblyFailed");
+ throw e;
+ }
+ } else if (lockMode.equals(FSNamesystemLockMode.FS)) {
+ this.fsLock.writeLockInterruptibly();
+ } else if (lockMode.equals(FSNamesystemLockMode.BM)) {
+ this.bmLock.writeLockInterruptibly();
+ }
+ }
+
+ @Override
+ public boolean hasWriteLock(FSNamesystemLockMode lockMode) {
+ if (lockMode.equals(FSNamesystemLockMode.GLOBAL)) {
+ if (this.fsLock.isWriteLockedByCurrentThread()) {
+ // The bm writeLock should be held by the current thread.
+ assert this.bmLock.isWriteLockedByCurrentThread();
+ return true;
+ } else {
+ // The bm writeLock should not be held by the current thread.
+ assert !this.bmLock.isWriteLockedByCurrentThread();
+ return false;
+ }
+ } else if (lockMode.equals(FSNamesystemLockMode.FS)) {
+ return this.fsLock.isWriteLockedByCurrentThread();
+ } else if (lockMode.equals(FSNamesystemLockMode.BM)) {
+ return this.bmLock.isWriteLockedByCurrentThread();
+ }
+ return false;
+ }
+
+ @Override
+ public boolean hasReadLock(FSNamesystemLockMode lockMode) {
+ if (lockMode.equals(FSNamesystemLockMode.GLOBAL)) {
+ if (hasWriteLock(FSNamesystemLockMode.GLOBAL)) {
+ return true;
+ } else if (this.fsLock.getReadHoldCount() > 0) {
+ // The bm readLock should be held by the current thread.
+ assert this.bmLock.getReadHoldCount() > 0;
+ return true;
+ } else {
+ // The bm readLock should not be held by the current thread.
+ assert this.bmLock.getReadHoldCount() <= 0;
+ return false;
+ }
+ } else if (lockMode.equals(FSNamesystemLockMode.FS)) {
+ return this.fsLock.getReadHoldCount() > 0 || this.fsLock.isWriteLockedByCurrentThread();
+ } else if (lockMode.equals(FSNamesystemLockMode.BM)) {
+ return this.bmLock.getReadHoldCount() > 0 || this.bmLock.isWriteLockedByCurrentThread();
+ }
+ return false;
+ }
+
+ @Override
+ /**
+ * This method is only used for ComputeDirectoryContentSummary.
+ * For the GLOBAL mode, just return the FSLock's ReadHoldCount.
+ */
+ public int getReadHoldCount(FSNamesystemLockMode lockMode) {
+ if (lockMode.equals(FSNamesystemLockMode.GLOBAL)) {
+ return this.fsLock.getReadHoldCount();
+ } else if (lockMode.equals(FSNamesystemLockMode.FS)) {
+ return this.fsLock.getReadHoldCount();
+ } else if (lockMode.equals(FSNamesystemLockMode.BM)) {
+ return this.bmLock.getReadHoldCount();
+ }
+ return -1;
+ }
+
+ @Override
+ public int getQueueLength(FSNamesystemLockMode lockMode) {
+ if (lockMode.equals(FSNamesystemLockMode.GLOBAL)) {
+ return -1;
+ } else if (lockMode.equals(FSNamesystemLockMode.FS)) {
+ return this.fsLock.getQueueLength();
+ } else if (lockMode.equals(FSNamesystemLockMode.BM)) {
+ return this.bmLock.getQueueLength();
+ }
+ return -1;
+ }
+
+ @Override
+ public long getNumOfReadLockLongHold(FSNamesystemLockMode lockMode) {
+ if (lockMode.equals(FSNamesystemLockMode.GLOBAL)) {
+ return -1;
+ } else if (lockMode.equals(FSNamesystemLockMode.FS)) {
+ return this.fsLock.getNumOfReadLockLongHold();
+ } else if (lockMode.equals(FSNamesystemLockMode.BM)) {
+ return this.bmLock.getNumOfReadLockLongHold();
+ }
+ return -1;
+ }
+
+ @Override
+ public long getNumOfWriteLockLongHold(FSNamesystemLockMode lockMode) {
+ if (lockMode.equals(FSNamesystemLockMode.GLOBAL)) {
+ return -1;
+ } else if (lockMode.equals(FSNamesystemLockMode.FS)) {
+ return this.fsLock.getNumOfWriteLockLongHold();
+ } else if (lockMode.equals(FSNamesystemLockMode.BM)) {
+ return this.bmLock.getNumOfWriteLockLongHold();
+ }
+ return -1;
+ }
+
+ @Override
+ public boolean isMetricsEnabled() {
+ return this.fsLock.isMetricsEnabled();
+ }
+
+ public void setMetricsEnabled(boolean metricsEnabled) {
+ this.fsLock.setMetricsEnabled(metricsEnabled);
+ this.bmLock.setMetricsEnabled(metricsEnabled);
+ }
+
+ @Override
+ public void setReadLockReportingThresholdMs(long readLockReportingThresholdMs) {
+ this.fsLock.setReadLockReportingThresholdMs(readLockReportingThresholdMs);
+ this.bmLock.setReadLockReportingThresholdMs(readLockReportingThresholdMs);
+ }
+
+ @Override
+ public long getReadLockReportingThresholdMs() {
+ return this.fsLock.getReadLockReportingThresholdMs();
+ }
+
+ @Override
+ public void setWriteLockReportingThresholdMs(long writeLockReportingThresholdMs) {
+ this.fsLock.setWriteLockReportingThresholdMs(writeLockReportingThresholdMs);
+ this.bmLock.setWriteLockReportingThresholdMs(writeLockReportingThresholdMs);
+ }
+
+ @Override
+ public long getWriteLockReportingThresholdMs() {
+ return this.fsLock.getWriteLockReportingThresholdMs();
+ }
+
+ @Override
+ public void setLockForTests(ReentrantReadWriteLock lock) {
+ throw new UnsupportedOperationException("SetLockTests is unsupported");
+ }
+
+ @Override
+ public ReentrantReadWriteLock getLockForTests() {
+ throw new UnsupportedOperationException("SetLockTests is unsupported");
+ }
+}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/fgl/TestFineGrainedFSNamesystemLock.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/fgl/TestFineGrainedFSNamesystemLock.java
new file mode 100644
index 000000000000..88d66cb3e9b6
--- /dev/null
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/fgl/TestFineGrainedFSNamesystemLock.java
@@ -0,0 +1,275 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hdfs.server.namenode.fgl;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.util.concurrent.HadoopExecutors;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.atomic.AtomicLong;
+
+public class TestFineGrainedFSNamesystemLock {
+
+ private final Logger log = LoggerFactory.getLogger(TestFineGrainedFSNamesystemLock.class);
+
+ private int getLoopNumber() {
+ return ThreadLocalRandom.current().nextInt(2000, 3000);
+ }
+
+ /**
+ * Test read/write lock of Global, FS and BM model through multi-threading.
+ */
+ @Test(timeout=120000)
+ public void testMultipleThreadsUsingLocks()
+ throws InterruptedException, ExecutionException {
+ FineGrainedFSNamesystemLock fsn = new FineGrainedFSNamesystemLock(new Configuration(), null);
+ ExecutorService service = HadoopExecutors.newFixedThreadPool(1000);
+
+ AtomicLong globalCount = new AtomicLong(0);
+ AtomicLong fsCount = new AtomicLong(0);
+ AtomicLong bmCount = new AtomicLong(0);
+ AtomicLong globalNumber = new AtomicLong(0);
+ AtomicLong fsNumber = new AtomicLong(0);
+ AtomicLong bmNumber = new AtomicLong(0);
+
+ List<Callable<Boolean>> callableList = new ArrayList<>(1000);
+ for (int i = 0; i < 1000; i++) {
+ int index = i % 12;
+ String opName = Integer.toString(i);
+ if (index == 0) { // Test the global write lock via multiple threads.
+ callableList.add(() -> {
+ for (int startIndex = 0; startIndex < getLoopNumber(); startIndex++) {
+ writeLock(fsn, FSNamesystemLockMode.GLOBAL, opName, globalCount);
+ globalNumber.incrementAndGet();
+ }
+ return true;
+ });
+ } else if (index == 1) { // Test the fs write lock via multiple threads.
+ callableList.add(() -> {
+ for (int startIndex = 0; startIndex < getLoopNumber(); startIndex++) {
+ writeLock(fsn, FSNamesystemLockMode.FS, opName, fsCount);
+ fsNumber.incrementAndGet();
+ }
+ return true;
+ });
+ } else if (index == 2) { // Test the bm write lock via multiple threads.
+ callableList.add(() -> {
+ for (int startIndex = 0; startIndex < getLoopNumber(); startIndex++) {
+ writeLock(fsn, FSNamesystemLockMode.BM, opName, bmCount);
+ bmNumber.incrementAndGet();
+ }
+ return true;
+ });
+ } else if (index == 3) { // Test the bm read lock via multiple threads.
+ callableList.add(() -> {
+ for (int startIndex = 0; startIndex < getLoopNumber(); startIndex++) {
+ readLock(fsn, FSNamesystemLockMode.BM, opName, bmCount);
+ bmNumber.incrementAndGet();
+ }
+ return true;
+ });
+ } else if (index == 4) { // Test the fs read lock via multiple threads.
+ callableList.add(() -> {
+ for (int startIndex = 0; startIndex < getLoopNumber(); startIndex++) {
+ readLock(fsn, FSNamesystemLockMode.FS, opName, fsCount);
+ fsNumber.incrementAndGet();
+ }
+ return true;
+ });
+ } else if (index == 5) { // Test the global read lock via multiple threads.
+ callableList.add(() -> {
+ for (int startIndex = 0; startIndex < getLoopNumber(); startIndex++) {
+ readLock(fsn, FSNamesystemLockMode.GLOBAL, opName, globalCount);
+ globalNumber.incrementAndGet();
+ }
+ return true;
+ });
+ } else if (index == 6) { // Test the global interruptable write lock via multiple threads.
+ callableList.add(() -> {
+ for (int startIndex = 0; startIndex < getLoopNumber(); startIndex++) {
+ writeLockInterruptibly(fsn, FSNamesystemLockMode.GLOBAL, opName, globalCount);
+ globalNumber.incrementAndGet();
+ }
+ return true;
+ });
+ } else if (index == 7) { // Test the fs interruptable write lock via multiple threads.
+ callableList.add(() -> {
+ for (int startIndex = 0; startIndex < getLoopNumber(); startIndex++) {
+ writeLockInterruptibly(fsn, FSNamesystemLockMode.FS, opName, fsCount);
+ fsNumber.incrementAndGet();
+ }
+ return true;
+ });
+ } else if (index == 8) { // Test the bm interruptable write lock via multiple threads.
+ callableList.add(() -> {
+ for (int startIndex = 0; startIndex < getLoopNumber(); startIndex++) {
+ writeLockInterruptibly(fsn, FSNamesystemLockMode.BM, opName, bmCount);
+ bmNumber.incrementAndGet();
+ }
+ return true;
+ });
+ } else if (index == 9) { // Test the bm interruptable read lock via multiple threads.
+ callableList.add(() -> {
+ for (int startIndex = 0; startIndex < getLoopNumber(); startIndex++) {
+ readLockInterruptibly(fsn, FSNamesystemLockMode.BM, opName, bmCount);
+ bmNumber.incrementAndGet();
+ }
+ return true;
+ });
+ } else if (index == 10) { // Test the fs interruptable read lock via multiple threads.
+ callableList.add(() -> {
+ for (int startIndex = 0; startIndex < getLoopNumber(); startIndex++) {
+ readLockInterruptibly(fsn, FSNamesystemLockMode.FS, opName, fsCount);
+ fsNumber.incrementAndGet();
+ }
+ return true;
+ });
+ } else { // Test the global interruptable read lock via multiple threads.
+ callableList.add(() -> {
+ for (int startIndex = 0; startIndex < getLoopNumber(); startIndex++) {
+ readLockInterruptibly(fsn, FSNamesystemLockMode.GLOBAL, opName, globalCount);
+ globalNumber.incrementAndGet();
+ }
+ return true;
+ });
+ }
+ }
+
+ List<Future<Boolean>> futures = service.invokeAll(callableList);
+ for (Future<Boolean> f : futures) {
+ f.get();
+ }
+ log.info("Global executed {} times, FS executed {} times, BM executed {} times.",
+ globalNumber.get(), fsNumber.get(), bmNumber.get());
+ assert globalCount.get() == 0;
+ assert fsCount.get() == 0;
+ assert bmCount.get() == 0;
+ }
+
+ /**
+ * Test write lock for the input lock mode.
+ * @param fsn FSNLockManager
+ * @param mode LockMode
+ * @param opName operation name
+ * @param counter counter to trace this lock mode
+ */
+ private void writeLock(FSNLockManager fsn, FSNamesystemLockMode mode,
+ String opName, AtomicLong counter) {
+ fsn.writeLock(mode);
+ try {
+ counter.incrementAndGet();
+ } finally {
+ fsn.writeUnlock(mode, opName);
+ }
+ fsn.writeLock(mode);
+ try {
+ counter.decrementAndGet();
+ } finally {
+ fsn.writeUnlock(mode, opName);
+ }
+ }
+
+ /**
+ * Test read lock for the input lock mode.
+ * @param fsn FSNLockManager
+ * @param mode LockMode
+ * @param opName operation name
+ * @param counter counter to trace this lock mode
+ */
+ private void readLock(FSNLockManager fsn, FSNamesystemLockMode mode,
+ String opName, AtomicLong counter) {
+ fsn.readLock(mode);
+ try {
+ counter.get();
+ } finally {
+ fsn.readUnlock(mode, opName);
+ }
+ }
+
+ /**
+ * Test write lock for the input lock mode.
+ * @param fsn FSNLockManager
+ * @param mode LockMode
+ * @param opName operation name
+ * @param counter counter to trace this lock mode
+ */
+ private void writeLockInterruptibly(FSNLockManager fsn, FSNamesystemLockMode mode,
+ String opName, AtomicLong counter) {
+ boolean success = false;
+ try {
+ fsn.writeLockInterruptibly(mode);
+ try {
+ counter.incrementAndGet();
+ success = true;
+ } finally {
+ fsn.writeUnlock(mode, opName);
+ }
+ } catch (InterruptedException e) {
+ log.info("InterruptedException happens in thread {}" +
+ " during increasing the Count.", opName);
+ // ignore;
+ }
+ while (success) {
+ try {
+ fsn.writeLockInterruptibly(mode);
+ try {
+ counter.decrementAndGet();
+ success = false;
+ } finally {
+ fsn.writeUnlock(mode, opName);
+ }
+ } catch (InterruptedException e) {
+ log.info("InterruptedException happens in thread {}" +
+ " during decreasing the Count.", opName);
+ // ignore.
+ }
+ }
+ }
+
+ /**
+ * Test read lock for the input lock mode.
+ * @param fsn FSNLockManager
+ * @param mode LockMode
+ * @param opName operation name
+ * @param counter counter to trace this lock mode
+ */
+ private void readLockInterruptibly(FSNLockManager fsn, FSNamesystemLockMode mode,
+ String opName, AtomicLong counter) {
+ try {
+ fsn.readLockInterruptibly(mode);
+ try {
+ counter.get();
+ } finally {
+ fsn.readUnlock(mode, opName);
+ }
+ } catch (InterruptedException e) {
+ log.info("InterruptedException happens in thread {}" +
+ " during getting the Count.", opName);
+ // ignore
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org
(hadoop) 12/23: HDFS-17415. [FGL] RPCs in NamenodeProtocol support fine-grained lock (#6654)
Posted by za...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zanderxu pushed a commit to branch HDFS-17384
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit ea3cbae809acc4d466e6b6874b0d8d12f6e67d16
Author: ZanderXu <za...@apache.org>
AuthorDate: Wed Mar 27 09:44:11 2024 +0800
HDFS-17415. [FGL] RPCs in NamenodeProtocol support fine-grained lock (#6654)
---
.../hadoop/hdfs/server/namenode/Checkpointer.java | 10 +++++----
.../hadoop/hdfs/server/namenode/FSNamesystem.java | 25 +++++++++++-----------
2 files changed, 19 insertions(+), 16 deletions(-)
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/Checkpointer.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/Checkpointer.java
index ab657fb67249..465aad3ec50b 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/Checkpointer.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/Checkpointer.java
@@ -32,6 +32,7 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.DFSUtil;
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NamenodeRole;
import org.apache.hadoop.hdfs.server.namenode.NNStorage.NameNodeFile;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.protocol.CheckpointCommand;
import org.apache.hadoop.hdfs.server.protocol.NamenodeCommand;
import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocol;
@@ -244,13 +245,14 @@ class Checkpointer extends Daemon {
if(needReloadImage) {
LOG.info("Loading image with txid " + sig.mostRecentCheckpointTxId);
- backupNode.namesystem.writeLock();
+ backupNode.namesystem.writeLock(FSNamesystemLockMode.GLOBAL);
try {
File file = bnStorage.findImageFile(NameNodeFile.IMAGE,
sig.mostRecentCheckpointTxId);
bnImage.reloadFromImageFile(file, backupNode.getNamesystem());
} finally {
- backupNode.namesystem.writeUnlock("doCheckpointByBackupNode");
+ backupNode.namesystem.writeUnlock(
+ FSNamesystemLockMode.GLOBAL, "doCheckpointByBackupNode");
}
}
rollForwardByApplyingLogs(manifest, bnImage, backupNode.getNamesystem());
@@ -258,7 +260,7 @@ class Checkpointer extends Daemon {
long txid = bnImage.getLastAppliedTxId();
- backupNode.namesystem.writeLock();
+ backupNode.namesystem.writeLock(FSNamesystemLockMode.GLOBAL);
try {
backupNode.namesystem.setImageLoaded();
if(backupNode.namesystem.getBlocksTotal() > 0) {
@@ -272,7 +274,7 @@ class Checkpointer extends Daemon {
bnImage.updateStorageVersion();
}
} finally {
- backupNode.namesystem.writeUnlock("doCheckpoint");
+ backupNode.namesystem.writeUnlock(FSNamesystemLockMode.GLOBAL, "doCheckpoint");
}
if(cpCmd.needToReturnImage()) {
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
index dbb5cfbf1951..cbd81c1f5578 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
@@ -1977,13 +1977,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
isGetBlocksCheckOperationEnabled ? OperationCategory.READ :
OperationCategory.UNCHECKED;
checkOperation(checkOp);
- readLock();
+ readLock(FSNamesystemLockMode.BM);
try {
checkOperation(checkOp);
return getBlockManager().getBlocksWithLocations(datanode, size,
minimumBlockSize, timeInterval, storageType);
} finally {
- readUnlock("getBlocks");
+ readUnlock(FSNamesystemLockMode.BM, "getBlocks");
}
}
@@ -5317,7 +5317,8 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
CheckpointSignature result = null;
checkSuperuserPrivilege(operationName);
checkOperation(OperationCategory.JOURNAL);
- writeLock();
+ // Using FSWriteLock to make edit-related operations thread safe.
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.JOURNAL);
checkNameNodeSafeMode("Log not rolled");
@@ -5326,7 +5327,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
}
result = getFSImage().rollEditLog(getEffectiveLayoutVersion());
} finally {
- writeUnlock(operationName, getLockReportInfoSupplier(null));
+ writeUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(null));
}
logAuditEvent(true, operationName, null);
return result;
@@ -5335,7 +5336,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
NamenodeCommand startCheckpoint(NamenodeRegistration backupNode,
NamenodeRegistration activeNamenode) throws IOException {
checkOperation(OperationCategory.CHECKPOINT);
- writeLock();
+ writeLock(FSNamesystemLockMode.GLOBAL);
try {
checkOperation(OperationCategory.CHECKPOINT);
checkNameNodeSafeMode("Checkpoint not started");
@@ -5346,7 +5347,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
getEditLog().logSync();
return cmd;
} finally {
- writeUnlock("startCheckpoint");
+ writeUnlock(FSNamesystemLockMode.GLOBAL, "startCheckpoint");
}
}
@@ -5367,14 +5368,14 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
void endCheckpoint(NamenodeRegistration registration,
CheckpointSignature sig) throws IOException {
checkOperation(OperationCategory.CHECKPOINT);
- readLock();
+ readLock(FSNamesystemLockMode.GLOBAL);
try {
checkOperation(OperationCategory.CHECKPOINT);
checkNameNodeSafeMode("Checkpoint not ended");
LOG.info("End checkpoint for " + registration.getAddress());
getFSImage().endCheckpoint(sig);
} finally {
- readUnlock("endCheckpoint");
+ readUnlock(FSNamesystemLockMode.GLOBAL, "endCheckpoint");
}
}
@@ -6129,7 +6130,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
*/
void registerBackupNode(NamenodeRegistration bnReg,
NamenodeRegistration nnReg) throws IOException {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
if(getNNStorage().getNamespaceID()
!= bnReg.getNamespaceID())
@@ -6143,7 +6144,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
bnReg, nnReg);
}
} finally {
- writeUnlock("registerBackupNode");
+ writeUnlock(FSNamesystemLockMode.FS, "registerBackupNode");
}
}
@@ -6156,7 +6157,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
void releaseBackupNode(NamenodeRegistration registration)
throws IOException {
checkOperation(OperationCategory.WRITE);
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
if(getNNStorage().getNamespaceID()
@@ -6168,7 +6169,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
" node namespaceID = " + registration.getNamespaceID());
getEditLog().releaseBackupStream(registration);
} finally {
- writeUnlock("releaseBackupNode");
+ writeUnlock(FSNamesystemLockMode.FS, "releaseBackupNode");
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org
(hadoop) 19/23: HDFS-17445. [FGL] some operations support fine-grained locking (#6715)
Posted by za...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zanderxu pushed a commit to branch HDFS-17384
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit 724b9fd5cfd4bd2e2c7ca3b00bfb3167b129b060
Author: ZanderXu <za...@apache.org>
AuthorDate: Wed Apr 10 10:08:24 2024 +0800
HDFS-17445. [FGL] some operations support fine-grained locking (#6715)
---
.../hdfs/server/blockmanagement/BlockManager.java | 10 +++---
.../hadoop/hdfs/server/namenode/BackupImage.java | 5 +--
.../hdfs/server/namenode/FSDirErasureCodingOp.java | 2 +-
.../hdfs/server/namenode/FSDirTruncateOp.java | 2 +-
.../hadoop/hdfs/server/namenode/FSNamesystem.java | 40 +++++++++++-----------
.../hdfs/server/namenode/FSPermissionChecker.java | 15 ++++----
.../hdfs/server/namenode/FSTreeTraverser.java | 7 ++--
.../hdfs/server/namenode/FsImageValidation.java | 5 +--
.../hadoop/hdfs/server/namenode/LeaseManager.java | 12 +++----
.../hadoop/hdfs/server/namenode/NameNode.java | 25 +++++++-------
.../hadoop/hdfs/server/namenode/NamenodeFsck.java | 10 +++---
.../hdfs/server/namenode/SecondaryNameNode.java | 5 +--
.../hdfs/server/namenode/TestLeaseManager.java | 2 ++
13 files changed, 75 insertions(+), 65 deletions(-)
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
index 324a89214599..7defb3183a2b 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
@@ -2788,7 +2788,7 @@ public class BlockManager implements BlockStatsMXBean {
* list of blocks that need to be removed from blocksMap
*/
public void removeBlocksAndUpdateSafemodeTotal(BlocksMapUpdateInfo blocks) {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
// In the case that we are a Standby tailing edits from the
// active while in safe-mode, we need to track the total number
// of blocks and safe blocks in the system.
@@ -4112,7 +4112,7 @@ public class BlockManager implements BlockStatsMXBean {
&& !Thread.currentThread().isInterrupted()
&& iter.hasNext()) {
int limit = processed + numBlocksPerIteration;
- namesystem.writeLockInterruptibly();
+ namesystem.writeLockInterruptibly(FSNamesystemLockMode.GLOBAL);
try {
while (iter.hasNext() && processed < limit) {
BlockInfo blk = iter.next();
@@ -4122,7 +4122,7 @@ public class BlockManager implements BlockStatsMXBean {
blk, r);
}
} finally {
- namesystem.writeUnlock("processMisReplicatedBlocks");
+ namesystem.writeUnlock(FSNamesystemLockMode.GLOBAL, "processMisReplicatedBlocks");
}
}
} catch (InterruptedException ex) {
@@ -5660,7 +5660,7 @@ public class BlockManager implements BlockStatsMXBean {
// batch as many operations in the write lock until the queue
// runs dry, or the max lock hold is reached.
int processed = 0;
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.GLOBAL);
metrics.setBlockOpsQueued(queue.size() + 1);
try {
long start = Time.monotonicNow();
@@ -5673,7 +5673,7 @@ public class BlockManager implements BlockStatsMXBean {
action = queue.poll();
} while (action != null);
} finally {
- namesystem.writeUnlock("processQueue");
+ namesystem.writeUnlock(FSNamesystemLockMode.GLOBAL, "processQueue");
metrics.addBlockOpsBatched(processed - 1);
}
} catch (InterruptedException e) {
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/BackupImage.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/BackupImage.java
index 7bde21dcb69e..fc1ff98a400e 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/BackupImage.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/BackupImage.java
@@ -28,6 +28,7 @@ import org.apache.hadoop.hdfs.server.common.HdfsServerConstants;
import org.apache.hadoop.hdfs.server.common.InconsistentFSStateException;
import org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory;
import org.apache.hadoop.hdfs.server.common.Storage.StorageState;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.util.Lists;
import org.apache.hadoop.util.StringUtils;
@@ -218,11 +219,11 @@ public class BackupImage extends FSImage {
}
lastAppliedTxId = logLoader.getLastAppliedTxId();
- getNamesystem().writeLock();
+ getNamesystem().writeLock(FSNamesystemLockMode.FS);
try {
getNamesystem().dir.updateCountForQuota();
} finally {
- getNamesystem().writeUnlock("applyEdits");
+ getNamesystem().writeUnlock(FSNamesystemLockMode.FS, "applyEdits");
}
} finally {
backupInputStream.clear();
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirErasureCodingOp.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirErasureCodingOp.java
index 6237862ed4bb..8fe05a9463af 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirErasureCodingOp.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirErasureCodingOp.java
@@ -430,7 +430,7 @@ final class FSDirErasureCodingOp {
*/
static ErasureCodingPolicyInfo[] getErasureCodingPolicies(
final FSNamesystem fsn) throws IOException {
- assert fsn.hasReadLock();
+ assert fsn.hasReadLock(FSNamesystemLockMode.FS);
return fsn.getErasureCodingPolicyManager().getPolicies();
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirTruncateOp.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirTruncateOp.java
index e956f9ca7116..8c7007e42394 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirTruncateOp.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirTruncateOp.java
@@ -176,7 +176,7 @@ final class FSDirTruncateOp {
final long newLength, final long mtime, final Block truncateBlock)
throws UnresolvedLinkException, QuotaExceededException,
SnapshotAccessControlException, IOException {
- assert fsn.hasWriteLock();
+ assert fsn.hasWriteLock(FSNamesystemLockMode.GLOBAL);
FSDirectory fsd = fsn.getFSDirectory();
INodeFile file = iip.getLastINode().asFile();
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
index 92865b1a7e60..a9d24192cc62 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
@@ -703,12 +703,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
void setImageLoaded() {
if(imageLoaded) return;
- writeLock();
+ writeLock(FSNamesystemLockMode.GLOBAL);
try {
setImageLoaded(true);
dir.markNameCacheInitialized();
} finally {
- writeUnlock("setImageLoaded");
+ writeUnlock(FSNamesystemLockMode.GLOBAL, "setImageLoaded");
}
}
@@ -1283,7 +1283,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
startOpt = StartupOption.REGULAR;
}
boolean success = false;
- writeLock();
+ writeLock(FSNamesystemLockMode.GLOBAL);
try {
// We shouldn't be calling saveNamespace if we've come up in standby state.
MetaRecoveryContext recovery = startOpt.createRecoveryContext();
@@ -1315,7 +1315,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
if (!success) {
fsImage.close();
}
- writeUnlock("loadFSImage", true);
+ writeUnlock(FSNamesystemLockMode.GLOBAL, "loadFSImage", true);
}
imageLoadComplete();
}
@@ -1386,7 +1386,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
* Stop services common to both active and standby states
*/
void stopCommonServices() {
- writeLock();
+ writeLock(FSNamesystemLockMode.GLOBAL);
if (inodeAttributeProvider != null) {
dir.setINodeAttributeProvider(null);
inodeAttributeProvider.stop();
@@ -1394,7 +1394,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
try {
if (blockManager != null) blockManager.close();
} finally {
- writeUnlock("stopCommonServices");
+ writeUnlock(FSNamesystemLockMode.GLOBAL, "stopCommonServices");
}
RetryCache.clear(retryCache);
}
@@ -1523,7 +1523,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
*/
void stopActiveServices() {
LOG.info("Stopping services started for active state");
- writeLock();
+ writeLock(FSNamesystemLockMode.GLOBAL);
try {
if (blockManager != null) {
blockManager.stopReconstructionInitializer();
@@ -1571,7 +1571,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
blockManager.setInitializedReplQueues(false);
}
} finally {
- writeUnlock("stopActiveServices");
+ writeUnlock(FSNamesystemLockMode.GLOBAL, "stopActiveServices");
}
}
@@ -4652,7 +4652,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
List<BlockCollection> filesToDelete = new ArrayList<>();
boolean changed = false;
- writeLock();
+ writeLock(FSNamesystemLockMode.GLOBAL);
try {
final Iterator<BlockInfo> it =
blockManager.getCorruptReplicaBlockIterator();
@@ -4683,7 +4683,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
}
}
} finally {
- writeUnlock("clearCorruptLazyPersistFiles");
+ writeUnlock(FSNamesystemLockMode.GLOBAL, "clearCorruptLazyPersistFiles");
}
if (changed) {
getEditLog().logSync();
@@ -4980,12 +4980,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
}
int getNumberOfDatanodes(DatanodeReportType type) {
- readLock();
+ readLock(FSNamesystemLockMode.BM);
try {
return getBlockManager().getDatanodeManager().getDatanodeListForReport(
type).size();
} finally {
- readUnlock("getNumberOfDatanodes");
+ readUnlock(FSNamesystemLockMode.BM, "getNumberOfDatanodes");
}
}
@@ -5214,12 +5214,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
public long getCompleteBlocksTotal() {
// Calculate number of blocks under construction
long numUCBlocks = 0;
- readLock();
+ readLock(FSNamesystemLockMode.GLOBAL);
try {
numUCBlocks = leaseManager.getNumUnderConstructionBlocks();
return getBlocksTotal() - numUCBlocks;
} finally {
- readUnlock("getCompleteBlocksTotal");
+ readUnlock(FSNamesystemLockMode.GLOBAL, "getCompleteBlocksTotal");
}
}
@@ -7646,7 +7646,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
if (upgradeInfo.createdRollbackImages()) {
return new RollingUpgradeInfo.Bean(upgradeInfo);
}
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
// check again after acquiring the read lock.
upgradeInfo = getRollingUpgradeInfo();
@@ -7660,7 +7660,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
} catch (IOException ioe) {
LOG.warn("Encountered exception setting Rollback Image", ioe);
} finally {
- readUnlock("getRollingUpgradeStatus");
+ readUnlock(FSNamesystemLockMode.FS, "getRollingUpgradeStatus");
}
return new RollingUpgradeInfo.Bean(upgradeInfo);
}
@@ -7743,7 +7743,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final String operationName = "finalizeRollingUpgrade";
checkSuperuserPrivilege(operationName);
checkOperation(OperationCategory.WRITE);
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
if (!isRollingUpgrade()) {
@@ -7761,7 +7761,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
getFSImage().renameCheckpoint(NameNodeFile.IMAGE_ROLLBACK,
NameNodeFile.IMAGE);
} finally {
- writeUnlock(operationName, getLockReportInfoSupplier(null));
+ writeUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(null));
}
if (!haEnabled) {
@@ -8736,7 +8736,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
@Override
public void removeXattr(long id, String xattrName) throws IOException {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
final INode inode = dir.getInode(id);
if (inode == null) {
@@ -8752,7 +8752,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
FSDirSatisfyStoragePolicyOp.removeSPSXattr(dir, inode, spsXAttr);
}
} finally {
- writeUnlock("removeXAttr");
+ writeUnlock(FSNamesystemLockMode.FS, "removeXAttr");
}
getEditLog().logSync();
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSPermissionChecker.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSPermissionChecker.java
index b432be398977..e8169606577e 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSPermissionChecker.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSPermissionChecker.java
@@ -25,6 +25,7 @@ import java.util.Optional;
import java.util.Stack;
import java.util.function.LongFunction;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.util.Preconditions;
import org.apache.hadoop.ipc.CallerContext;
import org.apache.hadoop.util.Time;
@@ -49,7 +50,7 @@ import org.apache.hadoop.security.UserGroupInformation;
* The state of this class need not be synchronized as it has data structures that
* are read-only.
*
- * Some of the helper methods are guarded by {@link FSNamesystem#readLock()}.
+ * Some of the helper methods are guarded by {@link FSNamesystem#readLock(FSNamesystemLockMode)}.
*/
public class FSPermissionChecker implements AccessControlEnforcer {
static final Logger LOG = LoggerFactory.getLogger(UserGroupInformation.class);
@@ -341,7 +342,7 @@ public class FSPermissionChecker implements AccessControlEnforcer {
* @param ignoreEmptyDir Ignore permission checking for empty directory?
* @throws AccessControlException
*
- * Guarded by {@link FSNamesystem#readLock()}
+ * Guarded by {@link FSNamesystem#readLock(FSNamesystemLockMode)}
* Caller of this method must hold that lock.
*/
void checkPermission(INodesInPath inodesInPath, boolean doCheckOwner,
@@ -554,7 +555,7 @@ public class FSPermissionChecker implements AccessControlEnforcer {
return inodeAttrs;
}
- /** Guarded by {@link FSNamesystem#readLock()} */
+ /** Guarded by {@link FSNamesystem#readLock(FSNamesystemLockMode)}. */
private void checkOwner(INodeAttributes[] inodes, byte[][] components, int i)
throws AccessControlException {
if (getUser().equals(inodes[i].getUserName())) {
@@ -565,7 +566,7 @@ public class FSPermissionChecker implements AccessControlEnforcer {
" is not the owner of inode=" + getPath(components, 0, i));
}
- /** Guarded by {@link FSNamesystem#readLock()}
+ /** Guarded by {@link FSNamesystem#readLock(FSNamesystemLockMode)}.
* @throws AccessControlException
* @throws ParentNotDirectoryException
* @throws UnresolvedPathException
@@ -579,7 +580,7 @@ public class FSPermissionChecker implements AccessControlEnforcer {
}
}
- /** Guarded by {@link FSNamesystem#readLock()} */
+ /** Guarded by {@link FSNamesystem#readLock(FSNamesystemLockMode)}. */
private void checkSubAccess(byte[][] components, int pathIdx,
INode inode, int snapshotId, FsAction access, boolean ignoreEmptyDir)
throws AccessControlException {
@@ -653,7 +654,7 @@ public class FSPermissionChecker implements AccessControlEnforcer {
}
}
- /** Guarded by {@link FSNamesystem#readLock()} */
+ /** Guarded by {@link FSNamesystem#readLock(FSNamesystemLockMode)}. */
private void check(INodeAttributes[] inodes, byte[][] components, int i,
FsAction access) throws AccessControlException {
INodeAttributes inode = (i >= 0) ? inodes[i] : null;
@@ -767,7 +768,7 @@ public class FSPermissionChecker implements AccessControlEnforcer {
return !foundMatch && mode.getOtherAction().implies(access);
}
- /** Guarded by {@link FSNamesystem#readLock()} */
+ /** Guarded by {@link FSNamesystem#readLock(FSNamesystemLockMode)}. */
private void checkStickyBit(INodeAttributes[] inodes, byte[][] components,
int index) throws AccessControlException {
INodeAttributes parent = inodes[index];
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSTreeTraverser.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSTreeTraverser.java
index c1d26f40c082..12b04d221a7e 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSTreeTraverser.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSTreeTraverser.java
@@ -28,6 +28,7 @@ import java.util.List;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot;
import org.apache.hadoop.hdfs.util.ReadOnlyList;
import org.apache.hadoop.util.Timer;
@@ -127,7 +128,7 @@ public abstract class FSTreeTraverser {
List<byte[]> startAfters, final TraverseInfo traverseInfo)
throws IOException, InterruptedException {
assert dir.hasReadLock();
- assert dir.getFSNamesystem().hasReadLock();
+ assert dir.getFSNamesystem().hasReadLock(FSNamesystemLockMode.FS);
long lockStartTime = timer.monotonicNow();
Preconditions.checkNotNull(curr, "Current inode can't be null");
checkINodeReady(startId);
@@ -261,13 +262,13 @@ public abstract class FSTreeTraverser {
}
protected void readLock() {
- dir.getFSNamesystem().readLock();
+ dir.getFSNamesystem().readLock(FSNamesystemLockMode.FS);
dir.readLock();
}
protected void readUnlock() {
dir.readUnlock();
- dir.getFSNamesystem().readUnlock("FSTreeTraverser");
+ dir.getFSNamesystem().readUnlock(FSNamesystemLockMode.FS, "FSTreeTraverser");
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FsImageValidation.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FsImageValidation.java
index 275be9050511..4752f11e09ce 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FsImageValidation.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FsImageValidation.java
@@ -26,6 +26,7 @@ import org.apache.hadoop.hdfs.server.blockmanagement.BlockManager;
import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeManager;
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants;
import org.apache.hadoop.hdfs.server.common.Storage;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.namenode.startupprogress.Phase;
import org.apache.hadoop.hdfs.server.namenode.NNStorage.NameNodeFile;
import org.apache.hadoop.hdfs.server.namenode.top.metrics.TopMetrics;
@@ -272,13 +273,13 @@ public class FsImageValidation {
final FSImageFormat.LoaderDelegator loader
= FSImageFormat.newLoader(conf, namesystem);
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.GLOBAL);
namesystem.getFSDirectory().writeLock();
try {
loader.load(fsImageFile, false);
} finally {
namesystem.getFSDirectory().writeUnlock();
- namesystem.writeUnlock("loadImage");
+ namesystem.writeUnlock(FSNamesystemLockMode.GLOBAL, "loadImage");
}
}
t.cancel();
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java
index c2e01ffe266f..df1dc3549856 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java
@@ -136,8 +136,8 @@ public class LeaseManager {
* calling this method.
*/
synchronized long getNumUnderConstructionBlocks() {
- assert this.fsnamesystem.hasReadLock() : "The FSNamesystem read lock wasn't"
- + "acquired before counting under construction blocks";
+ assert this.fsnamesystem.hasReadLock(FSNamesystemLockMode.GLOBAL) :
+ "The FSNamesystem read lock wasn't acquired before counting under construction blocks";
long numUCBlocks = 0;
for (Long id : getINodeIdWithLeases()) {
INode inode = fsnamesystem.getFSDirectory().getInode(id);
@@ -208,7 +208,7 @@ public class LeaseManager {
*/
public Set<INodesInPath> getINodeWithLeases(final INodeDirectory
ancestorDir) throws IOException {
- assert fsnamesystem.hasReadLock();
+ assert fsnamesystem.hasReadLock(FSNamesystemLockMode.FS);
final long startTimeMs = Time.monotonicNow();
Set<INodesInPath> iipSet = new HashSet<>();
final INode[] inodes = getINodesWithLease();
@@ -543,13 +543,13 @@ public class LeaseManager {
continue;
}
- fsnamesystem.writeLockInterruptibly();
+ fsnamesystem.writeLockInterruptibly(FSNamesystemLockMode.GLOBAL);
try {
if (!fsnamesystem.isInSafeMode()) {
needSync = checkLeases(candidates);
}
} finally {
- fsnamesystem.writeUnlock("leaseManager");
+ fsnamesystem.writeUnlock(FSNamesystemLockMode.GLOBAL, "leaseManager");
// lease reassignments should to be sync'ed.
if (needSync) {
fsnamesystem.getEditLog().logSync();
@@ -574,7 +574,7 @@ public class LeaseManager {
private synchronized boolean checkLeases(Collection<Lease> leasesToCheck) {
boolean needSync = false;
- assert fsnamesystem.hasWriteLock();
+ assert fsnamesystem.hasWriteLock(FSNamesystemLockMode.GLOBAL);
long start = monotonicNow();
for (Lease leaseToCheck : leasesToCheck) {
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java
index a48cfdbe5957..c42d75678283 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java
@@ -20,6 +20,7 @@ package org.apache.hadoop.hdfs.server.namenode;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.hadoop.classification.VisibleForTesting;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.ipc.CallerContext;
import org.apache.hadoop.thirdparty.com.google.common.base.Joiner;
import org.apache.hadoop.util.Preconditions;
@@ -2238,14 +2239,14 @@ public class NameNode extends ReconfigurableBase implements
@Override
public void writeLock() {
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.GLOBAL);
namesystem.lockRetryCache();
}
@Override
public void writeUnlock() {
namesystem.unlockRetryCache();
- namesystem.writeUnlock("HAState");
+ namesystem.writeUnlock(FSNamesystemLockMode.GLOBAL, "HAState");
}
/** Check if an operation of given category is allowed */
@@ -2396,7 +2397,7 @@ public class NameNode extends ReconfigurableBase implements
final String property) throws ReconfigurationException {
BlockManager bm = namesystem.getBlockManager();
int newSetting;
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.BM);
try {
if (property.equals(DFS_NAMENODE_REPLICATION_MAX_STREAMS_KEY)) {
bm.setMaxReplicationStreams(
@@ -2434,7 +2435,7 @@ public class NameNode extends ReconfigurableBase implements
throw new ReconfigurationException(property, newVal, getConf().get(
property), e);
} finally {
- namesystem.writeUnlock("reconfReplicationParameters");
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "reconfReplicationParameters");
}
}
@@ -2454,7 +2455,7 @@ public class NameNode extends ReconfigurableBase implements
private String reconfHeartbeatInterval(final DatanodeManager datanodeManager,
final String property, final String newVal)
throws ReconfigurationException {
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.BM);
try {
if (newVal == null) {
// set to default
@@ -2471,7 +2472,7 @@ public class NameNode extends ReconfigurableBase implements
throw new ReconfigurationException(property, newVal, getConf().get(
property), nfe);
} finally {
- namesystem.writeUnlock("reconfHeartbeatInterval");
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "reconfHeartbeatInterval");
LOG.info("RECONFIGURE* changed heartbeatInterval to "
+ datanodeManager.getHeartbeatInterval());
}
@@ -2480,7 +2481,7 @@ public class NameNode extends ReconfigurableBase implements
private String reconfHeartbeatRecheckInterval(
final DatanodeManager datanodeManager, final String property,
final String newVal) throws ReconfigurationException {
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.BM);
try {
if (newVal == null) {
// set to default
@@ -2495,7 +2496,7 @@ public class NameNode extends ReconfigurableBase implements
throw new ReconfigurationException(property, newVal, getConf().get(
property), nfe);
} finally {
- namesystem.writeUnlock("reconfHeartbeatRecheckInterval");
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "reconfHeartbeatRecheckInterval");
LOG.info("RECONFIGURE* changed heartbeatRecheckInterval to "
+ datanodeManager.getHeartbeatRecheckInterval());
}
@@ -2620,7 +2621,7 @@ public class NameNode extends ReconfigurableBase implements
String reconfigureSlowNodesParameters(final DatanodeManager datanodeManager,
final String property, final String newVal) throws ReconfigurationException {
BlockManager bm = namesystem.getBlockManager();
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.BM);
String result;
try {
switch (property) {
@@ -2697,13 +2698,13 @@ public class NameNode extends ReconfigurableBase implements
throw new ReconfigurationException(property, newVal, getConf().get(
property), e);
} finally {
- namesystem.writeUnlock("reconfigureSlowNodesParameters");
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "reconfigureSlowNodesParameters");
}
}
private String reconfigureBlockInvalidateLimit(final DatanodeManager datanodeManager,
final String property, final String newVal) throws ReconfigurationException {
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.BM);
try {
if (newVal == null) {
datanodeManager.setBlockInvalidateLimit(DFSConfigKeys.DFS_BLOCK_INVALIDATE_LIMIT_DEFAULT);
@@ -2717,7 +2718,7 @@ public class NameNode extends ReconfigurableBase implements
} catch (NumberFormatException e) {
throw new ReconfigurationException(property, newVal, getConf().get(property), e);
} finally {
- namesystem.writeUnlock("reconfigureBlockInvalidateLimit");
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "reconfigureBlockInvalidateLimit");
}
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NamenodeFsck.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NamenodeFsck.java
index bc6df0141c64..5c2ddfbdd0c2 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NamenodeFsck.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NamenodeFsck.java
@@ -38,6 +38,7 @@ import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
import org.apache.hadoop.hdfs.server.blockmanagement.BlockUnderConstructionFeature;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -289,7 +290,8 @@ public class NamenodeFsck implements DataEncryptionKeyFactory {
return;
}
- namenode.getNamesystem().readLock();
+ // TODO: Just hold the BM read lock.
+ namenode.getNamesystem().readLock(FSNamesystemLockMode.GLOBAL);
try {
//get blockInfo
Block block = new Block(Block.getBlockId(blockId));
@@ -353,7 +355,7 @@ public class NamenodeFsck implements DataEncryptionKeyFactory {
out.print("\n\n" + errMsg);
LOG.warn("Error in looking up block", e);
} finally {
- namenode.getNamesystem().readUnlock("fsck");
+ namenode.getNamesystem().readUnlock(FSNamesystemLockMode.GLOBAL, "fsck");
}
}
@@ -585,7 +587,7 @@ public class NamenodeFsck implements DataEncryptionKeyFactory {
final String operationName = "fsckGetBlockLocations";
FSPermissionChecker.setOperationType(operationName);
FSPermissionChecker pc = fsn.getPermissionChecker();
- fsn.readLock();
+ fsn.readLock(FSNamesystemLockMode.GLOBAL);
try {
blocks = FSDirStatAndListingOp.getBlockLocations(
fsn.getFSDirectory(), pc,
@@ -594,7 +596,7 @@ public class NamenodeFsck implements DataEncryptionKeyFactory {
} catch (FileNotFoundException fnfe) {
blocks = null;
} finally {
- fsn.readUnlock(operationName);
+ fsn.readUnlock(FSNamesystemLockMode.GLOBAL, operationName);
}
return blocks;
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/SecondaryNameNode.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/SecondaryNameNode.java
index e95200b35aaa..910b9568eb1e 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/SecondaryNameNode.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/SecondaryNameNode.java
@@ -37,6 +37,7 @@ import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hadoop.HadoopIllegalArgumentException;
@@ -1094,11 +1095,11 @@ public class SecondaryNameNode implements Runnable,
sig.mostRecentCheckpointTxId + " even though it should have " +
"just been downloaded");
}
- dstNamesystem.writeLock();
+ dstNamesystem.writeLock(FSNamesystemLockMode.GLOBAL);
try {
dstImage.reloadFromImageFile(file, dstNamesystem);
} finally {
- dstNamesystem.writeUnlock("reloadFromImageFile");
+ dstNamesystem.writeUnlock(FSNamesystemLockMode.GLOBAL, "reloadFromImageFile");
}
dstNamesystem.imageLoadComplete();
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestLeaseManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestLeaseManager.java
index 6be34537a050..5e6ab565a3eb 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestLeaseManager.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestLeaseManager.java
@@ -469,6 +469,8 @@ public class TestLeaseManager {
when(fsn.hasWriteLock()).thenReturn(true);
when(fsn.hasReadLock(FSNamesystemLockMode.FS)).thenReturn(true);
when(fsn.hasWriteLock(FSNamesystemLockMode.FS)).thenReturn(true);
+ when(fsn.hasReadLock(FSNamesystemLockMode.GLOBAL)).thenReturn(true);
+ when(fsn.hasWriteLock(FSNamesystemLockMode.GLOBAL)).thenReturn(true);
when(fsn.getFSDirectory()).thenReturn(dir);
when(fsn.getMaxLockHoldToReleaseLeaseMs()).thenReturn(maxLockHoldToReleaseLeaseMs);
return fsn;
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org
(hadoop) 01/23: HDFS-17394. [FGL] Remove unused WriteHoldCount of FSNamesystemLock (#6571)
Posted by za...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zanderxu pushed a commit to branch HDFS-17384
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit c4ba19c23b4f97787331ddbe09e07e6d5e16d459
Author: ZanderXu <za...@apache.org>
AuthorDate: Tue Feb 27 14:12:02 2024 +0800
HDFS-17394. [FGL] Remove unused WriteHoldCount of FSNamesystemLock (#6571)
---
.../hdfs/server/namenode/ContentSummaryComputationContext.java | 3 +--
.../org/apache/hadoop/hdfs/server/namenode/FSDirectory.java | 10 ----------
.../org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java | 4 ----
3 files changed, 1 insertion(+), 16 deletions(-)
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ContentSummaryComputationContext.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ContentSummaryComputationContext.java
index 61a34828f14d..bbebe78fb1f6 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ContentSummaryComputationContext.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ContentSummaryComputationContext.java
@@ -123,8 +123,7 @@ public class ContentSummaryComputationContext {
// sanity check.
if (!hadDirReadLock || !hadFsnReadLock || hadDirWriteLock ||
- hadFsnWriteLock || dir.getReadHoldCount() != 1 ||
- fsn.getReadHoldCount() != 1) {
+ hadFsnWriteLock || fsn.getReadHoldCount() != 1) {
// cannot relinquish
return false;
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java
index 516e87d11f5a..96fa1b4ad4d0 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java
@@ -285,16 +285,6 @@ public class FSDirectory implements Closeable {
return namesystem.hasReadLock();
}
- @Deprecated // dirLock is obsolete, use namesystem.fsLock instead
- public int getReadHoldCount() {
- return namesystem.getReadHoldCount();
- }
-
- @Deprecated // dirLock is obsolete, use namesystem.fsLock instead
- public int getWriteHoldCount() {
- return namesystem.getWriteHoldCount();
- }
-
public int getListLimit() {
return lsLimit;
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
index e21c24398680..8470eac05f83 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
@@ -1853,10 +1853,6 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
return this.fsLock.getReadHoldCount();
}
- public int getWriteHoldCount() {
- return this.fsLock.getWriteHoldCount();
- }
-
/** Lock the checkpoint lock */
public void cpLock() {
this.cpLock.lock();
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org
(hadoop) 16/23: HDFS-17388. [FGL] Client RPCs involving write process supports fine-grained lock (#6589)
Posted by za...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zanderxu pushed a commit to branch HDFS-17384
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit f0da5122e6d86f0410aee49da1eab5a95ac182cc
Author: ZanderXu <za...@apache.org>
AuthorDate: Fri Mar 29 18:16:07 2024 +0800
HDFS-17388. [FGL] Client RPCs involving write process supports fine-grained lock (#6589)
---
.../hdfs/server/blockmanagement/BlockManager.java | 2 +-
.../hadoop/hdfs/server/namenode/FSDirAppendOp.java | 5 +-
.../hadoop/hdfs/server/namenode/FSDirDeleteOp.java | 4 +-
.../server/namenode/FSDirEncryptionZoneOp.java | 8 +-
.../server/namenode/FSDirStatAndListingOp.java | 25 ++++--
.../hdfs/server/namenode/FSDirWriteFileOp.java | 43 +++++-----
.../hadoop/hdfs/server/namenode/FSNamesystem.java | 96 +++++++++++-----------
.../hadoop/hdfs/server/namenode/INodeFile.java | 6 ++
8 files changed, 107 insertions(+), 82 deletions(-)
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
index cf3ec7964c06..324a89214599 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
@@ -1579,7 +1579,7 @@ public class BlockManager implements BlockStatsMXBean {
final boolean inSnapshot, FileEncryptionInfo feInfo,
ErasureCodingPolicy ecPolicy)
throws IOException {
- assert namesystem.hasReadLock();
+ assert namesystem.hasReadLock(FSNamesystemLockMode.BM);
if (blocks == null) {
return null;
} else if (blocks.length == 0) {
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirAppendOp.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirAppendOp.java
index ba00e8ae936a..058928c41abb 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirAppendOp.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirAppendOp.java
@@ -38,6 +38,7 @@ import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.BlockUCState;
import org.apache.hadoop.hdfs.server.namenode.FSDirectory.DirOp;
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem.RecoverLeaseOp;
import org.apache.hadoop.hdfs.server.namenode.NameNodeLayoutVersion.Feature;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.ipc.RetriableException;
import org.apache.hadoop.util.Preconditions;
@@ -82,7 +83,7 @@ final class FSDirAppendOp {
final String srcArg, final FSPermissionChecker pc, final String holder,
final String clientMachine, final boolean newBlock,
final boolean logRetryCache) throws IOException {
- assert fsn.hasWriteLock();
+ assert fsn.hasWriteLock(FSNamesystemLockMode.GLOBAL);
final LocatedBlock lb;
final FSDirectory fsd = fsn.getFSDirectory();
@@ -180,7 +181,7 @@ final class FSDirAppendOp {
final String clientMachine, final boolean newBlock,
final boolean writeToEditLog, final boolean logRetryCache)
throws IOException {
- assert fsn.hasWriteLock();
+ assert fsn.hasWriteLock(FSNamesystemLockMode.GLOBAL);
final INodeFile file = iip.getLastINode().asFile();
final QuotaCounts delta = verifyQuotaForUCBlock(fsn, file, iip);
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirDeleteOp.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirDeleteOp.java
index 2dfb90ee6728..f513357d9c53 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirDeleteOp.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirDeleteOp.java
@@ -24,6 +24,7 @@ import org.apache.hadoop.hdfs.DFSUtil;
import org.apache.hadoop.hdfs.server.namenode.FSDirectory.DirOp;
import org.apache.hadoop.hdfs.server.namenode.INode.BlocksMapUpdateInfo;
import org.apache.hadoop.hdfs.server.namenode.INode.ReclaimContext;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.util.ChunkedArrayList;
import java.io.IOException;
@@ -170,7 +171,8 @@ class FSDirDeleteOp {
static BlocksMapUpdateInfo deleteInternal(
FSNamesystem fsn, INodesInPath iip, boolean logRetryCache)
throws IOException {
- assert fsn.hasWriteLock();
+ // Delete INode and modify BlockInfo
+ assert fsn.hasWriteLock(FSNamesystemLockMode.GLOBAL);
if (NameNode.stateChangeLog.isDebugEnabled()) {
NameNode.stateChangeLog.debug("DIR* NameSystem.delete: " + iip.getPath());
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirEncryptionZoneOp.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirEncryptionZoneOp.java
index 9520139577ba..0ce2ce75151b 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirEncryptionZoneOp.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirEncryptionZoneOp.java
@@ -84,8 +84,8 @@ final class FSDirEncryptionZoneOp {
private static EncryptedKeyVersion generateEncryptedDataEncryptionKey(
final FSDirectory fsd, final String ezKeyName) throws IOException {
// must not be holding lock during this operation
- assert !fsd.getFSNamesystem().hasReadLock();
- assert !fsd.getFSNamesystem().hasWriteLock();
+ assert !fsd.getFSNamesystem().hasReadLock(FSNamesystemLockMode.FS);
+ assert !fsd.getFSNamesystem().hasWriteLock(FSNamesystemLockMode.FS);
if (ezKeyName == null) {
return null;
}
@@ -657,13 +657,13 @@ final class FSDirEncryptionZoneOp {
Preconditions.checkNotNull(ezKeyName);
// Generate EDEK while not holding the fsn lock.
- fsn.writeUnlock("getEncryptionKeyInfo");
+ fsn.writeUnlock(FSNamesystemLockMode.FS, "getEncryptionKeyInfo");
try {
EncryptionFaultInjector.getInstance().startFileBeforeGenerateKey();
return new EncryptionKeyInfo(protocolVersion, suite, ezKeyName,
generateEncryptedDataEncryptionKey(fsd, ezKeyName));
} finally {
- fsn.writeLock();
+ fsn.writeLock(FSNamesystemLockMode.FS);
EncryptionFaultInjector.getInstance().startFileAfterGenerateKey();
}
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirStatAndListingOp.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirStatAndListingOp.java
index 4547228364d5..2fe8c307d2cd 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirStatAndListingOp.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirStatAndListingOp.java
@@ -18,6 +18,7 @@
package org.apache.hadoop.hdfs.server.namenode;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.util.Preconditions;
import org.apache.hadoop.fs.ContentSummary;
@@ -444,16 +445,22 @@ class FSDirStatAndListingOp {
if (isEncrypted) {
feInfo = FSDirEncryptionZoneOp.getFileEncryptionInfo(fsd, iip);
}
+ // ComputeFileSize and needLocation need BM lock.
if (needLocation) {
- final boolean inSnapshot = snapshot != Snapshot.CURRENT_STATE_ID;
- final boolean isUc = !inSnapshot && fileNode.isUnderConstruction();
- final long fileSize = !inSnapshot && isUc
- ? fileNode.computeFileSizeNotIncludingLastUcBlock() : size;
- loc = fsd.getBlockManager().createLocatedBlocks(
- fileNode.getBlocks(snapshot), fileSize, isUc, 0L, size,
- needBlockToken, inSnapshot, feInfo, ecPolicy);
- if (loc == null) {
- loc = new LocatedBlocks();
+ fsd.getFSNamesystem().readLock(FSNamesystemLockMode.BM);
+ try {
+ final boolean inSnapshot = snapshot != Snapshot.CURRENT_STATE_ID;
+ final boolean isUc = !inSnapshot && fileNode.isUnderConstruction();
+ final long fileSize = !inSnapshot && isUc
+ ? fileNode.computeFileSizeNotIncludingLastUcBlock() : size;
+ loc = fsd.getBlockManager().createLocatedBlocks(
+ fileNode.getBlocks(snapshot), fileSize, isUc, 0L, size,
+ needBlockToken, inSnapshot, feInfo, ecPolicy);
+ if (loc == null) {
+ loc = new LocatedBlocks();
+ }
+ } finally {
+ fsd.getFSNamesystem().readUnlock(FSNamesystemLockMode.BM, "createFileStatus");
}
}
} else if (node.isDirectory()) {
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirWriteFileOp.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirWriteFileOp.java
index 37000421abcb..3067162e3a1e 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirWriteFileOp.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirWriteFileOp.java
@@ -364,7 +364,7 @@ class FSDirWriteFileOp {
boolean shouldReplicate, String ecPolicyName, String storagePolicy,
boolean logRetryEntry)
throws IOException {
- assert fsn.hasWriteLock();
+ assert fsn.hasWriteLock(FSNamesystemLockMode.FS);
boolean overwrite = flag.contains(CreateFlag.OVERWRITE);
boolean isLazyPersist = flag.contains(CreateFlag.LAZY_PERSIST);
@@ -372,22 +372,27 @@ class FSDirWriteFileOp {
FSDirectory fsd = fsn.getFSDirectory();
if (iip.getLastINode() != null) {
- if (overwrite) {
- List<INode> toRemoveINodes = new ChunkedArrayList<>();
- List<Long> toRemoveUCFiles = new ChunkedArrayList<>();
- long ret = FSDirDeleteOp.delete(fsd, iip, toRemoveBlocks,
- toRemoveINodes, toRemoveUCFiles, now());
- if (ret >= 0) {
- iip = INodesInPath.replace(iip, iip.length() - 1, null);
- FSDirDeleteOp.incrDeletedFileCount(ret);
- fsn.removeLeasesAndINodes(toRemoveUCFiles, toRemoveINodes, true);
+ fsn.writeLock(FSNamesystemLockMode.BM);
+ try {
+ if (overwrite) {
+ List<INode> toRemoveINodes = new ChunkedArrayList<>();
+ List<Long> toRemoveUCFiles = new ChunkedArrayList<>();
+ long ret = FSDirDeleteOp.delete(fsd, iip, toRemoveBlocks,
+ toRemoveINodes, toRemoveUCFiles, now());
+ if (ret >= 0) {
+ iip = INodesInPath.replace(iip, iip.length() - 1, null);
+ FSDirDeleteOp.incrDeletedFileCount(ret);
+ fsn.removeLeasesAndINodes(toRemoveUCFiles, toRemoveINodes, true);
+ }
+ } else {
+ // If lease soft limit time is expired, recover the lease
+ fsn.recoverLeaseInternal(FSNamesystem.RecoverLeaseOp.CREATE_FILE, iip,
+ src, holder, clientMachine, false);
+ throw new FileAlreadyExistsException(src + " for client " +
+ clientMachine + " already exists");
}
- } else {
- // If lease soft limit time is expired, recover the lease
- fsn.recoverLeaseInternal(FSNamesystem.RecoverLeaseOp.CREATE_FILE, iip,
- src, holder, clientMachine, false);
- throw new FileAlreadyExistsException(src + " for client " +
- clientMachine + " already exists");
+ } finally {
+ fsn.writeUnlock(FSNamesystemLockMode.BM, "create");
}
}
fsn.checkFsObjectLimit();
@@ -597,7 +602,7 @@ class FSDirWriteFileOp {
FSNamesystem fsn, INodesInPath iip, long fileId, String clientName,
ExtendedBlock previous, LocatedBlock[] onRetryBlock)
throws IOException {
- assert fsn.hasReadLock();
+ assert fsn.hasReadLock(FSNamesystemLockMode.GLOBAL);
String src = iip.getPath();
checkBlock(fsn, previous);
onRetryBlock[0] = null;
@@ -695,7 +700,7 @@ class FSDirWriteFileOp {
FSNamesystem fsn, INodesInPath iip,
String holder, Block last, long fileId)
throws IOException {
- assert fsn.hasWriteLock();
+ assert fsn.hasWriteLock(FSNamesystemLockMode.GLOBAL);
final String src = iip.getPath();
final INodeFile pendingFile;
INode inode = null;
@@ -779,7 +784,7 @@ class FSDirWriteFileOp {
static void saveAllocatedBlock(FSNamesystem fsn, String src,
INodesInPath inodesInPath, Block newBlock, DatanodeStorageInfo[] targets,
BlockType blockType) throws IOException {
- assert fsn.hasWriteLock();
+ assert fsn.hasWriteLock(FSNamesystemLockMode.GLOBAL);
BlockInfo b = addBlock(fsn.dir, src, inodesInPath, newBlock, targets,
blockType);
logAllocatedBlock(src, b);
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
index fb983974458b..8eefe98383ea 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
@@ -2433,14 +2433,14 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
checkOperation(OperationCategory.WRITE);
FSPermissionChecker.setOperationType(operationName);
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot create symlink " + link);
auditStat = FSDirSymlinkOp.createSymlinkInt(this, target, link,
dirPerms, createParent, logRetryCache);
} finally {
- writeUnlock(operationName,
+ writeUnlock(FSNamesystemLockMode.FS, operationName,
getLockReportInfoSupplier(link, target, auditStat));
}
} catch (AccessControlException e) {
@@ -2787,7 +2787,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
checkOperation(OperationCategory.WRITE);
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(null);
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot create file" + src);
@@ -2849,7 +2849,8 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
dir.writeUnlock();
}
} finally {
- writeUnlock("create", getLockReportInfoSupplier(src, null, stat));
+ writeUnlock(FSNamesystemLockMode.FS, "create",
+ getLockReportInfoSupplier(src, null, stat));
// There might be transactions logged while trying to recover the lease.
// They need to be sync'ed even when an exception was thrown.
if (!skipSync) {
@@ -2882,7 +2883,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
checkOperation(OperationCategory.WRITE);
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(null);
- writeLock();
+ writeLock(FSNamesystemLockMode.GLOBAL);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot recover the lease of " + src);
@@ -2902,7 +2903,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
skipSync = true;
throw se;
} finally {
- writeUnlock("recoverLease");
+ writeUnlock(FSNamesystemLockMode.GLOBAL, "recoverLease");
// There might be transactions logged while trying to recover the lease.
// They need to be sync'ed even when an exception was thrown.
if (!skipSync) {
@@ -3022,7 +3023,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
checkOperation(OperationCategory.WRITE);
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
- writeLock();
+ writeLock(FSNamesystemLockMode.GLOBAL);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot append to file" + srcArg);
@@ -3032,7 +3033,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
skipSync = true;
throw se;
} finally {
- writeUnlock(operationName, getLockReportInfoSupplier(srcArg));
+ writeUnlock(FSNamesystemLockMode.GLOBAL, operationName, getLockReportInfoSupplier(srcArg));
// There might be transactions logged while trying to recover the lease
// They need to be sync'ed even when an exception was thrown.
if (!skipSync) {
@@ -3079,13 +3080,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
checkOperation(OperationCategory.WRITE);
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
- readLock();
+ readLock(FSNamesystemLockMode.GLOBAL);
try {
checkOperation(OperationCategory.WRITE);
r = FSDirWriteFileOp.validateAddBlock(this, pc, src, fileId, clientName,
previous, onRetryBlock);
} finally {
- readUnlock(operationName);
+ readUnlock(FSNamesystemLockMode.GLOBAL, operationName);
}
if (r == null) {
@@ -3098,14 +3099,14 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
blockManager, src, excludedNodes, favoredNodes, flags, r);
checkOperation(OperationCategory.WRITE);
- writeLock();
+ writeLock(FSNamesystemLockMode.GLOBAL);
LocatedBlock lb;
try {
checkOperation(OperationCategory.WRITE);
lb = FSDirWriteFileOp.storeAllocatedBlock(
this, src, fileId, clientName, previous, targets);
} finally {
- writeUnlock(operationName);
+ writeUnlock(FSNamesystemLockMode.GLOBAL, operationName);
}
getEditLog().logSync();
return lb;
@@ -3130,7 +3131,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
checkOperation(OperationCategory.WRITE);
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(null);
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
// Changing this operation category to WRITE instead of making getAdditionalDatanode as a
// read method is aim to let Active NameNode to handle this RPC, because Active NameNode
@@ -3155,7 +3156,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
"src=%s, fileId=%d, blk=%s, clientName=%s, clientMachine=%s",
src, fileId, blk, clientName, clientMachine));
} finally {
- readUnlock("getAdditionalDatanode");
+ readUnlock(FSNamesystemLockMode.FS, "getAdditionalDatanode");
}
if (clientnode == null) {
@@ -3181,7 +3182,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
checkOperation(OperationCategory.WRITE);
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(null);
- writeLock();
+ writeLock(FSNamesystemLockMode.GLOBAL);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot abandon block " + b + " for file" + src);
@@ -3189,7 +3190,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
NameNode.stateChangeLog.debug(
"BLOCK* NameSystem.abandonBlock: {} is removed from pendingCreates", b);
} finally {
- writeUnlock("abandonBlock");
+ writeUnlock(FSNamesystemLockMode.GLOBAL, "abandonBlock");
}
getEditLog().logSync();
}
@@ -3204,7 +3205,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
throws LeaseExpiredException, FileNotFoundException {
String src = iip.getPath();
INode inode = iip.getLastINode();
- assert hasReadLock();
+ assert hasReadLock(FSNamesystemLockMode.FS);
if (inode == null) {
throw new FileNotFoundException("File does not exist: "
+ leaseExceptionString(src, fileId, holder));
@@ -3247,14 +3248,14 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
checkOperation(OperationCategory.WRITE);
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(null);
- writeLock();
+ writeLock(FSNamesystemLockMode.GLOBAL);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot complete file " + src);
success = FSDirWriteFileOp.completeFile(this, pc, src, holder, last,
fileId);
} finally {
- writeUnlock("completeFile");
+ writeUnlock(FSNamesystemLockMode.GLOBAL, "completeFile");
}
getEditLog().logSync();
if (success) {
@@ -3269,6 +3270,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
* @param blockType is the file under striping or contiguous layout?
*/
Block createNewBlock(BlockType blockType) throws IOException {
+ // nextBlockId and nextGenerationStamp need to write edit log, so it needs FSLock.
assert hasWriteLock(FSNamesystemLockMode.GLOBAL);
Block b = new Block(nextBlockId(blockType), 0, 0);
// Increment the generation stamp for every new block.
@@ -3282,7 +3284,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
* all blocks, otherwise check only penultimate block.
*/
boolean checkFileProgress(String src, INodeFile v, boolean checkall) {
- assert hasReadLock();
+ assert hasReadLock(FSNamesystemLockMode.GLOBAL);
if (checkall) {
return checkBlocksComplete(src, true, v.getBlocks());
} else {
@@ -3328,14 +3330,14 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot rename " + src);
ret = FSDirRenameOp.renameToInt(dir, pc, src, dst, logRetryCache);
} finally {
FileStatus status = ret != null ? ret.auditStat : null;
- writeUnlock(operationName,
+ writeUnlock(FSNamesystemLockMode.FS, operationName,
getLockReportInfoSupplier(src, dst, status));
}
} catch (AccessControlException e) {
@@ -3360,7 +3362,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.GLOBAL);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot rename " + src);
@@ -3368,7 +3370,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
options);
} finally {
FileStatus status = res != null ? res.auditStat : null;
- writeUnlock(operationName,
+ writeUnlock(FSNamesystemLockMode.GLOBAL, operationName,
getLockReportInfoSupplier(src, dst, status));
}
} catch (AccessControlException e) {
@@ -3403,7 +3405,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
FSPermissionChecker.setOperationType(operationName);
boolean ret = false;
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.GLOBAL);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot delete " + src);
@@ -3411,7 +3413,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
this, pc, src, recursive, logRetryCache);
ret = toRemovedBlocks != null;
} finally {
- writeUnlock(operationName, getLockReportInfoSupplier(src));
+ writeUnlock(FSNamesystemLockMode.GLOBAL, operationName, getLockReportInfoSupplier(src));
}
} catch (AccessControlException e) {
logAuditEvent(false, operationName, src);
@@ -3441,7 +3443,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
void removeLeasesAndINodes(List<Long> removedUCFiles,
List<INode> removedINodes,
final boolean acquireINodeMapLock) {
- assert hasWriteLock();
+ assert hasWriteLock(FSNamesystemLockMode.FS);
for(long i : removedUCFiles) {
leaseManager.removeLease(i);
}
@@ -3546,14 +3548,14 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(operationName);
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot create directory " + src);
auditStat = FSDirMkdirOp.mkdirs(this, pc, src, permissions,
createParent);
} finally {
- writeUnlock(operationName,
+ writeUnlock(FSNamesystemLockMode.FS, operationName,
getLockReportInfoSupplier(src, null, auditStat));
}
} catch (AccessControlException e) {
@@ -3693,7 +3695,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
checkOperation(OperationCategory.WRITE);
final FSPermissionChecker pc = getPermissionChecker();
FSPermissionChecker.setOperationType(null);
- writeLock();
+ writeLock(FSNamesystemLockMode.GLOBAL);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot fsync file " + src);
@@ -3706,7 +3708,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
}
FSDirWriteFileOp.persistBlocks(dir, src, pendingFile, false);
} finally {
- writeUnlock("fsync");
+ writeUnlock(FSNamesystemLockMode.GLOBAL, "fsync");
}
getEditLog().logSync();
}
@@ -3729,7 +3731,8 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
String recoveryLeaseHolder) throws IOException {
LOG.info("Recovering " + lease + ", src=" + src);
assert !isInSafeMode();
- assert hasWriteLock();
+ // finalizeINodeFileUnderConstruction needs global write lock.
+ assert hasWriteLock(FSNamesystemLockMode.GLOBAL);
final INodeFile pendingFile = iip.getLastINode().asFile();
int nrBlocks = pendingFile.numBlocks();
@@ -3891,7 +3894,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
private Lease reassignLease(Lease lease, String src, String newHolder,
INodeFile pendingFile) {
- assert hasWriteLock();
+ assert hasWriteLock(FSNamesystemLockMode.FS);
if(newHolder == null)
return lease;
// The following transaction is not synced. Make sure it's sync'ed later.
@@ -3900,7 +3903,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
}
Lease reassignLeaseInternal(Lease lease, String newHolder, INodeFile pendingFile) {
- assert hasWriteLock();
+ assert hasWriteLock(FSNamesystemLockMode.FS);
pendingFile.getFileUnderConstructionFeature().setClientName(newHolder);
return leaseManager.reassignLease(lease, pendingFile, newHolder);
}
@@ -5861,6 +5864,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
*/
long nextGenerationStamp(boolean legacyBlock)
throws IOException {
+ // TODO: Use FSLock to make nextGenerationStamp thread safe.
assert hasWriteLock(FSNamesystemLockMode.GLOBAL);
checkNameNodeSafeMode("Cannot get next generation stamp");
@@ -5880,7 +5884,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
* @param blockType is the file under striping or contiguous layout?
*/
private long nextBlockId(BlockType blockType) throws IOException {
- assert hasWriteLock();
+ assert hasWriteLock(FSNamesystemLockMode.GLOBAL);
checkNameNodeSafeMode("Cannot get next block ID");
final long blockId = blockManager.nextBlockId(blockType);
getEditLog().logAllocateBlockId(blockId);
@@ -5929,7 +5933,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
private INodeFile checkUCBlock(ExtendedBlock block,
String clientName) throws IOException {
- assert hasWriteLock();
+ assert hasWriteLock(FSNamesystemLockMode.GLOBAL);
checkNameNodeSafeMode("Cannot get a new generation stamp and an "
+ "access token for block " + block);
@@ -6003,7 +6007,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
String clientName) throws IOException {
final LocatedBlock locatedBlock;
checkOperation(OperationCategory.WRITE);
- writeLock();
+ writeLock(FSNamesystemLockMode.GLOBAL);
try {
checkOperation(OperationCategory.WRITE);
@@ -6037,7 +6041,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
blockManager.setBlockToken(locatedBlock,
BlockTokenIdentifier.AccessMode.WRITE);
} finally {
- writeUnlock("bumpBlockGenerationStamp");
+ writeUnlock(FSNamesystemLockMode.GLOBAL, "bumpBlockGenerationStamp");
}
// Ensure we record the new generation stamp
getEditLog().logSync();
@@ -6066,7 +6070,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
+ ", newNodes=" + Arrays.asList(newNodes)
+ ", client=" + clientName
+ ")");
- writeLock();
+ writeLock(FSNamesystemLockMode.GLOBAL);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Pipeline not updated");
@@ -6075,7 +6079,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
updatePipelineInternal(clientName, oldBlock, newBlock, newNodes,
newStorageIDs, logRetryCache);
} finally {
- writeUnlock("updatePipeline");
+ writeUnlock(FSNamesystemLockMode.GLOBAL, "updatePipeline");
}
getEditLog().logSync();
LOG.info("updatePipeline(" + oldBlock.getLocalBlock() + " => "
@@ -6086,7 +6090,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
ExtendedBlock newBlock, DatanodeID[] newNodes, String[] newStorageIDs,
boolean logRetryCache)
throws IOException {
- assert hasWriteLock();
+ assert hasWriteLock(FSNamesystemLockMode.GLOBAL);
// check the vadility of the block and lease holder name
final INodeFile pendingFile = checkUCBlock(oldBlock, clientName);
final String src = pendingFile.getFullPathName();
@@ -6382,7 +6386,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
long expiryTime;
checkOperation(OperationCategory.WRITE);
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
@@ -6399,7 +6403,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
getEditLog().logRenewDelegationToken(id, expiryTime);
tokenId = id.toStringStable();
} finally {
- writeUnlock(operationName, getLockReportInfoSupplier(tokenId));
+ writeUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(tokenId));
}
} catch (AccessControlException ace) {
final DelegationTokenIdentifier id = DFSUtil.decodeDelegationToken(token);
@@ -6423,7 +6427,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
String tokenId = null;
checkOperation(OperationCategory.WRITE);
try {
- writeLock();
+ writeLock(FSNamesystemLockMode.FS);
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot cancel delegation token");
@@ -6433,7 +6437,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
getEditLog().logCancelDelegationToken(id);
tokenId = id.toStringStable();
} finally {
- writeUnlock(operationName, getLockReportInfoSupplier(tokenId));
+ writeUnlock(FSNamesystemLockMode.FS, operationName, getLockReportInfoSupplier(tokenId));
}
} catch (AccessControlException ace) {
final DelegationTokenIdentifier id = DFSUtil.decodeDelegationToken(token);
@@ -6508,7 +6512,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
private void logReassignLease(String leaseHolder, String src,
String newHolder) {
- assert hasWriteLock();
+ assert hasWriteLock(FSNamesystemLockMode.FS);
getEditLog().logReassignLease(leaseHolder, src, newHolder);
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java
index 1bd315f1771e..5389796b0b1e 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java
@@ -972,6 +972,12 @@ public class INodeFile extends INodeWithAdditionalFields
/**
* Compute file size of the current file.
+ *
+ * ComputeFileSize only needs the FSLock even through it involves block.
+ * BlockSize only be changed by hsync, addBlock, commitBlockSynchronization,
+ * complete, updatePipeline and forceCompleteBlock, all these operations
+ * already hold the FSWriteLock.
+ * CompleteBlock also hold the FSWriteLock since it needs to update Quota
*
* @param includesLastUcBlock
* If the last block is under construction, should it be included?
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org
(hadoop) 09/23: HDFS-17416. [FGL] Monitor threads in BlockManager.class support fine-grained lock (#6647)
Posted by za...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zanderxu pushed a commit to branch HDFS-17384
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit 1d2b15d9079cccfcaa3ece6f6cf3db0dd8d11fc6
Author: ZanderXu <za...@apache.org>
AuthorDate: Tue Mar 26 10:50:20 2024 +0800
HDFS-17416. [FGL] Monitor threads in BlockManager.class support fine-grained lock (#6647)
---
.../hdfs/server/blockmanagement/BlockManager.java | 76 +++++++++++++---------
.../server/blockmanagement/ProvidedStorageMap.java | 2 +-
.../hadoop/hdfs/server/namenode/FSNamesystem.java | 9 ++-
.../server/blockmanagement/TestBlockManager.java | 2 +-
.../blockmanagement/TestProvidedStorageMap.java | 3 +-
.../blockmanagement/TestReplicationPolicy.java | 7 ++
6 files changed, 64 insertions(+), 35 deletions(-)
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
index da16204050af..433b1266bf7b 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
@@ -2102,7 +2102,9 @@ public class BlockManager implements BlockStatsMXBean {
*/
int computeBlockReconstructionWork(int blocksToProcess) {
List<List<BlockInfo>> blocksToReconstruct = null;
- namesystem.writeLock();
+ // TODO: Change it to readLock(FSNamesystemLockMode.BM)
+ // since chooseLowRedundancyBlocks is thread safe.
+ namesystem.writeLock(FSNamesystemLockMode.BM);
try {
boolean reset = false;
if (replQueueResetToHeadThreshold > 0) {
@@ -2117,7 +2119,7 @@ public class BlockManager implements BlockStatsMXBean {
blocksToReconstruct = neededReconstruction
.chooseLowRedundancyBlocks(blocksToProcess, reset);
} finally {
- namesystem.writeUnlock("computeBlockReconstructionWork");
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "computeBlockReconstructionWork");
}
return computeReconstructionWorkForBlocks(blocksToReconstruct);
}
@@ -2136,7 +2138,9 @@ public class BlockManager implements BlockStatsMXBean {
List<BlockReconstructionWork> reconWork = new ArrayList<>();
// Step 1: categorize at-risk blocks into replication and EC tasks
- namesystem.writeLock();
+ // TODO: Change to readLock(FSNamesystemLockMode.GLOBAL)
+ // since neededReconstruction is thread safe.
+ namesystem.writeLock(FSNamesystemLockMode.GLOBAL);
try {
synchronized (neededReconstruction) {
for (int priority = 0; priority < blocksToReconstruct
@@ -2151,7 +2155,7 @@ public class BlockManager implements BlockStatsMXBean {
}
}
} finally {
- namesystem.writeUnlock("computeReconstructionWorkForBlocks");
+ namesystem.writeUnlock(FSNamesystemLockMode.GLOBAL, "computeReconstructionWorkForBlocks");
}
// Step 2: choose target nodes for each reconstruction task
@@ -2176,7 +2180,9 @@ public class BlockManager implements BlockStatsMXBean {
}
// Step 3: add tasks to the DN
- namesystem.writeLock();
+ // TODO: Change to readLock(FSNamesystemLockMode.BM)
+ // since pendingReconstruction and neededReconstruction are thread safe.
+ namesystem.writeLock(FSNamesystemLockMode.BM);
try {
for (BlockReconstructionWork rw : reconWork) {
final DatanodeStorageInfo[] targets = rw.getTargets();
@@ -2192,7 +2198,7 @@ public class BlockManager implements BlockStatsMXBean {
}
}
} finally {
- namesystem.writeUnlock("computeReconstructionWorkForBlocks");
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "computeReconstructionWorkForBlocks");
}
if (blockLog.isDebugEnabled()) {
@@ -2681,7 +2687,9 @@ public class BlockManager implements BlockStatsMXBean {
void processPendingReconstructions() {
BlockInfo[] timedOutItems = pendingReconstruction.getTimedOutBlocks();
if (timedOutItems != null) {
- namesystem.writeLock();
+ // TODO: Change to readLock(FSNamesystemLockMode.BM)
+ // since neededReconstruction is thread safe.
+ namesystem.writeLock(FSNamesystemLockMode.BM);
try {
for (int i = 0; i < timedOutItems.length; i++) {
/*
@@ -2700,7 +2708,7 @@ public class BlockManager implements BlockStatsMXBean {
}
}
} finally {
- namesystem.writeUnlock("processPendingReconstructions");
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "processPendingReconstructions");
}
/* If we know the target datanodes where the replication timedout,
* we could invoke decBlocksScheduled() on it. Its ok for now.
@@ -2895,7 +2903,7 @@ public class BlockManager implements BlockStatsMXBean {
final DatanodeStorage storage,
final BlockListAsLongs newReport,
BlockReportContext context) throws IOException {
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.GLOBAL);
final long startTime = Time.monotonicNow(); //after acquiring write lock
final long endTime;
DatanodeDescriptor node;
@@ -2953,7 +2961,7 @@ public class BlockManager implements BlockStatsMXBean {
storageInfo.receivedBlockReport();
} finally {
endTime = Time.monotonicNow();
- namesystem.writeUnlock("processReport");
+ namesystem.writeUnlock(FSNamesystemLockMode.GLOBAL, "processReport");
}
if (blockLog.isDebugEnabled()) {
@@ -3026,7 +3034,7 @@ public class BlockManager implements BlockStatsMXBean {
if (getPostponedMisreplicatedBlocksCount() == 0) {
return;
}
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.GLOBAL);
long startTime = Time.monotonicNow();
long startSize = postponedMisreplicatedBlocks.size();
try {
@@ -3055,7 +3063,8 @@ public class BlockManager implements BlockStatsMXBean {
postponedMisreplicatedBlocks.addAll(rescannedMisreplicatedBlocks);
rescannedMisreplicatedBlocks.clear();
long endSize = postponedMisreplicatedBlocks.size();
- namesystem.writeUnlock("rescanPostponedMisreplicatedBlocks");
+ namesystem.writeUnlock(FSNamesystemLockMode.GLOBAL,
+ "rescanPostponedMisreplicatedBlocks");
LOG.info("Rescan of postponedMisreplicatedBlocks completed in {}" +
" msecs. {} blocks are left. {} blocks were removed.",
(Time.monotonicNow() - startTime), endSize, (startSize - endSize));
@@ -3097,7 +3106,8 @@ public class BlockManager implements BlockStatsMXBean {
if (excessRedundancyMap.size() == 0) {
return;
}
- namesystem.writeLock();
+ // TODO: Change to readLock(FSNamesysteLockMode.BM) since invalidateBlocks is thread safe.
+ namesystem.writeLock(FSNamesystemLockMode.BM);
long now = Time.monotonicNow();
int processed = 0;
try {
@@ -3151,7 +3161,7 @@ public class BlockManager implements BlockStatsMXBean {
}
}
} finally {
- namesystem.writeUnlock("processTimedOutExcessBlocks");
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "processTimedOutExcessBlocks");
LOG.info("processTimedOutExcessBlocks {} msecs.", (Time.monotonicNow() - now));
}
}
@@ -3257,7 +3267,7 @@ public class BlockManager implements BlockStatsMXBean {
final DatanodeStorageInfo storageInfo,
final BlockListAsLongs report) throws IOException {
if (report == null) return;
- assert (namesystem.hasWriteLock());
+ assert (namesystem.hasWriteLock(FSNamesystemLockMode.GLOBAL));
assert (storageInfo.getBlockReportCount() == 0);
for (BlockReportReplica iblk : report) {
@@ -3309,6 +3319,7 @@ public class BlockManager implements BlockStatsMXBean {
// OpenFileBlocks only inside snapshots also will be added to safemode
// threshold. So we need to update such blocks to safemode
// refer HDFS-5283
+ // isInSnapshot involves the full path, so it needs FSReadLock.
if (namesystem.isInSnapshot(storedBlock.getBlockCollectionId())) {
int numOfReplicas = storedBlock.getUnderConstructionFeature()
.getNumExpectedLocations();
@@ -3724,7 +3735,7 @@ public class BlockManager implements BlockStatsMXBean {
private void addStoredBlockImmediate(BlockInfo storedBlock, Block reported,
DatanodeStorageInfo storageInfo)
throws IOException {
- assert (storedBlock != null && namesystem.hasWriteLock());
+ assert (storedBlock != null && namesystem.hasWriteLock(FSNamesystemLockMode.GLOBAL));
if (!namesystem.isInStartupSafeMode()
|| isPopulatingReplQueues()) {
addStoredBlock(storedBlock, reported, storageInfo, null, false);
@@ -3759,7 +3770,7 @@ public class BlockManager implements BlockStatsMXBean {
DatanodeDescriptor delNodeHint,
boolean logEveryBlock)
throws IOException {
- assert block != null && namesystem.hasWriteLock();
+ assert block != null && namesystem.hasWriteLock(FSNamesystemLockMode.GLOBAL);
BlockInfo storedBlock;
DatanodeDescriptor node = storageInfo.getDatanodeDescriptor();
if (!block.isComplete()) {
@@ -3995,7 +4006,7 @@ public class BlockManager implements BlockStatsMXBean {
while (namesystem.isRunning() && !Thread.currentThread().isInterrupted()) {
int processed = 0;
- namesystem.writeLockInterruptibly();
+ namesystem.writeLockInterruptibly(FSNamesystemLockMode.GLOBAL);
try {
while (processed < numBlocksPerIteration && blocksItr.hasNext()) {
BlockInfo block = blocksItr.next();
@@ -4054,7 +4065,7 @@ public class BlockManager implements BlockStatsMXBean {
break;
}
} finally {
- namesystem.writeUnlock("processMisReplicatesAsync");
+ namesystem.writeUnlock(FSNamesystemLockMode.GLOBAL, "processMisReplicatesAsync");
LOG.info("Reconstruction queues initialisation progress: {}, total number of blocks " +
"processed: {}/{}", reconstructionQueuesInitProgress, totalProcessed, totalBlocks);
// Make sure it is out of the write lock for sufficiently long time.
@@ -4207,7 +4218,7 @@ public class BlockManager implements BlockStatsMXBean {
private boolean processExtraRedundancyBlockWithoutPostpone(final BlockInfo block,
final short replication, final DatanodeDescriptor addedNode,
DatanodeDescriptor delNodeHint) {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.GLOBAL);
if (addedNode == delNodeHint) {
delNodeHint = null;
}
@@ -4251,7 +4262,10 @@ public class BlockManager implements BlockStatsMXBean {
BlockInfo storedBlock, short replication,
DatanodeDescriptor addedNode,
DatanodeDescriptor delNodeHint) {
- assert namesystem.hasWriteLock();
+ // bc.getStoragePolicyID() needs FSReadLock.
+ // TODO: Change to hasReadLock(FSNamesystemLockMode.GLOBAL)
+ // since chooseExcessRedundancyContiguous is thread safe.
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.GLOBAL);
// first form a rack to datanodes map and
BlockCollection bc = getBlockCollection(storedBlock);
if (storedBlock.isStriped()) {
@@ -4620,7 +4634,7 @@ public class BlockManager implements BlockStatsMXBean {
*/
public void processIncrementalBlockReport(final DatanodeID nodeID,
final StorageReceivedDeletedBlocks srdb) throws IOException {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.GLOBAL);
final DatanodeDescriptor node = datanodeManager.getDatanode(nodeID);
if (node == null || !node.isRegistered()) {
blockLog.warn("BLOCK* processIncrementalBlockReport"
@@ -4984,6 +4998,8 @@ public class BlockManager implements BlockStatsMXBean {
/** updates a block in needed reconstruction queue. */
private void updateNeededReconstructions(final BlockInfo block,
final int curReplicasDelta, int expectedReplicasDelta) {
+ // TODO: Change to readLock(FSNamesystemLockMode.BM)
+ // since pendingReconstruction and neededReconstruction are thread safe.
namesystem.writeLock(FSNamesystemLockMode.BM);
try {
if (!isPopulatingReplQueues() || !block.isComplete()) {
@@ -5035,8 +5051,9 @@ public class BlockManager implements BlockStatsMXBean {
*/
private int invalidateWorkForOneNode(DatanodeInfo dn) {
final List<Block> toInvalidate;
-
- namesystem.writeLock();
+
+ // TODO: Change to readLock(FSNamesystemLockMode.BM) since invalidateBlocks is thread safe.
+ namesystem.writeLock(FSNamesystemLockMode.BM);
try {
// blocks should not be replicated or removed if safe mode is on
if (namesystem.isInSafeMode()) {
@@ -5060,7 +5077,7 @@ public class BlockManager implements BlockStatsMXBean {
return 0;
}
} finally {
- namesystem.writeUnlock("invalidateWorkForOneNode");
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "invalidateWorkForOneNode");
}
if (blockLog.isDebugEnabled()) {
blockLog.debug("BLOCK* {}: ask {} to delete {}",
@@ -5283,7 +5300,7 @@ public class BlockManager implements BlockStatsMXBean {
private void remove(long time) {
if (checkToDeleteIterator()) {
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.BM);
try {
while (toDeleteIterator.hasNext()) {
removeBlock(toDeleteIterator.next());
@@ -5294,7 +5311,7 @@ public class BlockManager implements BlockStatsMXBean {
}
}
} finally {
- namesystem.writeUnlock("markedDeleteBlockScrubberThread");
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "markedDeleteBlockScrubberThread");
}
}
}
@@ -5408,12 +5425,13 @@ public class BlockManager implements BlockStatsMXBean {
int workFound = this.computeBlockReconstructionWork(blocksToProcess);
// Update counters
- namesystem.writeLock();
+ // TODO: Make corruptReplicas thread safe to remove this lock.
+ namesystem.writeLock(FSNamesystemLockMode.BM);
try {
this.updateState();
this.scheduledReplicationBlocksCount = workFound;
} finally {
- namesystem.writeUnlock("computeDatanodeWork");
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "computeDatanodeWork");
}
workFound += this.computeInvalidateWork(nodesToProcess);
return workFound;
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/ProvidedStorageMap.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/ProvidedStorageMap.java
index 4e4464b32599..558c43d06777 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/ProvidedStorageMap.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/ProvidedStorageMap.java
@@ -145,7 +145,7 @@ public class ProvidedStorageMap {
private void processProvidedStorageReport()
throws IOException {
- assert lock.hasWriteLock() : "Not holding write lock";
+ assert lock.hasWriteLock(FSNamesystemLockMode.GLOBAL) : "Not holding write lock";
if (providedStorageInfo.getBlockReportCount() == 0
|| providedDescriptor.activeProvidedDatanodes() == 0) {
LOG.info("Calling process first blk report from storage: "
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
index a32252525178..62db0411e16b 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
@@ -3959,7 +3959,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
@Override
public boolean isInSnapshot(long blockCollectionID) {
- assert hasReadLock();
+ assert hasReadLock(FSNamesystemLockMode.FS);
final INodeFile bc = getBlockCollection(blockCollectionID);
if (bc == null || !bc.isUnderConstruction()) {
return false;
@@ -5350,11 +5350,14 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
public void processIncrementalBlockReport(final DatanodeID nodeID,
final StorageReceivedDeletedBlocks srdb)
throws IOException {
- writeLock();
+ // completeBlock will updateQuota, so it needs BMWriteLock and FSWriteLock.
+ // processExtraRedundancyBlock chooses excess replicas depending on storage policyId,
+ // so it needs FSReadLock.
+ writeLock(FSNamesystemLockMode.GLOBAL);
try {
blockManager.processIncrementalBlockReport(nodeID, srdb);
} finally {
- writeUnlock("processIncrementalBlockReport");
+ writeUnlock(FSNamesystemLockMode.GLOBAL, "processIncrementalBlockReport");
}
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManager.java
index 2ebf4a6cacc7..0b1c18ed1d00 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManager.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManager.java
@@ -2334,4 +2334,4 @@ public class TestBlockManager {
DataNodeFaultInjector.set(oldInjector);
}
}
-}
\ No newline at end of file
+}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestProvidedStorageMap.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestProvidedStorageMap.java
index c7f837978624..aa692185cb38 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestProvidedStorageMap.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestProvidedStorageMap.java
@@ -24,6 +24,7 @@ import org.apache.hadoop.hdfs.DFSTestUtil;
import org.apache.hadoop.hdfs.HdfsConfiguration;
import org.apache.hadoop.hdfs.server.common.blockaliasmap.BlockAliasMap;
import org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.TestProvidedImpl;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.protocol.DatanodeStorage;
import org.apache.hadoop.hdfs.util.RwLock;
import org.junit.Before;
@@ -87,7 +88,7 @@ public class TestProvidedStorageMap {
DatanodeStorage dn1DiskStorage = new DatanodeStorage(
"sid-1", DatanodeStorage.State.NORMAL, StorageType.DISK);
- when(nameSystemLock.hasWriteLock()).thenReturn(true);
+ when(nameSystemLock.hasWriteLock(FSNamesystemLockMode.GLOBAL)).thenReturn(true);
DatanodeStorageInfo dns1Provided =
providedMap.getStorage(dn1, dn1ProvidedStorage);
DatanodeStorageInfo dns1Disk = providedMap.getStorage(dn1, dn1DiskStorage);
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicy.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicy.java
index b99e060ee387..fd7ea14446ab 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicy.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicy.java
@@ -66,6 +66,7 @@ import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
import org.apache.hadoop.hdfs.server.namenode.INodeFile;
import org.apache.hadoop.hdfs.server.namenode.Namesystem;
import org.apache.hadoop.hdfs.server.namenode.TestINodeFile;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.protocol.DatanodeStorage;
import org.apache.hadoop.net.Node;
import org.apache.hadoop.util.ReflectionUtils;
@@ -1406,6 +1407,12 @@ public class TestReplicationPolicy extends BaseReplicationPolicyTest {
FSNamesystem mockNS = mock(FSNamesystem.class);
when(mockNS.hasWriteLock()).thenReturn(true);
when(mockNS.hasReadLock()).thenReturn(true);
+ when(mockNS.hasWriteLock(FSNamesystemLockMode.GLOBAL)).thenReturn(true);
+ when(mockNS.hasReadLock(FSNamesystemLockMode.GLOBAL)).thenReturn(true);
+ when(mockNS.hasWriteLock(FSNamesystemLockMode.BM)).thenReturn(true);
+ when(mockNS.hasReadLock(FSNamesystemLockMode.BM)).thenReturn(true);
+ when(mockNS.hasWriteLock(FSNamesystemLockMode.FS)).thenReturn(true);
+ when(mockNS.hasReadLock(FSNamesystemLockMode.FS)).thenReturn(true);
BlockManager bm = new BlockManager(mockNS, false, new HdfsConfiguration());
LowRedundancyBlocks lowRedundancyBlocks = bm.neededReconstruction;
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org
(hadoop) 10/23: HDFS-17423. [FGL] BlockManagerSafeMode supports fine-grained lock (#6645)
Posted by za...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zanderxu pushed a commit to branch HDFS-17384
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit 24139acc8652d5c2f8053aa18bd0e77a6c54c336
Author: ZanderXu <za...@apache.org>
AuthorDate: Tue Mar 26 10:52:45 2024 +0800
HDFS-17423. [FGL] BlockManagerSafeMode supports fine-grained lock (#6645)
---
.../hdfs/server/blockmanagement/BlockManager.java | 2 +-
.../blockmanagement/BlockManagerSafeMode.java | 33 ++++++++++++----------
.../hadoop/hdfs/server/namenode/FSNamesystem.java | 32 +++++++++++++++------
.../blockmanagement/TestBlockManagerSafeMode.java | 3 ++
.../blockmanagement/TestReplicationPolicy.java | 1 +
5 files changed, 46 insertions(+), 25 deletions(-)
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
index 433b1266bf7b..82b82433e70e 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
@@ -3947,7 +3947,7 @@ public class BlockManager implements BlockStatsMXBean {
* extra or low redundancy. Place it into the respective queue.
*/
public void processMisReplicatedBlocks() {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
stopReconstructionInitializer();
neededReconstruction.clear();
reconstructionQueuesInitializer = new Daemon() {
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManagerSafeMode.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManagerSafeMode.java
index 4349ba01401d..49cd409211e7 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManagerSafeMode.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManagerSafeMode.java
@@ -26,6 +26,7 @@ import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.RollingUpgradeSt
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption;
import org.apache.hadoop.hdfs.server.namenode.NameNode;
import org.apache.hadoop.hdfs.server.namenode.Namesystem;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.namenode.startupprogress.Phase;
import org.apache.hadoop.hdfs.server.namenode.startupprogress.StartupProgress;
import org.apache.hadoop.hdfs.server.namenode.startupprogress.StartupProgress.Counter;
@@ -169,7 +170,7 @@ class BlockManagerSafeMode {
* @param total initial total blocks
*/
void activate(long total) {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
assert status == BMSafeModeStatus.OFF;
startTime = monotonicNow();
@@ -203,7 +204,7 @@ class BlockManagerSafeMode {
* If safe mode is not currently on, this is a no-op.
*/
void checkSafeMode() {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
if (namesystem.inTransitionToActive()) {
return;
}
@@ -219,6 +220,7 @@ class BlockManagerSafeMode {
initializeReplQueuesIfNecessary();
reportStatus("STATE* Safe mode extension entered.", true);
} else {
+ // TODO: let the smmthread to leave the safemode.
// PENDING_THRESHOLD -> OFF
leaveSafeMode(false);
}
@@ -244,7 +246,7 @@ class BlockManagerSafeMode {
* @param deltaTotal the change in number of total blocks expected
*/
void adjustBlockTotals(int deltaSafe, int deltaTotal) {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
if (!isSafeModeTrackingBlocks()) {
return;
}
@@ -278,7 +280,7 @@ class BlockManagerSafeMode {
* set after the image has been loaded.
*/
boolean isSafeModeTrackingBlocks() {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
return haEnabled && status != BMSafeModeStatus.OFF;
}
@@ -286,7 +288,7 @@ class BlockManagerSafeMode {
* Set total number of blocks.
*/
void setBlockTotal(long total) {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
synchronized (this) {
this.blockTotal = total;
this.blockThreshold = (long) (total * threshold);
@@ -372,7 +374,7 @@ class BlockManagerSafeMode {
* @return true if it leaves safe mode successfully else false
*/
boolean leaveSafeMode(boolean force) {
- assert namesystem.hasWriteLock() : "Leaving safe mode needs write lock!";
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM) : "Leaving safe mode needs write lock!";
final long bytesInFuture = getBytesInFuture();
if (bytesInFuture > 0) {
@@ -443,7 +445,7 @@ class BlockManagerSafeMode {
*/
synchronized void incrementSafeBlockCount(int storageNum,
BlockInfo storedBlock) {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
if (status == BMSafeModeStatus.OFF) {
return;
}
@@ -475,7 +477,7 @@ class BlockManagerSafeMode {
* If safe mode is not currently on, this is a no-op.
*/
synchronized void decrementSafeBlockCount(BlockInfo b) {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
if (status == BMSafeModeStatus.OFF) {
return;
}
@@ -498,7 +500,7 @@ class BlockManagerSafeMode {
* @param brr block report replica which belongs to no file in BlockManager
*/
void checkBlocksWithFutureGS(BlockReportReplica brr) {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
if (status == BMSafeModeStatus.OFF) {
return;
}
@@ -532,7 +534,8 @@ class BlockManagerSafeMode {
}
void close() {
- assert namesystem.hasWriteLock() : "Closing bmSafeMode needs write lock!";
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.GLOBAL)
+ : "Closing bmSafeMode needs write lock!";
try {
smmthread.interrupt();
smmthread.join(3000);
@@ -566,7 +569,7 @@ class BlockManagerSafeMode {
/** Check if we are ready to initialize replication queues. */
private void initializeReplQueuesIfNecessary() {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
// Whether it has reached the threshold for initializing replication queues.
boolean canInitializeReplQueues = blockManager.shouldPopulateReplQueues() &&
blockSafe >= blockReplQueueThreshold;
@@ -581,7 +584,7 @@ class BlockManagerSafeMode {
* @return true if both block and datanode threshold are met else false.
*/
private boolean areThresholdsMet() {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
// Calculating the number of live datanodes is time-consuming
// in large clusters. Skip it when datanodeThreshold is zero.
// We need to evaluate getNumLiveDataNodes only when
@@ -626,7 +629,7 @@ class BlockManagerSafeMode {
* Print status every 20 seconds.
*/
private void reportStatus(String msg, boolean rightNow) {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
long curTime = monotonicNow();
if(!rightNow && (curTime - lastStatusReport < 20 * 1000)) {
return;
@@ -660,7 +663,7 @@ class BlockManagerSafeMode {
public void run() {
while (namesystem.isRunning()) {
try {
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.GLOBAL);
if (status == BMSafeModeStatus.OFF) { // Not in safe mode.
break;
}
@@ -670,7 +673,7 @@ class BlockManagerSafeMode {
break;
}
} finally {
- namesystem.writeUnlock("leaveSafeMode");
+ namesystem.writeUnlock(FSNamesystemLockMode.GLOBAL, "leaveSafeMode");
}
try {
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
index 62db0411e16b..f23db6e0f3a8 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
@@ -1334,7 +1334,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
@Override
public void startSecretManagerIfNecessary() {
- assert hasWriteLock() : "Starting secret manager needs write lock";
+ assert hasWriteLock(FSNamesystemLockMode.BM) : "Starting secret manager needs write lock";
boolean shouldRun = shouldUseDelegationTokens() &&
!isInSafeMode() && getEditLog().isOpenForWrite();
boolean running = dtSecretManager.isRunning();
@@ -1354,7 +1354,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
*/
void startCommonServices(Configuration conf, HAContext haContext) throws IOException {
this.registerMBean(); // register the MBean for the FSNamesystemState
- writeLock();
+ writeLock(FSNamesystemLockMode.GLOBAL);
this.haContext = haContext;
try {
nnResourceChecker = new NameNodeResourceChecker(conf);
@@ -1367,7 +1367,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
completeBlocksTotal);
blockManager.activate(conf, completeBlocksTotal);
} finally {
- writeUnlock("startCommonServices");
+ writeUnlock(FSNamesystemLockMode.GLOBAL, "startCommonServices");
}
registerMXBean();
@@ -1406,7 +1406,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
void startActiveServices() throws IOException {
startingActiveService = true;
LOG.info("Starting services required for active state");
- writeLock();
+ writeLock(FSNamesystemLockMode.GLOBAL);
try {
FSEditLog editLog = getFSImage().getEditLog();
@@ -1499,7 +1499,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
} finally {
startingActiveService = false;
blockManager.checkSafeMode();
- writeUnlock("startActiveServices");
+ writeUnlock(FSNamesystemLockMode.GLOBAL, "startActiveServices");
}
}
@@ -5231,7 +5231,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
* @throws IOException
*/
void enterSafeMode(boolean resourcesLow) throws IOException {
- writeLock();
+ writeLock(FSNamesystemLockMode.GLOBAL);
try {
// Stop the secret manager, since rolling the master key would
// try to write to the edit log
@@ -5250,7 +5250,8 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
NameNode.stateChangeLog.info("STATE* Safe mode is ON.\n" +
getSafeModeTip());
} finally {
- writeUnlock("enterSafeMode", getLockReportInfoSupplier(null));
+ writeUnlock(FSNamesystemLockMode.GLOBAL,
+ "enterSafeMode", getLockReportInfoSupplier(null));
}
}
@@ -5259,7 +5260,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
* @param force true if to leave safe mode forcefully with -forceExit option
*/
void leaveSafeMode(boolean force) {
- writeLock();
+ writeLock(FSNamesystemLockMode.GLOBAL);
try {
if (!isInSafeMode()) {
NameNode.stateChangeLog.info("STATE* Safe mode is already OFF");
@@ -5270,7 +5271,8 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
startSecretManagerIfNecessary();
}
} finally {
- writeUnlock("leaveSafeMode", getLockReportInfoSupplier(null));
+ writeUnlock(FSNamesystemLockMode.GLOBAL,
+ "leaveSafeMode", getLockReportInfoSupplier(null));
}
}
@@ -8781,8 +8783,15 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
*/
@Override
public synchronized void checkAndProvisionSnapshotTrashRoots() {
+ assert hasWriteLock(FSNamesystemLockMode.BM);
if (isSnapshotTrashRootEnabled && (haEnabled && inActiveState()
|| !haEnabled) && !blockManager.isInSafeMode()) {
+ boolean releaseFSLock = false;
+ if (!hasWriteLock(FSNamesystemLockMode.GLOBAL)) {
+ writeUnlock(FSNamesystemLockMode.BM, "CheckAndProvisionSnapshotTrashRoots");
+ writeLock(FSNamesystemLockMode.GLOBAL);
+ releaseFSLock = true;
+ }
SnapshottableDirectoryStatus dirStatus = null;
try {
SnapshottableDirectoryStatus[] dirStatusList =
@@ -8815,6 +8824,11 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
LOG.error("Could not provision Trash directory for existing "
+ "snapshottable directory {}", dirStatus, e);
}
+ } finally {
+ if (releaseFSLock) {
+ writeUnlock(FSNamesystemLockMode.GLOBAL, "checkAndProvisionSnapshotTrashRoots");
+ writeLock(FSNamesystemLockMode.BM);
+ }
}
}
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManagerSafeMode.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManagerSafeMode.java
index d32cde834736..ca823d455147 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManagerSafeMode.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManagerSafeMode.java
@@ -27,6 +27,7 @@ import org.apache.hadoop.hdfs.server.blockmanagement.BlockManagerSafeMode.BMSafe
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NamenodeRole;
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
import org.apache.hadoop.hdfs.server.namenode.NameNode;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.test.Whitebox;
@@ -95,6 +96,8 @@ public class TestBlockManagerSafeMode {
fsn = mock(FSNamesystem.class);
doReturn(true).when(fsn).hasWriteLock();
doReturn(true).when(fsn).hasReadLock();
+ doReturn(true).when(fsn).hasWriteLock(FSNamesystemLockMode.BM);
+ doReturn(true).when(fsn).hasReadLock(FSNamesystemLockMode.BM);
doReturn(true).when(fsn).isRunning();
NameNode.initMetrics(conf, NamenodeRole.NAMENODE);
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicy.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicy.java
index fd7ea14446ab..5dbdef446e96 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicy.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicy.java
@@ -1462,6 +1462,7 @@ public class TestReplicationPolicy extends BaseReplicationPolicyTest {
throws IOException {
Namesystem mockNS = mock(Namesystem.class);
when(mockNS.hasWriteLock()).thenReturn(true);
+ when(mockNS.hasWriteLock(FSNamesystemLockMode.BM)).thenReturn(true);
BlockManager bm = new BlockManager(mockNS, false, new HdfsConfiguration());
LowRedundancyBlocks lowRedundancyBlocks = bm.neededReconstruction;
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org
(hadoop) 04/23: HDFS-17405. [FGL] Using different metric name to trace performance for FGL and Global lock (#6600)
Posted by za...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zanderxu pushed a commit to branch HDFS-17384
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit f733d942d10529f351ef41b5e06805509967a176
Author: ZanderXu <za...@apache.org>
AuthorDate: Wed Mar 6 15:17:53 2024 +0800
HDFS-17405. [FGL] Using different metric name to trace performance for FGL and Global lock (#6600)
---
.../hdfs/server/namenode/FSNamesystemLock.java | 34 ++++++++++++----------
.../namenode/fgl/FineGrainedFSNamesystemLock.java | 4 +--
.../namenode/fgl/GlobalFSNamesystemLock.java | 2 +-
.../hdfs/server/namenode/TestFSNamesystemLock.java | 20 ++++++-------
4 files changed, 32 insertions(+), 28 deletions(-)
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystemLock.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystemLock.java
index abdc80e1e81a..8bfe82eb8dfc 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystemLock.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystemLock.java
@@ -56,7 +56,7 @@ import static org.apache.hadoop.log.LogThrottlingHelper.LogAction;
* to be true, metrics will be emitted into the FSNamesystem metrics registry
* for each operation which acquires this lock indicating how long the operation
* held the lock for. These metrics have names of the form
- * FSN(Read|Write)LockNanosOperationName, where OperationName denotes the name
+ * ${LockName}(Read|Write)LockNanosOperationName, where OperationName denotes the name
* of the operation that initiated the lock hold (this will be OTHER for certain
* uncategorized operations) and they export the hold time values in
* nanoseconds. Note that if a thread dies, metrics produced after the
@@ -67,6 +67,7 @@ import static org.apache.hadoop.log.LogThrottlingHelper.LogAction;
public class FSNamesystemLock {
@VisibleForTesting
protected ReentrantReadWriteLock coarseLock;
+ private final String lockName;
private volatile boolean metricsEnabled;
private final MutableRatesWithAggregation detailedHoldTimeMetrics;
@@ -123,23 +124,26 @@ public class FSNamesystemLock {
@VisibleForTesting
static final String OP_NAME_OTHER = "OTHER";
- private static final String READ_LOCK_METRIC_PREFIX = "FSNReadLock";
- private static final String WRITE_LOCK_METRIC_PREFIX = "FSNWriteLock";
+ private final String readLockMetricPrefix;
+ private final String writeLockMetricPrefix;
private static final String LOCK_METRIC_SUFFIX = "Nanos";
private static final String OVERALL_METRIC_NAME = "Overall";
- public FSNamesystemLock(Configuration conf,
+ public FSNamesystemLock(Configuration conf, String lockName,
MutableRatesWithAggregation detailedHoldTimeMetrics) {
- this(conf, detailedHoldTimeMetrics, new Timer());
+ this(conf, lockName, detailedHoldTimeMetrics, new Timer());
}
@VisibleForTesting
- FSNamesystemLock(Configuration conf,
+ FSNamesystemLock(Configuration conf, String lockName,
MutableRatesWithAggregation detailedHoldTimeMetrics, Timer timer) {
+ this.lockName = lockName;
+ this.readLockMetricPrefix = this.lockName + "ReadLock";
+ this.writeLockMetricPrefix = this.lockName + "WriteLock";
boolean fair = conf.getBoolean(DFS_NAMENODE_FSLOCK_FAIR_KEY,
DFS_NAMENODE_FSLOCK_FAIR_DEFAULT);
- FSNamesystem.LOG.info("fsLock is fair: " + fair);
+ FSNamesystem.LOG.info("{}Lock is fair: {}.", this.lockName, fair);
this.coarseLock = new ReentrantReadWriteLock(fair);
this.timer = timer;
@@ -157,8 +161,8 @@ public class FSNamesystemLock {
this.metricsEnabled = conf.getBoolean(
DFS_NAMENODE_LOCK_DETAILED_METRICS_KEY,
DFS_NAMENODE_LOCK_DETAILED_METRICS_DEFAULT);
- FSNamesystem.LOG.info("Detailed lock hold time metrics enabled: " +
- this.metricsEnabled);
+ FSNamesystem.LOG.info("Detailed lock hold time metrics of {}Lock is {}.",
+ this.lockName, this.metricsEnabled ? "enabled" : "disabled");
this.detailedHoldTimeMetrics = detailedHoldTimeMetrics;
}
@@ -231,9 +235,9 @@ public class FSNamesystemLock {
LockHeldInfo lockHeldInfo =
longestReadLockHeldInfo.getAndSet(new LockHeldInfo());
FSNamesystem.LOG.info(
- "\tNumber of suppressed read-lock reports: {}"
+ "\tNumber of suppressed read-lock reports of {}Lock is {}"
+ "\n\tLongest read-lock held at {} for {}ms by {}{} via {}",
- numSuppressedWarnings, Time.formatTime(lockHeldInfo.getStartTimeMs()),
+ this.lockName, numSuppressedWarnings, Time.formatTime(lockHeldInfo.getStartTimeMs()),
lockHeldInfo.getIntervalMs(), lockHeldInfo.getOpName(),
lockHeldInfo.getLockReportInfo(), lockHeldInfo.getStackTrace());
}
@@ -337,10 +341,10 @@ public class FSNamesystemLock {
if (logAction.shouldLog()) {
FSNamesystem.LOG.info(
- "\tNumber of suppressed write-lock reports: {}"
+ "\tNumber of suppressed write-lock reports of {}Lock is {}"
+ "\n\tLongest write-lock held at {} for {}ms by {}{} via {}"
+ "\n\tTotal suppressed write-lock held time: {}",
- logAction.getCount() - 1,
+ this.lockName, logAction.getCount() - 1,
Time.formatTime(lockHeldInfo.getStartTimeMs()),
lockHeldInfo.getIntervalMs(), lockHeldInfo.getOpName(),
lockHeldInfo.getLockReportInfo(), lockHeldInfo.getStackTrace(),
@@ -456,8 +460,8 @@ public class FSNamesystemLock {
}
}
- private static String getMetricName(String operationName, boolean isWrite) {
- return (isWrite ? WRITE_LOCK_METRIC_PREFIX : READ_LOCK_METRIC_PREFIX) +
+ private String getMetricName(String operationName, boolean isWrite) {
+ return (isWrite ? this.writeLockMetricPrefix : this.readLockMetricPrefix) +
org.apache.commons.lang3.StringUtils.capitalize(operationName) +
LOCK_METRIC_SUFFIX;
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/fgl/FineGrainedFSNamesystemLock.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/fgl/FineGrainedFSNamesystemLock.java
index c2e3980476a9..2d67e68a2814 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/fgl/FineGrainedFSNamesystemLock.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/fgl/FineGrainedFSNamesystemLock.java
@@ -35,8 +35,8 @@ public class FineGrainedFSNamesystemLock implements FSNLockManager {
private final FSNamesystemLock bmLock;
public FineGrainedFSNamesystemLock(Configuration conf, MutableRatesWithAggregation aggregation) {
- this.fsLock = new FSNamesystemLock(conf, aggregation);
- this.bmLock = new FSNamesystemLock(conf, aggregation);
+ this.fsLock = new FSNamesystemLock(conf, "FS", aggregation);
+ this.bmLock = new FSNamesystemLock(conf, "BM", aggregation);
}
@Override
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/fgl/GlobalFSNamesystemLock.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/fgl/GlobalFSNamesystemLock.java
index c01529fac4c3..7c3a87d614e0 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/fgl/GlobalFSNamesystemLock.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/fgl/GlobalFSNamesystemLock.java
@@ -29,7 +29,7 @@ public class GlobalFSNamesystemLock implements FSNLockManager {
private final FSNamesystemLock lock;
public GlobalFSNamesystemLock(Configuration conf, MutableRatesWithAggregation aggregation) {
- this.lock = new FSNamesystemLock(conf, aggregation);
+ this.lock = new FSNamesystemLock(conf, "FSN", aggregation);
}
@Override
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystemLock.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystemLock.java
index f0ae18101670..512cd1531d6d 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystemLock.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystemLock.java
@@ -57,17 +57,17 @@ public class TestFSNamesystemLock {
Configuration conf = new Configuration();
conf.setBoolean(DFS_NAMENODE_FSLOCK_FAIR_KEY, true);
- FSNamesystemLock fsnLock = new FSNamesystemLock(conf, null);
+ FSNamesystemLock fsnLock = new FSNamesystemLock(conf, "FSN", null);
assertTrue(fsnLock.coarseLock.isFair());
conf.setBoolean(DFS_NAMENODE_FSLOCK_FAIR_KEY, false);
- fsnLock = new FSNamesystemLock(conf, null);
+ fsnLock = new FSNamesystemLock(conf, "FSN", null);
assertFalse(fsnLock.coarseLock.isFair());
}
@Test
public void testFSNamesystemLockCompatibility() {
- FSNamesystemLock rwLock = new FSNamesystemLock(new Configuration(), null);
+ FSNamesystemLock rwLock = new FSNamesystemLock(new Configuration(), "FSN", null);
assertEquals(0, rwLock.getReadHoldCount());
rwLock.readLock();
@@ -107,7 +107,7 @@ public class TestFSNamesystemLock {
final CountDownLatch latch = new CountDownLatch(threadCount);
final Configuration conf = new Configuration();
conf.setBoolean(DFS_NAMENODE_FSLOCK_FAIR_KEY, true);
- final FSNamesystemLock rwLock = new FSNamesystemLock(conf, null);
+ final FSNamesystemLock rwLock = new FSNamesystemLock(conf, "FSN", null);
rwLock.writeLock();
ExecutorService helper = Executors.newFixedThreadPool(threadCount);
@@ -150,7 +150,7 @@ public class TestFSNamesystemLock {
writeLockSuppressWarningInterval, TimeUnit.MILLISECONDS);
final FakeTimer timer = new FakeTimer();
- final FSNamesystemLock fsnLock = new FSNamesystemLock(conf, null, timer);
+ final FSNamesystemLock fsnLock = new FSNamesystemLock(conf, "FSN", null, timer);
timer.advance(writeLockSuppressWarningInterval);
LogCapturer logs = LogCapturer.captureLogs(FSNamesystem.LOG);
@@ -213,7 +213,7 @@ public class TestFSNamesystemLock {
"held at " + Time.formatTime(timer.now()).substring(0, 10);
assertTrue(logs.getOutput().contains(startTimeStr));
assertTrue(logs.getOutput().contains(
- "Number of suppressed write-lock reports: 2"));
+ "Number of suppressed write-lock reports of FSNLock is 2"));
}
/**
@@ -233,7 +233,7 @@ public class TestFSNamesystemLock {
readLockSuppressWarningInterval, TimeUnit.MILLISECONDS);
final FakeTimer timer = new FakeTimer();
- final FSNamesystemLock fsnLock = new FSNamesystemLock(conf, null, timer);
+ final FSNamesystemLock fsnLock = new FSNamesystemLock(conf, "FSN", null, timer);
timer.advance(readLockSuppressWarningInterval);
LogCapturer logs = LogCapturer.captureLogs(FSNamesystem.LOG);
@@ -304,7 +304,7 @@ public class TestFSNamesystemLock {
"held at " + Time.formatTime(timer.now()).substring(0, 10);
assertTrue(logs.getOutput().contains(startTimeStr));
assertTrue(logs.getOutput().contains(
- "Number of suppressed read-lock reports: 3"));
+ "Number of suppressed read-lock reports of FSNLock is 3"));
// Report if it's held for a long time (and time since last report
// exceeds the suppress warning interval) while another thread also has the
@@ -366,7 +366,7 @@ public class TestFSNamesystemLock {
MetricsRegistry registry = new MetricsRegistry("Test");
MutableRatesWithAggregation rates =
registry.newRatesWithAggregation("Test");
- FSNamesystemLock fsLock = new FSNamesystemLock(conf, rates, timer);
+ FSNamesystemLock fsLock = new FSNamesystemLock(conf, "FSN", rates, timer);
fsLock.readLock();
timer.advanceNanos(1300000);
@@ -419,7 +419,7 @@ public class TestFSNamesystemLock {
writeLockSuppressWarningInterval, TimeUnit.MILLISECONDS);
final FakeTimer timer = new FakeTimer();
- final FSNamesystemLock fsnLock = new FSNamesystemLock(conf, null, timer);
+ final FSNamesystemLock fsnLock = new FSNamesystemLock(conf, "FSN", null, timer);
timer.advance(writeLockSuppressWarningInterval);
LogCapturer logs = LogCapturer.captureLogs(FSNamesystem.LOG);
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org
(hadoop) 20/23: HDFS-17424. [FGL] DelegationTokenSecretManager supports fine-grained lock (#6696)
Posted by za...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zanderxu pushed a commit to branch HDFS-17384
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit 02de6df9d4434d71b8d16c2c0e8ec0324a76953a
Author: Yuanbo Liu <yu...@apache.org>
AuthorDate: Tue Apr 16 11:51:02 2024 +0800
HDFS-17424. [FGL] DelegationTokenSecretManager supports fine-grained lock (#6696)
---
.../security/token/delegation/DelegationTokenSecretManager.java | 9 +++++----
.../org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java | 4 ++--
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/security/token/delegation/DelegationTokenSecretManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/security/token/delegation/DelegationTokenSecretManager.java
index b89998d98958..5ac5d29d9a2c 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/security/token/delegation/DelegationTokenSecretManager.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/security/token/delegation/DelegationTokenSecretManager.java
@@ -27,6 +27,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.util.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -372,7 +373,7 @@ public class DelegationTokenSecretManager
// closes the edit log files. Doing this inside the
// fsn lock will prevent being interrupted when stopping
// the secret manager.
- namesystem.readLockInterruptibly();
+ namesystem.readLockInterruptibly(FSNamesystemLockMode.FS);
try {
// this monitor isn't necessary if stopped while holding write lock
// but for safety, guard against a stop with read lock.
@@ -383,7 +384,7 @@ public class DelegationTokenSecretManager
namesystem.logUpdateMasterKey(key);
}
} finally {
- namesystem.readUnlock("logUpdateMasterKey");
+ namesystem.readUnlock(FSNamesystemLockMode.FS, "logUpdateMasterKey");
}
} catch (InterruptedException ie) {
// AbstractDelegationTokenManager may crash if an exception is thrown.
@@ -401,7 +402,7 @@ public class DelegationTokenSecretManager
// closes the edit log files. Doing this inside the
// fsn lock will prevent being interrupted when stopping
// the secret manager.
- namesystem.readLockInterruptibly();
+ namesystem.readLockInterruptibly(FSNamesystemLockMode.FS);
try {
// this monitor isn't necessary if stopped while holding write lock
// but for safety, guard against a stop with read lock.
@@ -412,7 +413,7 @@ public class DelegationTokenSecretManager
namesystem.logExpireDelegationToken(dtId);
}
} finally {
- namesystem.readUnlock("logExpireToken");
+ namesystem.readUnlock(FSNamesystemLockMode.FS, "logExpireToken");
}
} catch (InterruptedException ie) {
// AbstractDelegationTokenManager may crash if an exception is thrown.
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
index a9d24192cc62..db12d646a671 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
@@ -6489,7 +6489,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
"the DT manager before entering safemode!";
// edit log rolling is not thread-safe and must be protected by the
// fsn lock. not updating namespace so read lock is sufficient.
- assert hasReadLock();
+ assert hasReadLock(FSNamesystemLockMode.FS);
getEditLog().logUpdateMasterKey(key);
getEditLog().logSync();
}
@@ -6505,7 +6505,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
"the DT manager before entering safemode!";
// edit log rolling is not thread-safe and must be protected by the
// fsn lock. not updating namespace so read lock is sufficient.
- assert hasReadLock();
+ assert hasReadLock(FSNamesystemLockMode.FS);
// do not logSync so expiration edits are batched
getEditLog().logCancelDelegationToken(id);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org
(hadoop) 23/23: HDFS-17457. [FGL] UTs support fine-grained locking (#6741)
Posted by za...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zanderxu pushed a commit to branch HDFS-17384
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit 14153f07aab8a229f128f503b2741d1c81a824b2
Author: ZanderXu <za...@apache.org>
AuthorDate: Tue Apr 23 09:42:23 2024 +0800
HDFS-17457. [FGL] UTs support fine-grained locking (#6741)
---
.../server/federation/router/TestRouterRpc.java | 5 +++--
.../hadoop/hdfs/TestBlocksScheduledCounter.java | 11 ++++++----
.../org/apache/hadoop/hdfs/TestFileCorruption.java | 13 +++++------
.../blockmanagement/BlockManagerTestUtil.java | 22 ++++++++++---------
.../server/blockmanagement/TestBlockManager.java | 8 +++----
.../TestBlocksWithNotEnoughRacks.java | 5 +++--
.../blockmanagement/TestComputeInvalidateWork.java | 25 +++++++++++-----------
.../blockmanagement/TestHeartbeatHandling.java | 9 ++++----
.../TestNameNodePrunesMissingStorages.java | 10 +++++----
.../hdfs/server/blockmanagement/TestNodeCount.java | 5 +++--
.../blockmanagement/TestOverReplicatedBlocks.java | 9 ++++----
.../blockmanagement/TestPendingReconstruction.java | 17 ++++++++-------
...tReconstructStripedBlocksWithRackAwareness.java | 10 +++++----
.../TestReplicationPolicyConsiderLoad.java | 10 +++++----
.../TestReplicationPolicyExcludeSlowNodes.java | 11 ++++++----
...licationPolicyRatioConsiderLoadWithStorage.java | 6 ++++--
.../hdfs/server/namenode/NameNodeAdapter.java | 25 +++++++++++-----------
.../hdfs/server/namenode/TestAddBlockRetry.java | 14 ++++++------
.../TestAddOverReplicatedStripedBlocks.java | 6 ++++--
.../TestBlockPlacementPolicyRackFaultTolerant.java | 6 ++++--
.../hdfs/server/namenode/TestCacheDirectives.java | 17 ++++++++-------
.../hdfs/server/namenode/TestDeleteRace.java | 5 +++--
.../server/namenode/TestDiskspaceQuotaUpdate.java | 5 +++--
.../hdfs/server/namenode/TestEditLogRace.java | 6 ++++--
.../server/namenode/TestFSImageWithSnapshot.java | 9 ++++----
.../hdfs/server/namenode/TestFSNamesystem.java | 5 +++--
.../server/namenode/TestFSNamesystemMBean.java | 7 +++---
.../hdfs/server/namenode/TestFileTruncate.java | 9 ++++----
.../hadoop/hdfs/server/namenode/TestFsck.java | 9 ++++----
.../server/namenode/TestGetBlockLocations.java | 14 ++++++------
.../server/namenode/TestLargeDirectoryDelete.java | 5 +++--
.../hdfs/server/namenode/TestListOpenFiles.java | 5 +++--
.../namenode/TestNameNodeMetadataConsistency.java | 11 ++++++----
.../namenode/TestReconstructStripedBlocks.java | 5 +++--
.../server/namenode/TestSecurityTokenEditLog.java | 5 +++--
.../hdfs/server/namenode/ha/TestDNFencing.java | 5 +++--
.../namenode/metrics/TestNameNodeMetrics.java | 13 +++++------
...TestINodeFileUnderConstructionWithSnapshot.java | 5 +++--
.../org/apache/hadoop/hdfs/tools/TestDFSAdmin.java | 5 +++--
.../namenode/ITestProvidedImplementation.java | 13 +++++------
40 files changed, 220 insertions(+), 165 deletions(-)
diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpc.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpc.java
index 766a035151c2..9028e6bc5e32 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpc.java
+++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpc.java
@@ -121,6 +121,7 @@ import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
import org.apache.hadoop.hdfs.server.namenode.INodeDirectory;
import org.apache.hadoop.hdfs.server.namenode.NameNode;
import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.namenode.snapshot.SnapshotTestHelper;
import org.apache.hadoop.hdfs.server.protocol.BlocksWithLocations;
import org.apache.hadoop.hdfs.server.protocol.BlocksWithLocations.BlockWithLocations;
@@ -1660,10 +1661,10 @@ public class TestRouterRpc {
// mark a replica as corrupt
LocatedBlock block = NameNodeAdapter
.getBlockLocations(nameNode, testFile, 0, 1024).get(0);
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.BM);
bm.findAndMarkBlockAsCorrupt(block.getBlock(), block.getLocations()[0],
"STORAGE_ID", "TEST");
- namesystem.writeUnlock();
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "findAndMarkBlockAsCorrupt");
BlockManagerTestUtil.updateState(bm);
DFSTestUtil.waitCorruptReplicas(fileSystem, namesystem,
new Path(testFile), block.getBlock(), 1);
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestBlocksScheduledCounter.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestBlocksScheduledCounter.java
index d86700b39b11..e2e36110049c 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestBlocksScheduledCounter.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestBlocksScheduledCounter.java
@@ -35,6 +35,7 @@ import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeManager;
import org.apache.hadoop.hdfs.server.datanode.DataNode;
import org.apache.hadoop.hdfs.server.datanode.DataNodeTestUtils;
import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.junit.After;
import org.junit.Test;
@@ -175,7 +176,7 @@ public class TestBlocksScheduledCounter {
.getBlockLocations(cluster.getNameNode(), filePath.toString(), 0, 1)
.get(0);
DatanodeInfo[] locs = block.getLocations();
- cluster.getNamesystem().writeLock();
+ cluster.getNamesystem().writeLock(FSNamesystemLockMode.BM);
try {
bm.findAndMarkBlockAsCorrupt(block.getBlock(), locs[0], "STORAGE_ID",
"TEST");
@@ -185,7 +186,8 @@ public class TestBlocksScheduledCounter {
BlockManagerTestUtil.updateState(bm);
assertEquals(1L, bm.getPendingReconstructionBlocksCount());
} finally {
- cluster.getNamesystem().writeUnlock();
+ cluster.getNamesystem().writeUnlock(FSNamesystemLockMode.BM,
+ "findAndMarkBlockAsCorrupt");
}
// 4. delete the file
@@ -238,13 +240,14 @@ public class TestBlocksScheduledCounter {
DataNodeTestUtils.setHeartbeatsDisabledForTests(dn, true);
}
- cluster.getNamesystem().writeLock();
+ cluster.getNamesystem().writeLock(FSNamesystemLockMode.BM);
try {
BlockManagerTestUtil.computeAllPendingWork(bm);
BlockManagerTestUtil.updateState(bm);
assertEquals(1L, bm.getPendingReconstructionBlocksCount());
} finally {
- cluster.getNamesystem().writeUnlock();
+ cluster.getNamesystem().writeUnlock(FSNamesystemLockMode.BM,
+ "testBlocksScheduledCounterOnTruncate");
}
// 5.truncate the file whose block exists in pending reconstruction
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestFileCorruption.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestFileCorruption.java
index 381cf1694f5d..f7088bc7ce53 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestFileCorruption.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestFileCorruption.java
@@ -51,6 +51,7 @@ import org.apache.hadoop.hdfs.server.datanode.DataNode;
import org.apache.hadoop.hdfs.server.datanode.InternalDataNodeTestUtils;
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
import org.apache.hadoop.hdfs.server.namenode.NameNode;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration;
import org.apache.hadoop.hdfs.server.protocol.DatanodeStorage;
import org.apache.hadoop.test.GenericTestUtils;
@@ -159,13 +160,13 @@ public class TestFileCorruption {
DatanodeRegistration dnR = InternalDataNodeTestUtils.
getDNRegistrationForBP(dataNode, blk.getBlockPoolId());
FSNamesystem ns = cluster.getNamesystem();
- ns.writeLock();
+ ns.writeLock(FSNamesystemLockMode.BM);
try {
cluster.getNamesystem().getBlockManager().findAndMarkBlockAsCorrupt(blk,
new DatanodeInfoBuilder().setNodeID(dnR).build(), "TEST",
"STORAGE_ID");
} finally {
- ns.writeUnlock();
+ ns.writeUnlock(FSNamesystemLockMode.BM, "testArrayOutOfBoundsException");
}
// open the file
@@ -210,16 +211,16 @@ public class TestFileCorruption {
FSNamesystem ns = cluster.getNamesystem();
//fail the storage on that node which has the block
try {
- ns.writeLock();
+ ns.writeLock(FSNamesystemLockMode.BM);
updateAllStorages(bm);
} finally {
- ns.writeUnlock();
+ ns.writeUnlock(FSNamesystemLockMode.BM, "testCorruptionWithDiskFailure");
}
- ns.writeLock();
+ ns.writeLock(FSNamesystemLockMode.BM);
try {
markAllBlocksAsCorrupt(bm, blk);
} finally {
- ns.writeUnlock();
+ ns.writeUnlock(FSNamesystemLockMode.BM, "testCorruptionWithDiskFailure");
}
// open the file
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManagerTestUtil.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManagerTestUtil.java
index c25cc88059d3..5278f6e2dd49 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManagerTestUtil.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManagerTestUtil.java
@@ -31,6 +31,7 @@ import org.apache.hadoop.hdfs.protocol.Block;
import org.apache.hadoop.hdfs.server.blockmanagement.BlockManagerSafeMode.BMSafeModeStatus;
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
import org.apache.hadoop.hdfs.server.namenode.NameNode;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.protocol.DatanodeStorage;
import org.apache.hadoop.hdfs.server.protocol.StorageReport;
import org.apache.hadoop.test.Whitebox;
@@ -50,23 +51,23 @@ public class BlockManagerTestUtil {
/** @return the datanode descriptor for the given the given storageID. */
public static DatanodeDescriptor getDatanode(final FSNamesystem ns,
final String storageID) {
- ns.readLock();
+ ns.readLock(FSNamesystemLockMode.BM);
try {
return ns.getBlockManager().getDatanodeManager().getDatanode(storageID);
} finally {
- ns.readUnlock();
+ ns.readUnlock(FSNamesystemLockMode.BM, "getDatanode");
}
}
public static Iterator<BlockInfo> getBlockIterator(final FSNamesystem ns,
final String storageID, final int startBlock) {
- ns.readLock();
+ ns.readLock(FSNamesystemLockMode.BM);
try {
DatanodeDescriptor dn =
ns.getBlockManager().getDatanodeManager().getDatanode(storageID);
return dn.getBlockIterator(startBlock);
} finally {
- ns.readUnlock();
+ ns.readUnlock(FSNamesystemLockMode.BM, "getBlockIterator");
}
}
@@ -88,7 +89,7 @@ public class BlockManagerTestUtil {
*/
public static int[] getReplicaInfo(final FSNamesystem namesystem, final Block b) {
final BlockManager bm = namesystem.getBlockManager();
- namesystem.readLock();
+ namesystem.readLock(FSNamesystemLockMode.BM);
try {
final BlockInfo storedBlock = bm.getStoredBlock(b);
return new int[]{getNumberOfRacks(bm, b),
@@ -96,7 +97,7 @@ public class BlockManagerTestUtil {
bm.neededReconstruction.contains(storedBlock) ? 1 : 0,
getNumberOfDomains(bm, b)};
} finally {
- namesystem.readUnlock();
+ namesystem.readUnlock(FSNamesystemLockMode.BM, "getReplicaInfo");
}
}
@@ -247,7 +248,7 @@ public class BlockManagerTestUtil {
*/
public static void noticeDeadDatanode(NameNode nn, String dnName) {
FSNamesystem namesystem = nn.getNamesystem();
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.BM);
try {
DatanodeManager dnm = namesystem.getBlockManager().getDatanodeManager();
HeartbeatManager hbm = dnm.getHeartbeatManager();
@@ -265,7 +266,7 @@ public class BlockManagerTestUtil {
hbm.heartbeatCheck();
}
} finally {
- namesystem.writeUnlock();
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "noticeDeadDatanode");
}
}
@@ -302,12 +303,13 @@ public class BlockManagerTestUtil {
*/
public static int checkHeartbeatAndGetUnderReplicatedBlocksCount(
FSNamesystem namesystem, BlockManager bm) {
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.BM);
try {
bm.getDatanodeManager().getHeartbeatManager().heartbeatCheck();
return bm.getUnderReplicatedNotMissingBlocks();
} finally {
- namesystem.writeUnlock();
+ namesystem.writeUnlock(FSNamesystemLockMode.BM,
+ "checkHeartbeatAndGetUnderReplicatedBlocksCount");
}
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManager.java
index 0b1c18ed1d00..cf9aee7c7021 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManager.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManager.java
@@ -1624,7 +1624,7 @@ public class TestBlockManager {
}
failedStorageDataNode.updateHeartbeat(reports.toArray(StorageReport
.EMPTY_ARRAY), 0L, 0L, 0, 0, null);
- ns.writeLock();
+ ns.writeLock(FSNamesystemLockMode.BM);
DatanodeStorageInfo corruptStorageInfo= null;
for(int i=0; i<corruptStorageDataNode.getStorageInfos().length; i++) {
corruptStorageInfo = corruptStorageDataNode.getStorageInfos()[i];
@@ -1638,16 +1638,16 @@ public class TestBlockManager {
blockManager.findAndMarkBlockAsCorrupt(blk, corruptStorageDataNode,
corruptStorageInfo.getStorageID(),
CorruptReplicasMap.Reason.ANY.toString());
- ns.writeUnlock();
+ ns.writeUnlock(FSNamesystemLockMode.BM, "testBlockManagerMachinesArray");
BlockInfo[] blockInfos = new BlockInfo[] {blockInfo};
- ns.readLock();
+ ns.readLock(FSNamesystemLockMode.BM);
LocatedBlocks locatedBlocks =
blockManager.createLocatedBlocks(blockInfos, 3L, false, 0L, 3L,
false, false, null, null);
assertTrue("Located Blocks should exclude corrupt" +
"replicas and failed storages",
locatedBlocks.getLocatedBlocks().size() == 1);
- ns.readUnlock();
+ ns.readUnlock(FSNamesystemLockMode.BM, "open");
} finally {
if (cluster != null) {
cluster.shutdown();
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlocksWithNotEnoughRacks.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlocksWithNotEnoughRacks.java
index 7dfb9514f9e7..059b5829f4ca 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlocksWithNotEnoughRacks.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlocksWithNotEnoughRacks.java
@@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeoutException;
import org.apache.hadoop.hdfs.server.datanode.InternalDataNodeTestUtils;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -602,11 +603,11 @@ public class TestBlocksWithNotEnoughRacks {
static BlockReconstructionWork scheduleReconstruction(
FSNamesystem fsn, BlockInfo block, int priority) {
- fsn.writeLock();
+ fsn.writeLock(FSNamesystemLockMode.BM);
try {
return fsn.getBlockManager().scheduleReconstruction(block, priority);
} finally {
- fsn.writeUnlock();
+ fsn.writeUnlock(FSNamesystemLockMode.BM, "scheduleReconstruction");
}
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestComputeInvalidateWork.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestComputeInvalidateWork.java
index 4ae0316fa7a2..38396132f2ee 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestComputeInvalidateWork.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestComputeInvalidateWork.java
@@ -40,6 +40,7 @@ import org.apache.hadoop.hdfs.server.common.HdfsServerConstants;
import org.apache.hadoop.hdfs.server.common.StorageInfo;
import org.apache.hadoop.hdfs.server.datanode.DataNode;
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration;
import org.apache.hadoop.test.Whitebox;
import org.apache.hadoop.util.VersionInfo;
@@ -131,7 +132,7 @@ public class TestComputeInvalidateWork {
public void testComputeInvalidateReplicas() throws Exception {
final int blockInvalidateLimit = bm.getDatanodeManager()
.getBlockInvalidateLimit();
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.BM);
try {
for (int i=0; i<nodes.length; i++) {
for(int j=0; j<3*blockInvalidateLimit+1; j++) {
@@ -142,7 +143,7 @@ public class TestComputeInvalidateWork {
}
verifyInvalidationWorkCounts(blockInvalidateLimit);
} finally {
- namesystem.writeUnlock();
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "testComputeInvalidateReplicas");
}
}
@@ -154,7 +155,7 @@ public class TestComputeInvalidateWork {
public void testComputeInvalidateStripedBlockGroups() throws Exception {
final int blockInvalidateLimit =
bm.getDatanodeManager().getBlockInvalidateLimit();
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.BM);
try {
int nodeCount = ecPolicy.getNumDataUnits() + ecPolicy.getNumParityUnits();
for (int i = 0; i < nodeCount; i++) {
@@ -167,7 +168,7 @@ public class TestComputeInvalidateWork {
}
verifyInvalidationWorkCounts(blockInvalidateLimit);
} finally {
- namesystem.writeUnlock();
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "testComputeInvalidateStripedBlockGroups");
}
}
@@ -181,7 +182,7 @@ public class TestComputeInvalidateWork {
final int blockInvalidateLimit =
bm.getDatanodeManager().getBlockInvalidateLimit();
final Random random = new Random(System.currentTimeMillis());
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.BM);
try {
int nodeCount = ecPolicy.getNumDataUnits() + ecPolicy.getNumParityUnits();
for (int i = 0; i < nodeCount; i++) {
@@ -201,7 +202,7 @@ public class TestComputeInvalidateWork {
}
verifyInvalidationWorkCounts(blockInvalidateLimit);
} finally {
- namesystem.writeUnlock();
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "testComputeInvalidate");
}
}
@@ -212,7 +213,7 @@ public class TestComputeInvalidateWork {
*/
@Test(timeout=120000)
public void testDatanodeReformat() throws Exception {
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.BM);
try {
// Change the datanode UUID to emulate a reformat
String poolId = cluster.getNamesystem().getBlockPoolId();
@@ -234,7 +235,7 @@ public class TestComputeInvalidateWork {
assertEquals(0, bm.computeInvalidateWork(1));
assertEquals(0, bm.getPendingDeletionBlocksCount());
} finally {
- namesystem.writeUnlock();
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "testDatanodeReformat");
}
}
@@ -255,7 +256,7 @@ public class TestComputeInvalidateWork {
dfs.delete(ecFile, false);
BlockManagerTestUtil.waitForMarkedDeleteQueueIsEmpty(
cluster.getNamesystem(0).getBlockManager());
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.BM);
InvalidateBlocks invalidateBlocks;
int totalStripedDataBlocks = totalBlockGroups * (ecPolicy.getNumDataUnits()
+ ecPolicy.getNumParityUnits());
@@ -272,7 +273,7 @@ public class TestComputeInvalidateWork {
assertEquals("Unexpected invalidate count for striped block groups!",
totalStripedDataBlocks, invalidateBlocks.getECBlocks());
} finally {
- namesystem.writeUnlock();
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "testDatanodeReRegistration");
}
// Re-register each DN and see that it wipes the invalidation work
int totalBlockGroupsPerDataNode = totalBlockGroups;
@@ -284,14 +285,14 @@ public class TestComputeInvalidateWork {
new StorageInfo(HdfsServerConstants.NodeType.DATA_NODE),
new ExportedBlockKeys(),
VersionInfo.getVersion());
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.BM);
try {
bm.getDatanodeManager().registerDatanode(reg);
expected -= (totalReplicasPerDataNode + totalBlockGroupsPerDataNode);
assertEquals("Expected number of invalidate blocks to decrease",
(long) expected, invalidateBlocks.numBlocks());
} finally {
- namesystem.writeUnlock();
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "testDatanodeReRegistration");
}
}
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestHeartbeatHandling.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestHeartbeatHandling.java
index f12f6f59f828..c7bf6ec8f6b6 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestHeartbeatHandling.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestHeartbeatHandling.java
@@ -36,6 +36,7 @@ import org.apache.hadoop.hdfs.server.datanode.InternalDataNodeTestUtils;
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
import org.apache.hadoop.hdfs.server.namenode.Namesystem;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.protocol.BlockCommand;
import org.apache.hadoop.hdfs.server.protocol.BlockRecoveryCommand;
import org.apache.hadoop.hdfs.server.protocol.DatanodeCommand;
@@ -91,7 +92,7 @@ public class TestHeartbeatHandling {
final DatanodeStorageInfo[] ONE_TARGET = {dd.getStorageInfo(storageID)};
try {
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.BM);
synchronized(hm) {
for (int i=0; i<MAX_REPLICATE_BLOCKS; i++) {
dd.addBlockToBeReplicated(
@@ -136,7 +137,7 @@ public class TestHeartbeatHandling {
assertEquals(0, cmds.length);
}
} finally {
- namesystem.writeUnlock();
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "testHeartbeat");
}
} finally {
cluster.shutdown();
@@ -176,7 +177,7 @@ public class TestHeartbeatHandling {
dd3.updateStorage(new DatanodeStorage(DatanodeStorage.generateUuid()));
try {
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.BM);
synchronized(hm) {
NameNodeAdapter.sendHeartBeat(nodeReg1, dd1, namesystem);
NameNodeAdapter.sendHeartBeat(nodeReg2, dd2, namesystem);
@@ -255,7 +256,7 @@ public class TestHeartbeatHandling {
assertEquals(recoveringNodes[2], dd3);
}
} finally {
- namesystem.writeUnlock();
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "testHeartbeat");
}
} finally {
cluster.shutdown();
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestNameNodePrunesMissingStorages.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestNameNodePrunesMissingStorages.java
index dea893bab3b4..944b27e656c2 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestNameNodePrunesMissingStorages.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestNameNodePrunesMissingStorages.java
@@ -39,6 +39,7 @@ import org.apache.hadoop.hdfs.server.datanode.DataNodeTestUtils;
import org.apache.hadoop.hdfs.server.datanode.StorageLocation;
import org.apache.hadoop.hdfs.server.datanode.fsdataset.FsDatasetSpi.FsVolumeReferences;
import org.apache.hadoop.hdfs.server.datanode.fsdataset.FsVolumeSpi;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration;
import org.apache.hadoop.hdfs.server.protocol.DatanodeStorage;
import org.apache.hadoop.hdfs.server.protocol.SlowDiskReports;
@@ -184,7 +185,7 @@ public class TestNameNodePrunesMissingStorages {
DataNodeTestUtils.triggerBlockReport(dn);
}
ExtendedBlock block = DFSTestUtil.getFirstBlock(fs, new Path("/foo1"));
- cluster.getNamesystem().writeLock();
+ cluster.getNamesystem().writeLock(FSNamesystemLockMode.BM);
final String storageIdToRemove;
String datanodeUuid;
// Find the first storage which this block is in.
@@ -200,7 +201,8 @@ public class TestNameNodePrunesMissingStorages {
storageIdToRemove = info.getStorageID();
datanodeUuid = info.getDatanodeDescriptor().getDatanodeUuid();
} finally {
- cluster.getNamesystem().writeUnlock();
+ cluster.getNamesystem().writeUnlock(FSNamesystemLockMode.BM,
+ "testRemovingStorageDoesNotProduceZombies");
}
// Find the DataNode which holds that first storage.
final DataNode datanodeToRemoveStorageFrom;
@@ -345,7 +347,7 @@ public class TestNameNodePrunesMissingStorages {
GenericTestUtils.waitFor(new Supplier<Boolean>() {
@Override
public Boolean get() {
- cluster.getNamesystem().writeLock();
+ cluster.getNamesystem().writeLock(FSNamesystemLockMode.BM);
try {
Iterator<DatanodeStorageInfo> storageInfoIter =
cluster.getNamesystem().getBlockManager().
@@ -367,7 +369,7 @@ public class TestNameNodePrunesMissingStorages {
LOG.info("Successfully found " + block.getBlockName() + " in " +
"be in storage id " + newStorageId);
} finally {
- cluster.getNamesystem().writeUnlock();
+ cluster.getNamesystem().writeUnlock(FSNamesystemLockMode.BM, "testRenamingStorageIds");
}
return true;
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestNodeCount.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestNodeCount.java
index d915b6e6b732..fa8f0af5a857 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestNodeCount.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestNodeCount.java
@@ -32,6 +32,7 @@ import org.apache.hadoop.hdfs.MiniDFSCluster.DataNodeProperties;
import org.apache.hadoop.hdfs.protocol.Block;
import org.apache.hadoop.hdfs.protocol.ExtendedBlock;
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.util.Time;
import org.junit.Test;
@@ -174,14 +175,14 @@ public class TestNodeCount {
/* threadsafe read of the replication counts for this block */
NumberReplicas countNodes(Block block, FSNamesystem namesystem) {
BlockManager blockManager = namesystem.getBlockManager();
- namesystem.readLock();
+ namesystem.readLock(FSNamesystemLockMode.BM);
try {
lastBlock = block;
lastNum = blockManager.countNodes(blockManager.getStoredBlock(block));
return lastNum;
}
finally {
- namesystem.readUnlock();
+ namesystem.readUnlock(FSNamesystemLockMode.BM, "countNodes");
}
}
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestOverReplicatedBlocks.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestOverReplicatedBlocks.java
index d5f2fb99b782..d964f4269869 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestOverReplicatedBlocks.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestOverReplicatedBlocks.java
@@ -39,6 +39,7 @@ import org.apache.hadoop.hdfs.server.datanode.DataNode;
import org.apache.hadoop.hdfs.server.datanode.InternalDataNodeTestUtils;
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration;
import org.junit.Test;
@@ -95,7 +96,7 @@ public class TestOverReplicatedBlocks {
final BlockManager bm = namesystem.getBlockManager();
final HeartbeatManager hm = bm.getDatanodeManager().getHeartbeatManager();
try {
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.GLOBAL);
synchronized(hm) {
// set live datanode's remaining space to be 0
// so they will be chosen to be deleted when over-replication occurs
@@ -118,7 +119,7 @@ public class TestOverReplicatedBlocks {
bm.getStoredBlock(block.getLocalBlock())).liveReplicas());
}
} finally {
- namesystem.writeUnlock();
+ namesystem.writeUnlock(FSNamesystemLockMode.GLOBAL, "testProcesOverReplicateBlock");
}
} finally {
@@ -181,11 +182,11 @@ public class TestOverReplicatedBlocks {
// All replicas for deletion should be scheduled on lastDN.
// And should not actually be deleted, because lastDN does not heartbeat.
- namesystem.readLock();
+ namesystem.readLock(FSNamesystemLockMode.BM);
final int dnBlocks = bm.getExcessSize4Testing(dnReg.getDatanodeUuid());
assertEquals("Replicas on node " + lastDNid + " should have been deleted",
SMALL_FILE_LENGTH / SMALL_BLOCK_SIZE, dnBlocks);
- namesystem.readUnlock();
+ namesystem.readUnlock(FSNamesystemLockMode.BM, "excessSize4Testing");
for(BlockLocation location : locs)
assertEquals("Block should still have 4 replicas",
4, location.getNames().length);
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestPendingReconstruction.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestPendingReconstruction.java
index ea7347f9e505..d5de79f67d35 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestPendingReconstruction.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestPendingReconstruction.java
@@ -51,6 +51,7 @@ import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
import org.apache.hadoop.hdfs.server.namenode.INodeFile;
import org.apache.hadoop.hdfs.server.namenode.NameNode;
import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration;
import org.apache.hadoop.hdfs.server.protocol.DatanodeStorage;
import org.apache.hadoop.hdfs.server.protocol.ReceivedDeletedBlockInfo;
@@ -288,13 +289,13 @@ public class TestPendingReconstruction {
// A received IBR processing calls addBlock(). If the gen stamp in the
// report is not the same, it should stay in pending.
- fsn.writeLock();
+ fsn.writeLock(FSNamesystemLockMode.BM);
try {
// Use a wrong gen stamp.
blkManager.addBlock(desc[0].getStorageInfos()[0],
new Block(1, 1, 0), null);
} finally {
- fsn.writeUnlock();
+ fsn.writeUnlock(FSNamesystemLockMode.BM, "testProcessPendingReconstructions");
}
// The block should still be pending
@@ -303,12 +304,12 @@ public class TestPendingReconstruction {
// A block report with the correct gen stamp should remove the record
// from the pending queue.
- fsn.writeLock();
+ fsn.writeLock(FSNamesystemLockMode.BM);
try {
blkManager.addBlock(desc[0].getStorageInfos()[0],
new Block(1, 1, 1), null);
} finally {
- fsn.writeUnlock();
+ fsn.writeUnlock(FSNamesystemLockMode.BM, "testProcessPendingReconstructions");
}
GenericTestUtils.waitFor(() -> pendingReconstruction.size() == 0, 500,
@@ -459,7 +460,7 @@ public class TestPendingReconstruction {
// 3. mark a couple of blocks as corrupt
LocatedBlock block = NameNodeAdapter.getBlockLocations(
cluster.getNameNode(), filePath.toString(), 0, 1).get(0);
- cluster.getNamesystem().writeLock();
+ cluster.getNamesystem().writeLock(FSNamesystemLockMode.BM);
try {
bm.findAndMarkBlockAsCorrupt(block.getBlock(), block.getLocations()[0],
"STORAGE_ID", "TEST");
@@ -471,7 +472,7 @@ public class TestPendingReconstruction {
BlockInfo storedBlock = bm.getStoredBlock(block.getBlock().getLocalBlock());
assertEquals(bm.pendingReconstruction.getNumReplicas(storedBlock), 2);
} finally {
- cluster.getNamesystem().writeUnlock();
+ cluster.getNamesystem().writeUnlock(FSNamesystemLockMode.BM, "testPendingAndInvalidate");
}
// 4. delete the file
@@ -507,7 +508,7 @@ public class TestPendingReconstruction {
DATANODE_COUNT).build();
tmpCluster.waitActive();
FSNamesystem fsn = tmpCluster.getNamesystem(0);
- fsn.writeLock();
+ fsn.writeLock(FSNamesystemLockMode.BM);
try {
BlockManager bm = fsn.getBlockManager();
@@ -563,7 +564,7 @@ public class TestPendingReconstruction {
}, 100, 60000);
} finally {
tmpCluster.shutdown();
- fsn.writeUnlock();
+ fsn.writeUnlock(FSNamesystemLockMode.BM, "testReplicationCounter");
}
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReconstructStripedBlocksWithRackAwareness.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReconstructStripedBlocksWithRackAwareness.java
index 19b845007bf4..0d5c51420818 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReconstructStripedBlocksWithRackAwareness.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReconstructStripedBlocksWithRackAwareness.java
@@ -32,6 +32,7 @@ import org.apache.hadoop.hdfs.server.datanode.DataNode;
import org.apache.hadoop.hdfs.server.datanode.DataNodeTestUtils;
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
import org.apache.hadoop.hdfs.server.namenode.INodeFile;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.net.NetworkTopology;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.test.Whitebox;
@@ -196,11 +197,11 @@ public class TestReconstructStripedBlocksWithRackAwareness {
DataNodeTestUtils.setHeartbeatsDisabledForTests(dn, true);
}
- fsn.writeLock();
+ fsn.writeLock(FSNamesystemLockMode.BM);
try {
bm.processMisReplicatedBlocks();
} finally {
- fsn.writeUnlock();
+ fsn.writeUnlock(FSNamesystemLockMode.BM, "testReconstructForNotEnoughRacks");
}
// check if redundancy monitor correctly schedule the reconstruction work.
@@ -342,12 +343,13 @@ public class TestReconstructStripedBlocksWithRackAwareness {
final DatanodeAdminManager decomManager =
(DatanodeAdminManager) Whitebox.getInternalState(
dm, "datanodeAdminManager");
- cluster.getNamesystem().writeLock();
+ cluster.getNamesystem().writeLock(FSNamesystemLockMode.BM);
try {
dn9.stopDecommission();
decomManager.startDecommission(dn9);
} finally {
- cluster.getNamesystem().writeUnlock();
+ cluster.getNamesystem().writeUnlock(FSNamesystemLockMode.BM,
+ "testReconstructionWithDecommission");
}
// make sure the decommission finishes and the block in on 6 racks
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicyConsiderLoad.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicyConsiderLoad.java
index fef0b45f39cc..a182f21e16aa 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicyConsiderLoad.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicyConsiderLoad.java
@@ -31,6 +31,7 @@ import org.apache.hadoop.hdfs.DFSTestUtil;
import org.apache.hadoop.hdfs.TestBlockStoragePolicy;
import org.apache.hadoop.hdfs.server.namenode.NameNode;
import org.apache.hadoop.hdfs.DFSConfigKeys;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -72,7 +73,7 @@ public class TestReplicationPolicyConsiderLoad
*/
@Test
public void testChooseTargetWithDecomNodes() throws IOException {
- namenode.getNamesystem().writeLock();
+ namenode.getNamesystem().writeLock(FSNamesystemLockMode.BM);
try {
dnManager.getHeartbeatManager().updateHeartbeat(dataNodes[3],
BlockManagerTestUtil.getStorageReportsForDatanode(dataNodes[3]),
@@ -124,14 +125,15 @@ public class TestReplicationPolicyConsiderLoad
dataNodes[0].stopDecommission();
dataNodes[1].stopDecommission();
dataNodes[2].stopDecommission();
- namenode.getNamesystem().writeUnlock();
+ namenode.getNamesystem().writeUnlock(FSNamesystemLockMode.BM,
+ "testChooseTargetWithDecomNodes");
}
NameNode.LOG.info("Done working on it");
}
@Test
public void testConsiderLoadFactor() throws IOException {
- namenode.getNamesystem().writeLock();
+ namenode.getNamesystem().writeLock(FSNamesystemLockMode.BM);
try {
dnManager.getHeartbeatManager().updateHeartbeat(dataNodes[0],
BlockManagerTestUtil.getStorageReportsForDatanode(dataNodes[0]),
@@ -178,7 +180,7 @@ public class TestReplicationPolicyConsiderLoad
info.getDatanodeDescriptor().getXceiverCount() <= (load/6)*1.2);
}
} finally {
- namenode.getNamesystem().writeUnlock();
+ namenode.getNamesystem().writeUnlock(FSNamesystemLockMode.BM, "testConsiderLoadFactor");
}
}
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicyExcludeSlowNodes.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicyExcludeSlowNodes.java
index d1e856d23571..baeac8f5619c 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicyExcludeSlowNodes.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicyExcludeSlowNodes.java
@@ -22,6 +22,7 @@ import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.DFSTestUtil;
import org.apache.hadoop.hdfs.TestBlockStoragePolicy;
import org.apache.hadoop.hdfs.server.namenode.NameNode;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.protocol.OutlierMetrics;
import org.apache.hadoop.test.GenericTestUtils;
@@ -85,7 +86,7 @@ public class TestReplicationPolicyExcludeSlowNodes
*/
@Test
public void testChooseTargetExcludeSlowNodes() throws Exception {
- namenode.getNamesystem().writeLock();
+ namenode.getNamesystem().writeLock(FSNamesystemLockMode.BM);
try {
// add nodes
for (int i = 0; i < dataNodes.length; i++) {
@@ -135,14 +136,15 @@ public class TestReplicationPolicyExcludeSlowNodes
.getDatanodeUuid()));
}
} finally {
- namenode.getNamesystem().writeUnlock();
+ namenode.getNamesystem().writeUnlock(FSNamesystemLockMode.BM,
+ "testChooseTargetExcludeSlowNodes");
}
NameNode.LOG.info("Done working on it");
}
@Test
public void testSlowPeerTrackerEnabledClearSlowNodes() throws Exception {
- namenode.getNamesystem().writeLock();
+ namenode.getNamesystem().writeLock(FSNamesystemLockMode.BM);
try {
// add nodes
for (DatanodeDescriptor dataNode : dataNodes) {
@@ -172,7 +174,8 @@ public class TestReplicationPolicyExcludeSlowNodes
assertTrue(dnManager.isSlowPeerCollectorInitialized());
assertEquals(0, DatanodeManager.getSlowNodesUuidSet().size());
} finally {
- namenode.getNamesystem().writeUnlock();
+ namenode.getNamesystem().writeUnlock(FSNamesystemLockMode.BM,
+ "testSlowPeerTrackerEnabledClearSlowNodes");
}
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicyRatioConsiderLoadWithStorage.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicyRatioConsiderLoadWithStorage.java
index d06af0546990..31f154315a52 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicyRatioConsiderLoadWithStorage.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicyRatioConsiderLoadWithStorage.java
@@ -22,6 +22,7 @@ import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.DFSTestUtil;
import org.apache.hadoop.hdfs.TestBlockStoragePolicy;
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.protocol.DatanodeStorage;
import org.junit.Test;
@@ -91,7 +92,7 @@ public class TestReplicationPolicyRatioConsiderLoadWithStorage
*/
@Test
public void testChooseTargetWithRatioConsiderLoad() {
- namenode.getNamesystem().writeLock();
+ namenode.getNamesystem().writeLock(FSNamesystemLockMode.BM);
try {
// After heartbeat has been processed, the total load should be 200.
// And average load per node should be 40. The max load should be 2 * 40;
@@ -163,7 +164,8 @@ public class TestReplicationPolicyRatioConsiderLoadWithStorage
assertTrue(targetSet.contains(dataNodes[3]));
assertTrue(targetSet.contains(dataNodes[4]));
} finally {
- namenode.getNamesystem().writeUnlock();
+ namenode.getNamesystem().writeUnlock(FSNamesystemLockMode.BM,
+ "testChooseTargetWithRatioConsiderLoad");
}
}
}
\ No newline at end of file
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/NameNodeAdapter.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/NameNodeAdapter.java
index 3731c2d4cad7..82fe4064f916 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/NameNodeAdapter.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/NameNodeAdapter.java
@@ -20,6 +20,7 @@ package org.apache.hadoop.hdfs.server.namenode;
import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState;
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo;
import org.apache.hadoop.hdfs.server.blockmanagement.BlockManager;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.protocol.SlowDiskReports;
import static org.mockito.Mockito.doAnswer;
@@ -94,13 +95,13 @@ public class NameNodeAdapter {
// consistent with FSNamesystem#getFileInfo()
final String operationName = needBlockToken ? "open" : "getfileinfo";
FSPermissionChecker.setOperationType(operationName);
- namenode.getNamesystem().readLock();
+ namenode.getNamesystem().readLock(FSNamesystemLockMode.FS);
try {
return FSDirStatAndListingOp.getFileInfo(namenode.getNamesystem()
.getFSDirectory(), pc, src, resolveLink, needLocation,
needBlockToken);
} finally {
- namenode.getNamesystem().readUnlock();
+ namenode.getNamesystem().readUnlock(FSNamesystemLockMode.FS, "getFileInfo");
}
}
@@ -213,11 +214,11 @@ public class NameNodeAdapter {
*/
public static DatanodeDescriptor getDatanode(final FSNamesystem ns,
DatanodeID id) throws IOException {
- ns.readLock();
+ ns.readLock(FSNamesystemLockMode.BM);
try {
return ns.getBlockManager().getDatanodeManager().getDatanode(id);
} finally {
- ns.readUnlock();
+ ns.readUnlock(FSNamesystemLockMode.BM, "getDatanode");
}
}
@@ -241,7 +242,7 @@ public class NameNodeAdapter {
public static BlockInfo addBlockNoJournal(final FSNamesystem fsn,
final String src, final DatanodeStorageInfo[] targets)
throws IOException {
- fsn.writeLock();
+ fsn.writeLock(FSNamesystemLockMode.GLOBAL);
try {
INodeFile file = (INodeFile)fsn.getFSDirectory().getINode(src);
Block newBlock = fsn.createNewBlock(BlockType.CONTIGUOUS);
@@ -250,17 +251,17 @@ public class NameNodeAdapter {
fsn, src, inodesInPath, newBlock, targets, BlockType.CONTIGUOUS);
return file.getLastBlock();
} finally {
- fsn.writeUnlock();
+ fsn.writeUnlock(FSNamesystemLockMode.GLOBAL, "addBlockNoJournal");
}
}
public static void persistBlocks(final FSNamesystem fsn,
final String src, final INodeFile file) throws IOException {
- fsn.writeLock();
+ fsn.writeLock(FSNamesystemLockMode.FS);
try {
FSDirWriteFileOp.persistBlocks(fsn.getFSDirectory(), src, file, true);
} finally {
- fsn.writeUnlock();
+ fsn.writeUnlock(FSNamesystemLockMode.FS, "persistBlocks");
}
}
@@ -272,8 +273,8 @@ public class NameNodeAdapter {
public static FSNamesystem spyOnNamesystem(NameNode nn) {
FSNamesystem fsnSpy = Mockito.spy(nn.getNamesystem());
FSNamesystem fsnOld = nn.namesystem;
- fsnOld.writeLock();
- fsnSpy.writeLock();
+ fsnOld.writeLock(FSNamesystemLockMode.GLOBAL);
+ fsnSpy.writeLock(FSNamesystemLockMode.GLOBAL);
nn.namesystem = fsnSpy;
try {
FieldUtils.writeDeclaredField(
@@ -291,8 +292,8 @@ public class NameNodeAdapter {
} catch (IllegalAccessException e) {
throw new RuntimeException("Cannot set spy FSNamesystem", e);
} finally {
- fsnSpy.writeUnlock();
- fsnOld.writeUnlock();
+ fsnSpy.writeUnlock(FSNamesystemLockMode.GLOBAL, "spyOnNamesystem");
+ fsnOld.writeUnlock(FSNamesystemLockMode.GLOBAL, "spyOnNamesystem");
}
return fsnSpy;
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAddBlockRetry.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAddBlockRetry.java
index 1a763b5bae3b..dd944d08b943 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAddBlockRetry.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAddBlockRetry.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.EnumSet;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hadoop.conf.Configuration;
@@ -34,6 +35,7 @@ import org.apache.hadoop.hdfs.protocol.HdfsConstants;
import org.apache.hadoop.hdfs.protocol.LocatedBlock;
import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeStorageInfo;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols;
import org.apache.hadoop.io.EnumSetWritable;
import org.junit.After;
@@ -91,7 +93,7 @@ public class TestAddBlockRetry {
// start first addBlock()
LOG.info("Starting first addBlock for " + src);
LocatedBlock[] onRetryBlock = new LocatedBlock[1];
- ns.readLock();
+ ns.readLock(FSNamesystemLockMode.GLOBAL);
FSDirWriteFileOp.ValidateAddBlockResult r;
FSPermissionChecker pc = Mockito.mock(FSPermissionChecker.class);
try {
@@ -99,7 +101,7 @@ public class TestAddBlockRetry {
HdfsConstants.GRANDFATHER_INODE_ID,
"clientName", null, onRetryBlock);
} finally {
- ns.readUnlock();
+ ns.readUnlock(FSNamesystemLockMode.GLOBAL, "validateAddBlock");
}
DatanodeStorageInfo targets[] = FSDirWriteFileOp.chooseTargetForNewBlock(
ns.getBlockManager(), src, null, null, null, r);
@@ -117,13 +119,13 @@ public class TestAddBlockRetry {
assertEquals("Wrong replication", REPLICATION, lb2.getLocations().length);
// continue first addBlock()
- ns.writeLock();
+ ns.writeLock(FSNamesystemLockMode.GLOBAL);
LocatedBlock newBlock;
try {
newBlock = FSDirWriteFileOp.storeAllocatedBlock(ns, src,
HdfsConstants.GRANDFATHER_INODE_ID, "clientName", null, targets);
} finally {
- ns.writeUnlock();
+ ns.writeUnlock(FSNamesystemLockMode.GLOBAL, "testRetryAddBlockWhileInChooseTarget");
}
assertEquals("Blocks are not equal", lb2.getBlock(), newBlock.getBlock());
@@ -137,11 +139,11 @@ public class TestAddBlockRetry {
boolean checkFileProgress(String src, boolean checkall) throws IOException {
final FSNamesystem ns = cluster.getNamesystem();
- ns.readLock();
+ ns.readLock(FSNamesystemLockMode.GLOBAL);
try {
return ns.checkFileProgress(src, ns.dir.getINode(src).asFile(), checkall);
} finally {
- ns.readUnlock();
+ ns.readUnlock(FSNamesystemLockMode.GLOBAL, "checkFileProgress");
}
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAddOverReplicatedStripedBlocks.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAddOverReplicatedStripedBlocks.java
index aad8e9b96a01..336409c4b505 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAddOverReplicatedStripedBlocks.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAddOverReplicatedStripedBlocks.java
@@ -33,6 +33,7 @@ import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfoStriped;
import org.apache.hadoop.hdfs.server.blockmanagement.BlockManager;
import org.apache.hadoop.hdfs.server.datanode.DataNode;
import org.apache.hadoop.hdfs.server.datanode.SimulatedFSDataset;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@@ -204,12 +205,13 @@ public class TestAddOverReplicatedStripedBlocks {
BlockManager bm = cluster.getNamesystem().getBlockManager();
List<DatanodeInfo> infos = Arrays.asList(bg.getLocations());
List<String> storages = Arrays.asList(bg.getStorageIDs());
- cluster.getNamesystem().writeLock();
+ cluster.getNamesystem().writeLock(FSNamesystemLockMode.BM);
try {
bm.findAndMarkBlockAsCorrupt(lbs.getLastLocatedBlock().getBlock(),
infos.get(0), storages.get(0), "TEST");
} finally {
- cluster.getNamesystem().writeUnlock();
+ cluster.getNamesystem().writeUnlock(FSNamesystemLockMode.BM,
+ "testProcessOverReplicatedAndCorruptStripedBlock");
}
assertEquals(1, bm.countNodes(bm.getStoredBlock(blockInfo))
.corruptReplicas());
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestBlockPlacementPolicyRackFaultTolerant.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestBlockPlacementPolicyRackFaultTolerant.java
index 3beea47800d7..60024ca64a44 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestBlockPlacementPolicyRackFaultTolerant.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestBlockPlacementPolicyRackFaultTolerant.java
@@ -37,6 +37,7 @@ import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor;
import org.apache.hadoop.hdfs.server.blockmanagement.BlockManager;
import org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementStatus;
import org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicyRackFaultTolerant;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols;
import org.apache.hadoop.net.StaticMapping;
import org.apache.hadoop.test.GenericTestUtils;
@@ -253,11 +254,12 @@ public class TestBlockPlacementPolicyRackFaultTolerant {
//test if decommission succeeded
DatanodeDescriptor dnd3 = dnm.getDatanode(cluster.getDataNodes().get(3).getDatanodeId());
- cluster.getNamesystem().writeLock();
+ cluster.getNamesystem().writeLock(FSNamesystemLockMode.BM);
try {
dm.getDatanodeAdminManager().startDecommission(dnd3);
} finally {
- cluster.getNamesystem().writeUnlock();
+ cluster.getNamesystem().writeUnlock(FSNamesystemLockMode.BM,
+ "testPlacementWithOnlyOneNodeInRackDecommission");
}
// make sure the decommission finishes and the block in on 4 racks
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCacheDirectives.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCacheDirectives.java
index 1331c50e80b3..73937c7470cd 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCacheDirectives.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCacheDirectives.java
@@ -43,6 +43,7 @@ import java.util.LinkedList;
import java.util.List;
import org.apache.commons.lang3.time.DateUtils;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.namenode.ha.HATestUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -761,7 +762,7 @@ public class TestCacheDirectives {
@Override
public Boolean get() {
int numCachedBlocks = 0, numCachedReplicas = 0;
- namesystem.readLock();
+ namesystem.readLock(FSNamesystemLockMode.BM);
try {
GSet<CachedBlock, CachedBlock> cachedBlocks =
cacheManager.getCachedBlocks();
@@ -774,7 +775,7 @@ public class TestCacheDirectives {
}
}
} finally {
- namesystem.readUnlock();
+ namesystem.readUnlock(FSNamesystemLockMode.BM, "checkBlocks");
}
LOG.info(logString + " cached blocks: have " + numCachedBlocks +
@@ -1505,7 +1506,7 @@ public class TestCacheDirectives {
private void checkPendingCachedEmpty(MiniDFSCluster cluster)
throws Exception {
Thread.sleep(1000);
- cluster.getNamesystem().readLock();
+ cluster.getNamesystem().readLock(FSNamesystemLockMode.BM);
try {
final DatanodeManager datanodeManager =
cluster.getNamesystem().getBlockManager().getDatanodeManager();
@@ -1518,7 +1519,7 @@ public class TestCacheDirectives {
descriptor.getPendingCached().isEmpty());
}
} finally {
- cluster.getNamesystem().readUnlock();
+ cluster.getNamesystem().readUnlock(FSNamesystemLockMode.BM, "checkPendingCachedEmpty");
}
}
@@ -1665,9 +1666,9 @@ public class TestCacheDirectives {
HATestUtil.waitForStandbyToCatchUp(ann, sbn);
GenericTestUtils.waitFor(() -> {
boolean isConsistence = false;
- ann.getNamesystem().readLock();
+ ann.getNamesystem().readLock(FSNamesystemLockMode.FS);
try {
- sbn.getNamesystem().readLock();
+ sbn.getNamesystem().readLock(FSNamesystemLockMode.FS);
try {
Iterator<CacheDirective> annDirectivesIt = annCachemanager.
getCacheDirectives().iterator();
@@ -1682,10 +1683,10 @@ public class TestCacheDirectives {
}
}
} finally {
- sbn.getNamesystem().readUnlock();
+ sbn.getNamesystem().readUnlock(FSNamesystemLockMode.FS, "expiryTimeConsistency");
}
} finally {
- ann.getNamesystem().readUnlock();
+ ann.getNamesystem().readUnlock(FSNamesystemLockMode.FS, "expiryTimeConsistency");
}
if (!isConsistence) {
LOG.info("testEexpiryTimeConsistency:"
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestDeleteRace.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestDeleteRace.java
index 9d32528bf25b..cf16672d61ce 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestDeleteRace.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestDeleteRace.java
@@ -52,6 +52,7 @@ import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor;
import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeStorageInfo;
import org.apache.hadoop.hdfs.server.datanode.DataNode;
import org.apache.hadoop.hdfs.server.datanode.InternalDataNodeTestUtils;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.namenode.snapshot.SnapshotTestHelper;
import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.net.Node;
@@ -471,7 +472,7 @@ public class TestDeleteRace {
} catch (InterruptedException e) {
}
});
- fsn.writeLock();
+ fsn.writeLock(FSNamesystemLockMode.GLOBAL);
open.start();
openSem.acquire();
Thread.yield();
@@ -479,7 +480,7 @@ public class TestDeleteRace {
rename.start();
renameSem.acquire();
Thread.yield();
- fsn.writeUnlock();
+ fsn.writeUnlock(FSNamesystemLockMode.GLOBAL, "testOpenRenameRace");
// wait open and rename threads finish.
open.join();
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestDiskspaceQuotaUpdate.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestDiskspaceQuotaUpdate.java
index 0cf696f504b9..febcafa89548 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestDiskspaceQuotaUpdate.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestDiskspaceQuotaUpdate.java
@@ -45,6 +45,7 @@ import org.apache.hadoop.hdfs.protocol.DSQuotaExceededException;
import org.apache.hadoop.hdfs.protocol.HdfsConstants;
import org.apache.hadoop.hdfs.protocol.QuotaByStorageTypeExceededException;
import org.apache.hadoop.hdfs.server.datanode.InternalDataNodeTestUtils;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot;
import org.apache.hadoop.ipc.RemoteException;
import org.apache.hadoop.hdfs.protocolPB.DatanodeProtocolClientSideTranslatorPB;
@@ -392,11 +393,11 @@ public class TestDiskspaceQuotaUpdate {
private void updateCountForQuota(int i) {
FSNamesystem fsn = cluster.getNamesystem();
- fsn.writeLock();
+ fsn.writeLock(FSNamesystemLockMode.FS);
try {
getFSDirectory().updateCountForQuota(i);
} finally {
- fsn.writeUnlock();
+ fsn.writeUnlock(FSNamesystemLockMode.FS, "updateCountForQuota");
}
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestEditLogRace.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestEditLogRace.java
index 9dc2cc9182bb..936bec677161 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestEditLogRace.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestEditLogRace.java
@@ -41,6 +41,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hadoop.conf.Configuration;
@@ -55,6 +56,7 @@ import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction;
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NamenodeRole;
import org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.OpInstanceCache;
import org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.SetOwnerOp;
import org.apache.hadoop.hdfs.server.namenode.JournalSet.JournalAndStream;
@@ -523,11 +525,11 @@ public class TestEditLogRace {
public void run() {
try {
LOG.info("Starting setOwner");
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.FS);
try {
editLog.logSetOwner("/","test","test");
} finally {
- namesystem.writeUnlock();
+ namesystem.writeUnlock(FSNamesystemLockMode.FS, "testSaveRightBeforeSync");
}
sleepingBeforeSync.countDown();
LOG.info("edit thread: sleeping for " + BLOCK_TIME + "secs");
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImageWithSnapshot.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImageWithSnapshot.java
index 1c1bb61721a7..12d5843e0025 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImageWithSnapshot.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImageWithSnapshot.java
@@ -31,6 +31,7 @@ import org.apache.hadoop.hdfs.client.HdfsDataOutputStream;
import org.apache.hadoop.hdfs.client.HdfsDataOutputStream.SyncFlag;
import org.apache.hadoop.hdfs.protocol.SnapshottableDirectoryStatus;
import org.apache.hadoop.hdfs.server.namenode.NNStorage.NameNodeFile;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.namenode.snapshot.DiffList;
import org.apache.hadoop.hdfs.server.namenode.snapshot.DirectoryWithSnapshotFeature.DirectoryDiff;
import org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot;
@@ -147,11 +148,11 @@ public class TestFSImageWithSnapshot {
conf);
FSImageCompression compression = FSImageCompression.createCompression(conf);
File imageFile = getImageFile(testDir, txid);
- fsn.readLock();
+ fsn.readLock(FSNamesystemLockMode.GLOBAL);
try {
saver.save(imageFile, compression);
} finally {
- fsn.readUnlock();
+ fsn.readUnlock(FSNamesystemLockMode.GLOBAL, "saveFSImage");
}
return imageFile;
}
@@ -159,14 +160,14 @@ public class TestFSImageWithSnapshot {
/** Load the fsimage from a temp file */
private void loadFSImageFromTempFile(File imageFile) throws IOException {
FSImageFormat.LoaderDelegator loader = FSImageFormat.newLoader(conf, fsn);
- fsn.writeLock();
+ fsn.writeLock(FSNamesystemLockMode.GLOBAL);
fsn.getFSDirectory().writeLock();
try {
loader.load(imageFile, false);
fsn.getFSDirectory().updateCountForQuota();
} finally {
fsn.getFSDirectory().writeUnlock();
- fsn.writeUnlock();
+ fsn.writeUnlock(FSNamesystemLockMode.GLOBAL, "loadFSImageFromTempFile");
}
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystem.java
index f2f42440240c..defbf36e5e10 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystem.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystem.java
@@ -41,6 +41,7 @@ import org.apache.hadoop.hdfs.HdfsConfiguration;
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.hdfs.server.blockmanagement.BlockManager;
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NamenodeRole;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.namenode.ha.HAContext;
import org.apache.hadoop.hdfs.server.namenode.ha.HAState;
import org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot;
@@ -194,12 +195,12 @@ public class TestFSNamesystem {
}
private void clearNamesystem(FSNamesystem fsn) {
- fsn.writeLock();
+ fsn.writeLock(FSNamesystemLockMode.GLOBAL);
try {
fsn.clear();
assertFalse(fsn.isImageLoaded());
} finally {
- fsn.writeUnlock();
+ fsn.writeUnlock(FSNamesystemLockMode.GLOBAL, "clearNamesystem");
}
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystemMBean.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystemMBean.java
index 2353dd975a70..a3005ec291c6 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystemMBean.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystemMBean.java
@@ -37,6 +37,7 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.DFSTestUtil;
import org.apache.hadoop.hdfs.DistributedFileSystem;
import org.apache.hadoop.hdfs.MiniDFSCluster;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.metrics2.impl.ConfigBuilder;
import org.apache.hadoop.metrics2.impl.TestMetricsConfig;
import org.apache.hadoop.test.GenericTestUtils;
@@ -153,7 +154,7 @@ public class TestFSNamesystemMBean {
cluster.waitActive();
fsn = cluster.getNameNode().namesystem;
- fsn.writeLock();
+ fsn.writeLock(FSNamesystemLockMode.GLOBAL);
Thread.sleep(jmxCachePeriod * 1000);
MBeanClient client = new MBeanClient();
@@ -163,8 +164,8 @@ public class TestFSNamesystemMBean {
"is owned by another thread", client.succeeded);
client.interrupt();
} finally {
- if (fsn != null && fsn.hasWriteLock()) {
- fsn.writeUnlock();
+ if (fsn != null && fsn.hasWriteLock(FSNamesystemLockMode.GLOBAL)) {
+ fsn.writeUnlock(FSNamesystemLockMode.GLOBAL, "testWithFSNamesystemWriteLock");
}
if (cluster != null) {
cluster.shutdown();
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFileTruncate.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFileTruncate.java
index b96f218ceb20..9abb28da7bac 100755
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFileTruncate.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFileTruncate.java
@@ -36,6 +36,7 @@ import java.util.concurrent.ThreadLocalRandom;
import org.apache.hadoop.fs.CommonPathCapabilities;
import org.apache.hadoop.hdfs.server.blockmanagement.BlockManagerTestUtil;
import org.apache.hadoop.hdfs.server.datanode.DataNodeFaultInjector;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.ipc.RemoteException;
import org.apache.hadoop.test.LambdaTestUtils;
import org.slf4j.Logger;
@@ -1083,7 +1084,7 @@ public class TestFileTruncate {
INodeFile file = iip.getLastINode().asFile();
long initialGenStamp = file.getLastBlock().getGenerationStamp();
// Test that prepareFileForTruncate sets up in-place truncate.
- fsn.writeLock();
+ fsn.writeLock(FSNamesystemLockMode.GLOBAL);
try {
Block oldBlock = file.getLastBlock();
Block truncateBlock = FSDirTruncateOp.prepareFileForTruncate(fsn, iip,
@@ -1103,7 +1104,7 @@ public class TestFileTruncate {
fsn.getEditLog().logTruncate(
src, client, clientMachine, BLOCK_SIZE-1, Time.now(), truncateBlock);
} finally {
- fsn.writeUnlock();
+ fsn.writeUnlock(FSNamesystemLockMode.GLOBAL, "testTruncateRecovery");
}
// Re-create file and ensure we are ready to copy on truncate
@@ -1117,7 +1118,7 @@ public class TestFileTruncate {
(BlockInfoContiguous) file.getLastBlock()), is(true));
initialGenStamp = file.getLastBlock().getGenerationStamp();
// Test that prepareFileForTruncate sets up copy-on-write truncate
- fsn.writeLock();
+ fsn.writeLock(FSNamesystemLockMode.GLOBAL);
try {
Block oldBlock = file.getLastBlock();
Block truncateBlock = FSDirTruncateOp.prepareFileForTruncate(fsn, iip,
@@ -1137,7 +1138,7 @@ public class TestFileTruncate {
fsn.getEditLog().logTruncate(
src, client, clientMachine, BLOCK_SIZE-1, Time.now(), truncateBlock);
} finally {
- fsn.writeUnlock();
+ fsn.writeUnlock(FSNamesystemLockMode.GLOBAL, "testTruncateRecovery");
}
checkBlockRecovery(srcPath);
fs.deleteSnapshot(parent, "ss0");
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFsck.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFsck.java
index 892c5ce020a4..b59d7545d085 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFsck.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFsck.java
@@ -105,6 +105,7 @@ import org.apache.hadoop.hdfs.server.namenode.NamenodeFsck.Result;
import org.apache.hadoop.hdfs.server.namenode.NamenodeFsck.ReplicationResult;
import org.apache.hadoop.hdfs.server.namenode.FSDirectory.DirOp;
import org.apache.hadoop.hdfs.server.namenode.NamenodeFsck.ErasureCodingResult;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.namenode.ha.HATestUtil;
import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols;
import org.apache.hadoop.hdfs.tools.DFSck;
@@ -1511,11 +1512,11 @@ public class TestFsck {
ExtendedBlock eb = util.getFirstBlock(dfs, path);
BlockCollection bc = null;
try {
- fsn.writeLock();
+ fsn.writeLock(FSNamesystemLockMode.GLOBAL);
BlockInfo bi = bm.getStoredBlock(eb.getLocalBlock());
bc = fsn.getBlockCollection(bi);
} finally {
- fsn.writeUnlock();
+ fsn.writeUnlock(FSNamesystemLockMode.GLOBAL, "testBlockIdCKDecommission");
}
DatanodeDescriptor dn = bc.getBlocks()[0].getDatanode(0);
bm.getDatanodeManager().getDatanodeAdminManager().startDecommission(dn);
@@ -1953,11 +1954,11 @@ public class TestFsck {
ExtendedBlock eb = util.getFirstBlock(dfs, path);
BlockCollection bc = null;
try {
- fsn.writeLock();
+ fsn.writeLock(FSNamesystemLockMode.GLOBAL);
BlockInfo bi = bm.getStoredBlock(eb.getLocalBlock());
bc = fsn.getBlockCollection(bi);
} finally {
- fsn.writeUnlock();
+ fsn.writeUnlock(FSNamesystemLockMode.GLOBAL, "testFsckWithDecommissionedReplicas");
}
DatanodeDescriptor dn = bc.getBlocks()[0]
.getDatanode(0);
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestGetBlockLocations.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestGetBlockLocations.java
index 1975549415e5..fe5e88e32565 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestGetBlockLocations.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestGetBlockLocations.java
@@ -23,6 +23,7 @@ import org.apache.hadoop.fs.permission.PermissionStatus;
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo;
import org.apache.hadoop.hdfs.server.namenode.FSDirectory.DirOp;
import org.apache.hadoop.hdfs.server.namenode.NameNode.OperationCategory;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@@ -72,14 +73,15 @@ public class TestGetBlockLocations {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
if(!deleted[0]) {
- fsn.writeLock();
+ fsn.writeLock(FSNamesystemLockMode.GLOBAL);
try {
INodesInPath iip = fsd.getINodesInPath(FILE_PATH, DirOp.READ);
FSDirDeleteOp.delete(fsd, iip, new INode.BlocksMapUpdateInfo(),
new ArrayList<INode>(), new ArrayList<Long>(),
now());
} finally {
- fsn.writeUnlock();
+ fsn.writeUnlock(FSNamesystemLockMode.GLOBAL,
+ "testGetBlockLocationsRacingWithDelete");
}
deleted[0] = true;
}
@@ -106,14 +108,14 @@ public class TestGetBlockLocations {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
if (!renamed[0]) {
- fsn.writeLock();
+ fsn.writeLock(FSNamesystemLockMode.FS);
try {
FSDirRenameOp.renameTo(fsd, fsd.getPermissionChecker(), FILE_PATH,
DST_PATH, new INode.BlocksMapUpdateInfo(),
false);
renamed[0] = true;
} finally {
- fsn.writeUnlock();
+ fsn.writeUnlock(FSNamesystemLockMode.FS, "testGetBlockLocationsRacingWithRename");
}
}
invocation.callRealMethod();
@@ -142,13 +144,13 @@ public class TestGetBlockLocations {
perm, 1, 1, new BlockInfo[] {}, (short) 1,
DFS_BLOCK_SIZE_DEFAULT);
- fsn.writeLock();
+ fsn.writeLock(FSNamesystemLockMode.FS);
try {
final FSDirectory fsd = fsn.getFSDirectory();
INodesInPath iip = fsd.getINodesInPath("/", DirOp.READ);
fsd.addINode(iip, file, null);
} finally {
- fsn.writeUnlock();
+ fsn.writeUnlock(FSNamesystemLockMode.FS, "setupFileSystem");
}
return fsn;
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestLargeDirectoryDelete.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestLargeDirectoryDelete.java
index 42f054006c9a..06cdc8c46361 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestLargeDirectoryDelete.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestLargeDirectoryDelete.java
@@ -21,6 +21,7 @@ import java.io.IOException;
import java.util.Random;
import org.apache.hadoop.hdfs.server.blockmanagement.BlockManagerTestUtil;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hadoop.conf.Configuration;
@@ -120,11 +121,11 @@ public class TestLargeDirectoryDelete {
try {
int blockcount = getBlockCount();
if (blockcount < TOTAL_BLOCKS && blockcount > 0) {
- mc.getNamesystem().writeLock();
+ mc.getNamesystem().writeLock(FSNamesystemLockMode.GLOBAL);
try {
lockOps++;
} finally {
- mc.getNamesystem().writeUnlock();
+ mc.getNamesystem().writeUnlock(FSNamesystemLockMode.GLOBAL, "runThreads");
}
Thread.sleep(1);
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestListOpenFiles.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestListOpenFiles.java
index c60a1369bd98..9a5a9a9e76ba 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestListOpenFiles.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestListOpenFiles.java
@@ -47,6 +47,7 @@ import org.apache.hadoop.hdfs.protocol.ClientProtocol;
import org.apache.hadoop.hdfs.protocol.OpenFileEntry;
import org.apache.hadoop.hdfs.protocol.OpenFilesIterator;
import org.apache.hadoop.hdfs.protocol.OpenFilesIterator.OpenFilesType;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.namenode.ha.HATestUtil;
import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols;
import org.apache.hadoop.hdfs.DFSConfigKeys;
@@ -338,7 +339,7 @@ public class TestListOpenFiles {
FSDirectory dir = fsNamesystem.getFSDirectory();
List<INode> removedINodes = new ChunkedArrayList<>();
removedINodes.add(dir.getINode(path));
- fsNamesystem.writeLock();
+ fsNamesystem.writeLock(FSNamesystemLockMode.FS);
try {
dir.removeFromInodeMap(removedINodes);
openFileEntryBatchedEntries = nnRpc
@@ -349,7 +350,7 @@ public class TestListOpenFiles {
} catch (NullPointerException e) {
Assert.fail("Should not throw NPE when the file is deleted but has lease!");
} finally {
- fsNamesystem.writeUnlock();
+ fsNamesystem.writeUnlock(FSNamesystemLockMode.FS, "testListOpenFilesWithDeletedPath");
}
}
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMetadataConsistency.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMetadataConsistency.java
index 3e80091307c0..dac99f40df8e 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMetadataConsistency.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMetadataConsistency.java
@@ -28,6 +28,7 @@ import org.apache.hadoop.hdfs.protocol.ExtendedBlock;
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo;
import org.apache.hadoop.hdfs.server.blockmanagement.BlockManagerTestUtil;
import org.apache.hadoop.hdfs.server.datanode.DataNodeTestUtils;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.test.GenericTestUtils;
import java.util.function.Supplier;
@@ -95,13 +96,14 @@ public class TestNameNodeMetadataConsistency {
// Simulate Namenode forgetting a Block
cluster.restartNameNode(true);
- cluster.getNameNode().getNamesystem().writeLock();
+ cluster.getNameNode().getNamesystem().writeLock(FSNamesystemLockMode.BM);
BlockInfo bInfo = cluster.getNameNode().getNamesystem().getBlockManager()
.getStoredBlock(block.getLocalBlock());
bInfo.delete();
cluster.getNameNode().getNamesystem().getBlockManager()
.removeBlock(bInfo);
- cluster.getNameNode().getNamesystem().writeUnlock();
+ cluster.getNameNode().getNamesystem().writeUnlock(FSNamesystemLockMode.BM,
+ "testGenerationStampInFuture");
// we also need to tell block manager that we are in the startup path
BlockManagerTestUtil.setStartupSafeModeForTest(
@@ -145,11 +147,12 @@ public class TestNameNodeMetadataConsistency {
cluster.restartNameNode(true);
BlockInfo bInfo = cluster.getNameNode().getNamesystem().getBlockManager
().getStoredBlock(block.getLocalBlock());
- cluster.getNameNode().getNamesystem().writeLock();
+ cluster.getNameNode().getNamesystem().writeLock(FSNamesystemLockMode.BM);
bInfo.delete();
cluster.getNameNode().getNamesystem().getBlockManager()
.removeBlock(bInfo);
- cluster.getNameNode().getNamesystem().writeUnlock();
+ cluster.getNameNode().getNamesystem().writeUnlock(FSNamesystemLockMode.BM,
+ "testEnsureGenStampsIsStartupOnly");
cluster.restartDataNode(dnProps);
waitForNumBytes(0);
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestReconstructStripedBlocks.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestReconstructStripedBlocks.java
index 67ab88ea7261..5cdfa2942f42 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestReconstructStripedBlocks.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestReconstructStripedBlocks.java
@@ -44,6 +44,7 @@ import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeStorageInfo;
import org.apache.hadoop.hdfs.server.blockmanagement.NumberReplicas;
import org.apache.hadoop.hdfs.server.datanode.DataNode;
import org.apache.hadoop.hdfs.server.datanode.DataNodeTestUtils;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.protocol.BlockECReconstructionCommand.BlockECReconstructionInfo;
import org.apache.hadoop.hdfs.util.StripedBlockUtil;
@@ -338,13 +339,13 @@ public class TestReconstructStripedBlocks {
boolean reconstructed = false;
for (int i = 0; i < 5; i++) {
NumberReplicas num = null;
- fsn.readLock();
+ fsn.readLock(FSNamesystemLockMode.GLOBAL);
try {
BlockInfo blockInfo = cluster.getNamesystem().getFSDirectory()
.getINode4Write(filePath.toString()).asFile().getLastBlock();
num = bm.countNodes(blockInfo);
} finally {
- fsn.readUnlock();
+ fsn.readUnlock(FSNamesystemLockMode.GLOBAL, "testCountLiveReplicas");
}
if (num.liveReplicas() >= groupSize) {
reconstructed = true;
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestSecurityTokenEditLog.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestSecurityTokenEditLog.java
index c43c909c98a1..e6eccbfb77e6 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestSecurityTokenEditLog.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestSecurityTokenEditLog.java
@@ -35,6 +35,7 @@ import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifie
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenSecretManager;
import org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory;
import org.apache.hadoop.hdfs.server.namenode.NNStorage.NameNodeDirType;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.security.token.Token;
@@ -196,8 +197,8 @@ public class TestSecurityTokenEditLog {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
// fsn claims read lock if either read or write locked.
- Assert.assertTrue(fsnRef.get().hasReadLock());
- Assert.assertFalse(fsnRef.get().hasWriteLock());
+ Assert.assertTrue(fsnRef.get().hasReadLock(FSNamesystemLockMode.FS));
+ Assert.assertFalse(fsnRef.get().hasWriteLock(FSNamesystemLockMode.FS));
return null;
}
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestDNFencing.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestDNFencing.java
index 9d79e496102d..f27864283f0c 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestDNFencing.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestDNFencing.java
@@ -52,6 +52,7 @@ import org.apache.hadoop.hdfs.server.datanode.DataNodeTestUtils;
import org.apache.hadoop.hdfs.server.datanode.InternalDataNodeTestUtils;
import org.apache.hadoop.hdfs.server.namenode.NameNode;
import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.test.GenericTestUtils.DelayAnswer;
@@ -568,13 +569,13 @@ public class TestDNFencing {
}
private void doMetasave(NameNode nn2) {
- nn2.getNamesystem().writeLock();
+ nn2.getNamesystem().writeLock(FSNamesystemLockMode.BM);
try {
PrintWriter pw = new PrintWriter(System.err);
nn2.getNamesystem().getBlockManager().metaSave(pw);
pw.flush();
} finally {
- nn2.getNamesystem().writeUnlock();
+ nn2.getNamesystem().writeUnlock(FSNamesystemLockMode.BM, "metaSave");
}
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/metrics/TestNameNodeMetrics.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/metrics/TestNameNodeMetrics.java
index 4d472d74b46a..510fa3cfe0d7 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/metrics/TestNameNodeMetrics.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/metrics/TestNameNodeMetrics.java
@@ -50,6 +50,7 @@ import java.util.List;
import java.util.Random;
import org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.ipc.metrics.RpcDetailedMetrics;
import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableList;
@@ -491,12 +492,12 @@ public class TestNameNodeMetrics {
// Corrupt first replica of the block
LocatedBlock block = NameNodeAdapter.getBlockLocations(
cluster.getNameNode(), file.toString(), 0, 1).get(0);
- cluster.getNamesystem().writeLock();
+ cluster.getNamesystem().writeLock(FSNamesystemLockMode.BM);
try {
bm.findAndMarkBlockAsCorrupt(block.getBlock(), block.getLocations()[0],
"STORAGE_ID", "TEST");
} finally {
- cluster.getNamesystem().writeUnlock();
+ cluster.getNamesystem().writeUnlock(FSNamesystemLockMode.BM, "testCorruptBlock");
}
BlockManagerTestUtil.updateState(bm);
@@ -583,12 +584,12 @@ public class TestNameNodeMetrics {
assert lbs.get(0) instanceof LocatedStripedBlock;
LocatedStripedBlock bg = (LocatedStripedBlock) (lbs.get(0));
- cluster.getNamesystem().writeLock();
+ cluster.getNamesystem().writeLock(FSNamesystemLockMode.BM);
try {
bm.findAndMarkBlockAsCorrupt(bg.getBlock(), bg.getLocations()[0],
"STORAGE_ID", "TEST");
} finally {
- cluster.getNamesystem().writeUnlock();
+ cluster.getNamesystem().writeUnlock(FSNamesystemLockMode.BM, "testStripedFileCorruptBlocks");
}
BlockManagerTestUtil.updateState(bm);
@@ -681,12 +682,12 @@ public class TestNameNodeMetrics {
// Corrupt the only replica of the block to result in a missing block
LocatedBlock block = NameNodeAdapter.getBlockLocations(
cluster.getNameNode(), file.toString(), 0, 1).get(0);
- cluster.getNamesystem().writeLock();
+ cluster.getNamesystem().writeLock(FSNamesystemLockMode.BM);
try {
bm.findAndMarkBlockAsCorrupt(block.getBlock(), block.getLocations()[0],
"STORAGE_ID", "TEST");
} finally {
- cluster.getNamesystem().writeUnlock();
+ cluster.getNamesystem().writeUnlock(FSNamesystemLockMode.BM, "testMissingBlock");
}
Thread.sleep(1000); // Wait for block to be marked corrupt
MetricsRecordBuilder rb = getMetrics(NS_METRICS);
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestINodeFileUnderConstructionWithSnapshot.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestINodeFileUnderConstructionWithSnapshot.java
index 4f32af9b9a43..e9ea5b6d9b9a 100755
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestINodeFileUnderConstructionWithSnapshot.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestINodeFileUnderConstructionWithSnapshot.java
@@ -46,6 +46,7 @@ import org.apache.hadoop.hdfs.server.namenode.INode;
import org.apache.hadoop.hdfs.server.namenode.INodeDirectory;
import org.apache.hadoop.hdfs.server.namenode.INodeFile;
import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.namenode.snapshot.DirectoryWithSnapshotFeature.DirectoryDiff;
import org.apache.hadoop.test.GenericTestUtils;
import org.slf4j.event.Level;
@@ -297,10 +298,10 @@ public class TestINodeFileUnderConstructionWithSnapshot {
hdfs.delete(foo, true);
Thread.sleep(1000);
try {
- fsn.writeLock();
+ fsn.writeLock(FSNamesystemLockMode.GLOBAL);
NameNodeAdapter.getLeaseManager(fsn).runLeaseChecks();
} finally {
- fsn.writeUnlock();
+ fsn.writeUnlock(FSNamesystemLockMode.GLOBAL, "testLease");
}
} finally {
NameNodeAdapter.setLeasePeriod(fsn, HdfsConstants.LEASE_SOFTLIMIT_PERIOD,
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdmin.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdmin.java
index 392866e86ea2..75e89f4f2aa5 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdmin.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdmin.java
@@ -81,6 +81,7 @@ import org.apache.hadoop.hdfs.server.common.Storage;
import org.apache.hadoop.hdfs.server.datanode.DataNode;
import org.apache.hadoop.hdfs.server.datanode.StorageLocation;
import org.apache.hadoop.hdfs.server.namenode.NameNode;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.ipc.RemoteException;
import org.apache.hadoop.security.AccessControlException;
@@ -783,14 +784,14 @@ public class TestDFSAdmin {
LocatedStripedBlock bg =
(LocatedStripedBlock)(lbs.get(0));
- miniCluster.getNamesystem().writeLock();
+ miniCluster.getNamesystem().writeLock(FSNamesystemLockMode.BM);
try {
BlockManager bm = miniCluster.getNamesystem().getBlockManager();
bm.findAndMarkBlockAsCorrupt(bg.getBlock(), bg.getLocations()[0],
"STORAGE_ID", "TEST");
BlockManagerTestUtil.updateState(bm);
} finally {
- miniCluster.getNamesystem().writeUnlock();
+ miniCluster.getNamesystem().writeUnlock(FSNamesystemLockMode.BM, "testReportCommand");
}
waitForCorruptBlock(miniCluster, client, file);
diff --git a/hadoop-tools/hadoop-fs2img/src/test/java/org/apache/hadoop/hdfs/server/namenode/ITestProvidedImplementation.java b/hadoop-tools/hadoop-fs2img/src/test/java/org/apache/hadoop/hdfs/server/namenode/ITestProvidedImplementation.java
index 361243fd6968..7056034f3f3d 100644
--- a/hadoop-tools/hadoop-fs2img/src/test/java/org/apache/hadoop/hdfs/server/namenode/ITestProvidedImplementation.java
+++ b/hadoop-tools/hadoop-fs2img/src/test/java/org/apache/hadoop/hdfs/server/namenode/ITestProvidedImplementation.java
@@ -84,6 +84,7 @@ import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY;
import org.apache.hadoop.hdfs.server.datanode.fsdataset.FsVolumeSpi;
import org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.FsVolumeImpl;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.namenode.ha.BootstrapStandby;
import org.apache.hadoop.hdfs.server.protocol.StorageReport;
import org.apache.hadoop.ipc.RemoteException;
@@ -1094,26 +1095,26 @@ public class ITestProvidedImplementation {
private void startDecommission(FSNamesystem namesystem, DatanodeManager dnm,
int dnIndex) throws Exception {
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.BM);
DatanodeDescriptor dnDesc = getDatanodeDescriptor(dnm, dnIndex);
dnm.getDatanodeAdminManager().startDecommission(dnDesc);
- namesystem.writeUnlock();
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "startDecommission");
}
private void startMaintenance(FSNamesystem namesystem, DatanodeManager dnm,
int dnIndex) throws Exception {
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.BM);
DatanodeDescriptor dnDesc = getDatanodeDescriptor(dnm, dnIndex);
dnm.getDatanodeAdminManager().startMaintenance(dnDesc, Long.MAX_VALUE);
- namesystem.writeUnlock();
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "startMaintenance");
}
private void stopMaintenance(FSNamesystem namesystem, DatanodeManager dnm,
int dnIndex) throws Exception {
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.GLOBAL);
DatanodeDescriptor dnDesc = getDatanodeDescriptor(dnm, dnIndex);
dnm.getDatanodeAdminManager().stopMaintenance(dnDesc);
- namesystem.writeUnlock();
+ namesystem.writeUnlock(FSNamesystemLockMode.GLOBAL, "stopMaintenance");
}
@Test
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org
(hadoop) 08/23: HDFS-17414. [FGL] RPCs in DatanodeProtocol support fine-grained lock (#6649)
Posted by za...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zanderxu pushed a commit to branch HDFS-17384
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit f64cb049ad0664534489882f4f6b0adc3c844bce
Author: ZanderXu <za...@apache.org>
AuthorDate: Sat Mar 23 21:27:34 2024 +0800
HDFS-17414. [FGL] RPCs in DatanodeProtocol support fine-grained lock (#6649)
---
.../hdfs/server/blockmanagement/BlockManager.java | 20 +++++++-------
.../server/blockmanagement/DatanodeManager.java | 7 ++---
.../server/blockmanagement/ProvidedStorageMap.java | 3 ++-
.../hdfs/server/namenode/FSDirWriteFileOp.java | 3 ++-
.../hadoop/hdfs/server/namenode/FSDirectory.java | 2 +-
.../hadoop/hdfs/server/namenode/FSNamesystem.java | 31 +++++++++++-----------
.../server/blockmanagement/TestBlockManager.java | 5 ++++
.../blockmanagement/TestDatanodeManager.java | 15 ++++++++++-
8 files changed, 54 insertions(+), 32 deletions(-)
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
index 8f65673806bd..da16204050af 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
@@ -97,6 +97,7 @@ import org.apache.hadoop.hdfs.server.namenode.INodeFile;
import org.apache.hadoop.hdfs.server.namenode.INodesInPath;
import org.apache.hadoop.hdfs.server.namenode.NameNode;
import org.apache.hadoop.hdfs.server.namenode.Namesystem;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.namenode.ha.HAContext;
import org.apache.hadoop.hdfs.server.namenode.metrics.NameNodeMetrics;
import org.apache.hadoop.hdfs.server.namenode.sps.StoragePolicySatisfyManager;
@@ -1895,7 +1896,7 @@ public class BlockManager implements BlockStatsMXBean {
*/
public void findAndMarkBlockAsCorrupt(final ExtendedBlock blk,
final DatanodeInfo dn, String storageID, String reason) throws IOException {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
final Block reportedBlock = blk.getLocalBlock();
final BlockInfo storedBlock = getStoredBlock(reportedBlock);
if (storedBlock == null) {
@@ -2708,7 +2709,7 @@ public class BlockManager implements BlockStatsMXBean {
}
public long requestBlockReportLeaseId(DatanodeRegistration nodeReg) {
- assert namesystem.hasReadLock();
+ assert namesystem.hasReadLock(FSNamesystemLockMode.BM);
DatanodeDescriptor node = null;
try {
node = datanodeManager.getDatanode(nodeReg);
@@ -2730,7 +2731,6 @@ public class BlockManager implements BlockStatsMXBean {
public void registerDatanode(DatanodeRegistration nodeReg)
throws IOException {
- assert namesystem.hasWriteLock();
datanodeManager.registerDatanode(nodeReg);
bmSafeMode.checkSafeMode();
}
@@ -2997,7 +2997,7 @@ public class BlockManager implements BlockStatsMXBean {
public void removeBRLeaseIfNeeded(final DatanodeID nodeID,
final BlockReportContext context) throws IOException {
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.BM);
DatanodeDescriptor node;
try {
node = datanodeManager.getDatanode(nodeID);
@@ -3015,7 +3015,7 @@ public class BlockManager implements BlockStatsMXBean {
}
}
} finally {
- namesystem.writeUnlock("removeBRLeaseIfNeeded");
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "removeBRLeaseIfNeeded");
}
}
@@ -3207,7 +3207,7 @@ public class BlockManager implements BlockStatsMXBean {
BlockInfo block,
long oldGenerationStamp, long oldNumBytes,
DatanodeStorageInfo[] newStorages) throws IOException {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
BlockToMarkCorrupt b = null;
if (block.getGenerationStamp() != oldGenerationStamp) {
b = new BlockToMarkCorrupt(oldBlock, block, oldGenerationStamp,
@@ -4426,7 +4426,7 @@ public class BlockManager implements BlockStatsMXBean {
*/
public void removeStoredBlock(BlockInfo storedBlock, DatanodeDescriptor node) {
blockLog.debug("BLOCK* removeStoredBlock: {} from {}", storedBlock, node);
- assert (namesystem.hasWriteLock());
+ assert (namesystem.hasWriteLock(FSNamesystemLockMode.BM));
{
if (storedBlock == null || !blocksMap.removeNode(storedBlock, node)) {
blockLog.debug("BLOCK* removeStoredBlock: {} has already been removed from node {}",
@@ -4941,7 +4941,7 @@ public class BlockManager implements BlockStatsMXBean {
}
public void removeBlock(BlockInfo block) {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
// No need to ACK blocks that are being removed entirely
// from the namespace, since the removal of the associated
// file already removes them from the block map below.
@@ -4984,7 +4984,7 @@ public class BlockManager implements BlockStatsMXBean {
/** updates a block in needed reconstruction queue. */
private void updateNeededReconstructions(final BlockInfo block,
final int curReplicasDelta, int expectedReplicasDelta) {
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.BM);
try {
if (!isPopulatingReplQueues() || !block.isComplete()) {
return;
@@ -5003,7 +5003,7 @@ public class BlockManager implements BlockStatsMXBean {
repl.outOfServiceReplicas(), oldExpectedReplicas);
}
} finally {
- namesystem.writeUnlock("updateNeededReconstructions");
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "updateNeededReconstructions");
}
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java
index b3eb2fd7f97e..dc22fe22c96e 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java
@@ -22,6 +22,7 @@ import static org.apache.hadoop.util.Time.monotonicNow;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.classification.VisibleForTesting;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.util.Preconditions;
import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableList;
@@ -855,7 +856,7 @@ public class DatanodeManager {
*/
private void removeDatanode(DatanodeDescriptor nodeInfo,
boolean removeBlocksFromBlocksMap) {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.BM);
heartbeatManager.removeDatanode(nodeInfo);
if (removeBlocksFromBlocksMap) {
blockManager.removeBlocksAssociatedTo(nodeInfo);
@@ -874,7 +875,7 @@ public class DatanodeManager {
*/
public void removeDatanode(final DatanodeID node)
throws UnregisteredNodeException {
- namesystem.writeLock();
+ namesystem.writeLock(FSNamesystemLockMode.BM);
try {
final DatanodeDescriptor descriptor = getDatanode(node);
if (descriptor != null) {
@@ -884,7 +885,7 @@ public class DatanodeManager {
+ node + " does not exist");
}
} finally {
- namesystem.writeUnlock("removeDatanode");
+ namesystem.writeUnlock(FSNamesystemLockMode.BM, "removeDatanode");
}
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/ProvidedStorageMap.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/ProvidedStorageMap.java
index 8d3e17a53528..4e4464b32599 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/ProvidedStorageMap.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/ProvidedStorageMap.java
@@ -45,6 +45,7 @@ import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
import org.apache.hadoop.hdfs.server.common.blockaliasmap.BlockAliasMap;
import org.apache.hadoop.hdfs.server.common.blockaliasmap.impl.TextFileRegionAliasMap;
import org.apache.hadoop.hdfs.server.common.BlockAlias;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.protocol.DatanodeStorage;
import org.apache.hadoop.hdfs.server.protocol.DatanodeStorage.State;
import org.apache.hadoop.hdfs.util.RwLock;
@@ -173,7 +174,7 @@ public class ProvidedStorageMap {
public void removeDatanode(DatanodeDescriptor dnToRemove) {
if (providedEnabled) {
- assert lock.hasWriteLock() : "Not holding write lock";
+ assert lock.hasWriteLock(FSNamesystemLockMode.BM) : "Not holding write lock";
providedDescriptor.remove(dnToRemove);
// if all datanodes fail, set the block report count to 0
if (providedDescriptor.activeProvidedDatanodes() == 0) {
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirWriteFileOp.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirWriteFileOp.java
index 339873efadc6..37000421abcb 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirWriteFileOp.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirWriteFileOp.java
@@ -17,6 +17,7 @@
*/
package org.apache.hadoop.hdfs.server.namenode;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.util.Preconditions;
import org.apache.hadoop.HadoopIllegalArgumentException;
import org.apache.hadoop.fs.XAttrSetFlag;
@@ -104,7 +105,7 @@ class FSDirWriteFileOp {
*/
static void persistBlocks(
FSDirectory fsd, String path, INodeFile file, boolean logRetryCache) {
- assert fsd.getFSNamesystem().hasWriteLock();
+ assert fsd.getFSNamesystem().hasWriteLock(FSNamesystemLockMode.FS);
Preconditions.checkArgument(file.isUnderConstruction());
fsd.getEditLog().logUpdateBlocks(path, file, logRetryCache);
if(NameNode.stateChangeLog.isDebugEnabled()) {
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java
index 5b846b56b3d8..2b92477b841c 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java
@@ -1106,7 +1106,7 @@ public class FSDirectory implements Closeable {
*/
public void updateSpaceForCompleteBlock(BlockInfo completeBlk,
INodesInPath inodes) throws IOException {
- assert namesystem.hasWriteLock();
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.GLOBAL);
INodesInPath iip = inodes != null ? inodes :
INodesInPath.fromINode(namesystem.getBlockCollection(completeBlk));
INodeFile fileINode = iip.getLastINode().asFile();
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
index e97444b7db25..a32252525178 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
@@ -1894,11 +1894,11 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
NamespaceInfo getNamespaceInfo() {
- readLock();
+ readLock(FSNamesystemLockMode.FS);
try {
return unprotectedGetNamespaceInfo();
} finally {
- readUnlock("getNamespaceInfo");
+ readUnlock(FSNamesystemLockMode.FS, "getNamespaceInfo");
}
}
@@ -3905,7 +3905,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
void commitOrCompleteLastBlock(
final INodeFile fileINode, final INodesInPath iip,
final Block commitBlock) throws IOException {
- assert hasWriteLock();
+ assert hasWriteLock(FSNamesystemLockMode.GLOBAL);
Preconditions.checkArgument(fileINode.isUnderConstruction());
blockManager.commitOrCompleteLastBlock(fileINode, commitBlock, iip);
}
@@ -3927,7 +3927,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
void finalizeINodeFileUnderConstruction(String src, INodeFile pendingFile,
int latestSnapshot, boolean allowCommittedBlock) throws IOException {
- assert hasWriteLock();
+ assert hasWriteLock(FSNamesystemLockMode.GLOBAL);
FileUnderConstructionFeature uc = pendingFile.getFileUnderConstructionFeature();
if (uc == null) {
@@ -3996,7 +3996,8 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
@Override
public INodeFile getBlockCollection(long id) {
- assert hasReadLock() : "Accessing INode id = " + id + " without read lock";
+ assert hasReadLock(FSNamesystemLockMode.FS)
+ : "Accessing INode id = " + id + " without read lock";
INode inode = getFSDirectory().getInode(id);
return inode == null ? null : inode.asFile();
}
@@ -4014,7 +4015,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
+ ")");
checkOperation(OperationCategory.WRITE);
final String src;
- writeLock();
+ writeLock(FSNamesystemLockMode.GLOBAL);
boolean copyTruncate = false;
BlockInfo truncatedBlock = null;
try {
@@ -4149,7 +4150,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
}
blockManager.successfulBlockRecovery(storedBlock);
} finally {
- writeUnlock("commitBlockSynchronization");
+ writeUnlock(FSNamesystemLockMode.GLOBAL, "commitBlockSynchronization");
}
getEditLog().logSync();
if (closeFile) {
@@ -4410,11 +4411,11 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
* @see org.apache.hadoop.hdfs.server.datanode.DataNode
*/
void registerDatanode(DatanodeRegistration nodeReg) throws IOException {
- writeLock();
+ writeLock(FSNamesystemLockMode.BM);
try {
blockManager.registerDatanode(nodeReg);
} finally {
- writeUnlock("registerDatanode");
+ writeUnlock(FSNamesystemLockMode.BM, "registerDatanode");
}
}
@@ -4447,7 +4448,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
@Nonnull SlowPeerReports slowPeers,
@Nonnull SlowDiskReports slowDisks)
throws IOException {
- readLock();
+ readLock(FSNamesystemLockMode.BM);
try {
//get datanode commands
DatanodeCommand[] cmds = blockManager.getDatanodeManager().handleHeartbeat(
@@ -4470,7 +4471,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
return new HeartbeatResponse(cmds, haState, rollingUpgradeInfo,
blockReportLeaseId, isSlownode);
} finally {
- readUnlock("handleHeartbeat");
+ readUnlock(FSNamesystemLockMode.BM, "handleHeartbeat");
}
}
@@ -4532,7 +4533,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
* @param file
*/
private void closeFile(String path, INodeFile file) {
- assert hasWriteLock();
+ assert hasWriteLock(FSNamesystemLockMode.FS);
// file is closed
getEditLog().logCloseFile(path, file);
NameNode.stateChangeLog.debug("closeFile: {} with {} blocks is persisted to the file system",
@@ -5877,7 +5878,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
}
boolean isFileDeleted(INodeFile file) {
- assert hasReadLock();
+ assert hasReadLock(FSNamesystemLockMode.FS);
// Not in the inodeMap or in the snapshot but marked deleted.
if (dir.getInode(file.getId()) == null) {
return true;
@@ -5955,7 +5956,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
*/
void reportBadBlocks(LocatedBlock[] blocks) throws IOException {
checkOperation(OperationCategory.WRITE);
- writeLock();
+ writeLock(FSNamesystemLockMode.BM);
try {
checkOperation(OperationCategory.WRITE);
for (int i = 0; i < blocks.length; i++) {
@@ -5971,7 +5972,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
}
}
} finally {
- writeUnlock("reportBadBlocks");
+ writeUnlock(FSNamesystemLockMode.BM, "reportBadBlocks");
}
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManager.java
index d9d236b66468..2ebf4a6cacc7 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManager.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManager.java
@@ -21,6 +21,7 @@ import org.apache.hadoop.fs.BlockLocation;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.hdfs.server.datanode.DataNodeFaultInjector;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.thirdparty.com.google.common.base.Joiner;
import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableList;
import org.apache.hadoop.thirdparty.com.google.common.collect.LinkedListMultimap;
@@ -166,6 +167,10 @@ public class TestBlockManager {
fsn = Mockito.mock(FSNamesystem.class);
Mockito.doReturn(true).when(fsn).hasWriteLock();
Mockito.doReturn(true).when(fsn).hasReadLock();
+ Mockito.doReturn(true).when(fsn).hasWriteLock(FSNamesystemLockMode.GLOBAL);
+ Mockito.doReturn(true).when(fsn).hasReadLock(FSNamesystemLockMode.GLOBAL);
+ Mockito.doReturn(true).when(fsn).hasWriteLock(FSNamesystemLockMode.BM);
+ Mockito.doReturn(true).when(fsn).hasReadLock(FSNamesystemLockMode.BM);
Mockito.doReturn(true).when(fsn).isRunning();
//Make shouldPopulaeReplQueues return true
HAContext haContext = Mockito.mock(HAContext.class);
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestDatanodeManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestDatanodeManager.java
index bcdba9577587..de89d4c8e253 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestDatanodeManager.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestDatanodeManager.java
@@ -36,6 +36,7 @@ import java.util.Map.Entry;
import java.util.Random;
import java.util.Set;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hadoop.conf.Configuration;
@@ -119,6 +120,7 @@ public class TestDatanodeManager {
//Create the DatanodeManager which will be tested
FSNamesystem fsn = Mockito.mock(FSNamesystem.class);
Mockito.when(fsn.hasWriteLock()).thenReturn(true);
+ Mockito.when(fsn.hasWriteLock(FSNamesystemLockMode.BM)).thenReturn(true);
Configuration conf = new Configuration();
conf.setLong(DFSConfigKeys.DFS_HEARTBEAT_INTERVAL_KEY, 0);
conf.setLong(DFSConfigKeys.DFS_NAMENODE_HEARTBEAT_RECHECK_INTERVAL_KEY, 10);
@@ -154,6 +156,7 @@ public class TestDatanodeManager {
//Create the DatanodeManager which will be tested
FSNamesystem fsn = Mockito.mock(FSNamesystem.class);
Mockito.when(fsn.hasWriteLock()).thenReturn(true);
+ Mockito.when(fsn.hasWriteLock(FSNamesystemLockMode.BM)).thenReturn(true);
Configuration conf = new Configuration();
DatanodeManager dm = mockDatanodeManager(fsn, conf);
@@ -184,6 +187,7 @@ public class TestDatanodeManager {
//Create the DatanodeManager which will be tested
FSNamesystem fsn = Mockito.mock(FSNamesystem.class);
Mockito.when(fsn.hasWriteLock()).thenReturn(true);
+ Mockito.when(fsn.hasWriteLock(FSNamesystemLockMode.BM)).thenReturn(true);
DatanodeManager dm = mockDatanodeManager(fsn, new Configuration());
//Seed the RNG with a known value so test failures are easier to reproduce
@@ -283,7 +287,8 @@ public class TestDatanodeManager {
//Create the DatanodeManager which will be tested
FSNamesystem fsn = Mockito.mock(FSNamesystem.class);
Mockito.when(fsn.hasWriteLock()).thenReturn(true);
-
+ Mockito.when(fsn.hasWriteLock(FSNamesystemLockMode.BM)).thenReturn(true);
+
Configuration conf = new Configuration();
//Set configuration property for rejecting unresolved topology mapping
@@ -401,6 +406,7 @@ public class TestDatanodeManager {
Configuration conf = new Configuration();
FSNamesystem fsn = Mockito.mock(FSNamesystem.class);
Mockito.when(fsn.hasWriteLock()).thenReturn(true);
+ Mockito.when(fsn.hasWriteLock(FSNamesystemLockMode.BM)).thenReturn(true);
if (scriptFileName != null && !scriptFileName.isEmpty()) {
URL shellScript = getClass().getResource(scriptFileName);
Path resourcePath = Paths.get(shellScript.toURI());
@@ -499,6 +505,7 @@ public class TestDatanodeManager {
Configuration conf = new Configuration();
FSNamesystem fsn = Mockito.mock(FSNamesystem.class);
Mockito.when(fsn.hasWriteLock()).thenReturn(true);
+ Mockito.when(fsn.hasWriteLock(FSNamesystemLockMode.BM)).thenReturn(true);
URL shellScript = getClass().getResource(
"/" + Shell.appendScriptExtension("topology-script"));
Path resourcePath = Paths.get(shellScript.toURI());
@@ -648,6 +655,7 @@ public class TestDatanodeManager {
DFSConfigKeys.DFS_NAMENODE_AVOID_STALE_DATANODE_FOR_READ_KEY, true);
FSNamesystem fsn = Mockito.mock(FSNamesystem.class);
Mockito.when(fsn.hasWriteLock()).thenReturn(true);
+ Mockito.when(fsn.hasWriteLock(FSNamesystemLockMode.BM)).thenReturn(true);
URL shellScript = getClass()
.getResource("/" + Shell.appendScriptExtension("topology-script"));
Path resourcePath = Paths.get(shellScript.toURI());
@@ -715,6 +723,7 @@ public class TestDatanodeManager {
DFSConfigKeys.DFS_NAMENODE_AVOID_STALE_DATANODE_FOR_READ_KEY, true);
FSNamesystem fsn = Mockito.mock(FSNamesystem.class);
Mockito.when(fsn.hasWriteLock()).thenReturn(true);
+ Mockito.when(fsn.hasWriteLock(FSNamesystemLockMode.BM)).thenReturn(true);
URL shellScript = getClass()
.getResource("/" + Shell.appendScriptExtension("topology-script"));
Path resourcePath = Paths.get(shellScript.toURI());
@@ -801,6 +810,7 @@ public class TestDatanodeManager {
DFSConfigKeys.DFS_NAMENODE_AVOID_STALE_DATANODE_FOR_READ_KEY, true);
FSNamesystem fsn = Mockito.mock(FSNamesystem.class);
Mockito.when(fsn.hasWriteLock()).thenReturn(true);
+ Mockito.when(fsn.hasWriteLock(FSNamesystemLockMode.BM)).thenReturn(true);
URL shellScript = getClass()
.getResource("/" + Shell.appendScriptExtension("topology-script"));
Path resourcePath = Paths.get(shellScript.toURI());
@@ -890,6 +900,7 @@ public class TestDatanodeManager {
// Set the write lock so that the DatanodeManager can start
Mockito.when(fsn.hasWriteLock()).thenReturn(true);
+ Mockito.when(fsn.hasWriteLock(FSNamesystemLockMode.BM)).thenReturn(true);
DatanodeManager dm = mockDatanodeManager(fsn, new Configuration());
HostFileManager hm = new HostFileManager();
@@ -988,6 +999,7 @@ public class TestDatanodeManager {
throws IOException {
FSNamesystem fsn = Mockito.mock(FSNamesystem.class);
Mockito.when(fsn.hasWriteLock()).thenReturn(true);
+ Mockito.when(fsn.hasWriteLock(FSNamesystemLockMode.BM)).thenReturn(true);
Configuration conf = new Configuration();
conf.setInt(DFSConfigKeys.DFS_NAMENODE_REPLICATION_MAX_STREAMS_KEY, maxTransfers);
conf.setInt(DFSConfigKeys.DFS_NAMENODE_REPLICATION_STREAMS_HARD_LIMIT_KEY,
@@ -1142,6 +1154,7 @@ public class TestDatanodeManager {
throws IOException {
FSNamesystem fsn = Mockito.mock(FSNamesystem.class);
Mockito.when(fsn.hasWriteLock()).thenReturn(true);
+ Mockito.when(fsn.hasWriteLock(FSNamesystemLockMode.BM)).thenReturn(true);
Configuration conf = new Configuration();
conf.setInt(DFSConfigKeys.DFS_NAMENODE_REPLICATION_MAX_STREAMS_KEY, maxTransfers);
DatanodeManager dm = Mockito.spy(mockDatanodeManager(fsn, conf));
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org
(hadoop) 22/23: HDFS-17459. [FGL] Add documentation (#6737)
Posted by za...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zanderxu pushed a commit to branch HDFS-17384
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit 39e0ac082555e4267c8ad1934ad6d48294978ed3
Author: Felix Nguyen <23...@users.noreply.github.com>
AuthorDate: Fri Apr 19 15:13:49 2024 +0800
HDFS-17459. [FGL] Add documentation (#6737)
---
.../hadoop-hdfs/src/site/markdown/NamenodeFGL.md | 210 +++++++++++++++++++++
1 file changed, 210 insertions(+)
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/site/markdown/NamenodeFGL.md b/hadoop-hdfs-project/hadoop-hdfs/src/site/markdown/NamenodeFGL.md
new file mode 100644
index 000000000000..be22b89be88d
--- /dev/null
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/site/markdown/NamenodeFGL.md
@@ -0,0 +1,210 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+HDFS Namenode Fine-grained Locking
+==================================
+
+<!-- MACRO{toc|fromDepth=0|toDepth=3} -->
+
+Overview
+--------
+
+HDFS relies on a single master, the Namenode (NN), as its metadata center.
+From an architectural point of view, a few elements make NN the bottleneck of an HDFS cluster:
+* NN keeps the entire namespace in memory (directory tree, blocks, Datanode related info, etc.)
+* Read requests (`getListing`, `getFileInfo`, `getBlockLocations`) are served from memory.
+Write requests (`mkdir`, `create`, `addBlock`, `complete`) update the memory state and write a journal transaction into QJM.
+Both types of requests need a locking mechanism to ensure data consistency and correctness.
+* All requests are funneled into NN and have to go through the global FS lock.
+Each write operation acquires this lock in write mode and holds it until that operation is executed.
+This lock mode prevents concurrent execution of write operations even if they involve different branches of the directory tree.
+
+NN fine-grained locking (FGL) implementation aims to alleviate this bottleneck by allowing concurrency of disjoint write operations.
+
+JIRA: [HDFS-17366](https://issues.apache.org/jira/browse/HDFS-17366)
+
+Design
+------
+In theory, fully independent operations can be processed concurrently, such as operations involving different subdirectory trees.
+As such, NN can split the global lock into the full path lock, just using the full path lock to protect a special subdirectory tree.
+
+### RPC Categorization
+
+Roughly, RPC operations handled by NN can be divided into 8 main categories
+
+| Category | Operations [...]
+|----------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ [...]
+| Involving namespace tree | `mkdir`, `create` (without overwrite), `getFileInfo` (without locations), `getListing` (without locations), `setOwner`, `setPermission`, `getStoragePolicy`, `setStoragePolicy`, `rename`, `isFileClosed`, `getFileLinkInfo`, `setTimes`, `modifyAclEntries`, `removeAclEntries`, `setAcl`, `getAcl`, `setXAttr`, `getXAttrs`, `listXAttrs`, `removeXAttr`, `checkAccess`, `getErasureCodingPolicy`, `unsetErasureCodingPolicy`, `getQuotaUsage`, `getPreferredBl [...]
+| Involving only blocks | `reportBadBlocks`, `updateBlockForPipeline`, `updatePipeline` [...]
+| Involving only DNs | `registerDatanode`, `setBalancerBandwidth`, `sendHeartbeat` [...]
+| Involving both namespace tree & blocks | `getBlockLocation`, `create` (with overwrite), `append`, `setReplication`, `abandonBlock`, `addBlock`, `getAdditionalDatanode`, `complete`, `concat`, `truncate`, `delete`, `getListing` (with locations), `getFileInfo` (with locations), `recoverLease`, `listCorruptFileBlocks`, `fsync`, `commitBlockSynchronization`, `RedundancyMonitor`, `processMisReplicatedBlocks` [...]
+| Involving both DNs & blocks | `getBlocks`, `errorReport` [...]
+| Involving namespace tree, DNs & blocks | `blockReport`, `blockReceivedAndDeleted`, `HeartbeatManager`, `Decommission` [...]
+| Requiring locking the entire namespace | `rollEditLog`, `startCommonService`, `startActiveService`, `saveNamespace`, `rollEdits`, `EditLogTailer`, `rollingUpgrade` [...]
+| Requiring no locking | `getServerDefaults`, `getStats` [...]
+
+For operations involving namespace tree, fully independent operations can be handled by NN concurrently. Almost all of them use the full path as a parameter, e.g. `create`, `mkdirs`, `getFileInfo`, etc. So we can use a full path lock to make them thread-safe.
+
+For operations involving blocks, one block belongs to one and only one `INodeFile`, so NN can use the namespace tree to make these operations thread-safe.
+
+For operations involving DNs, NN needs a separate DN lock because DNs operate separately from the namespace tree.
+
+For operations requiring the entire namespace locked, the global lock can be used to make these operations thread-safe. In general, these operations have low frequency and thus low impact despite the global locking.
+
+### Full Path Lock
+
+Used to protect operations involving namespace tree.
+
+All of these operations receive a path or INodeID as a parameter and can further be divided into 3 main subcategories:
+1. Parameters contain only one path (`create`, `mkdir`)
+2. Parameters contain multiple paths (`rename`, `concat`)
+3. Parameters contain INodeID (`addBlock`, `complete`)
+
+For type 1, NN acquires a full path lock according to its semantics. Take `setPermission("/a/b/c/f.txt")` for example, the set of locks to acquire are ReadLock("/"), ReadLock("a"), ReadLock("b"), ReadLock("c") and WriteLock("f.txt"). Different lock patterns are explained in a later section.
+
+For type 2, NN acquires full path locks in a predefined order, such as the lexicographic order, to avoid deadlocks.
+
+For type 3, NN acquires a full path lock by in the following fashion:
+- Unsafely obtains full path recursively
+- Acquires the full path lock according to the lock mode
+- Rechecks whether the last node of the full path is equal to the INodeID given
+ - If not, that means that the `INodeFile` might have been renamed or concatenated, need to retry
+ - If the max retry attempts have been reached, throw a `RetryException` to client to let client retry
+
+### `INodeFile` Lock
+
+Used to protect operations involving blocks.
+
+One block belongs to one and only one `INodeFile`, so NN can use the INodeFile lock to make operations thread-safe. Normally, there is no need to acquire the full path lock since changing the namespace tree structure does not affect the block.
+
+`concat` might change the `INodeFile` a block belongs to. Since both block related operations and `concat` need to acquire the `INodeFile` write lock, only one of them can be processed at a time.
+
+### DN Lock
+
+Used to protect operations involving DNs.
+
+NN uses a `DatanodeDescriptor` object to store the information of one DN and uses `DatanodeManager` to manage all DNs in the memory. `DatanodeDescriptor` uses `DatanodeStorageInfo` to store the information of one storage device on one DN.
+
+DNs have nothing to do with the namespace tree, so NN uses a separate DN lock for these operations. Since DNs are independent of one another, NN can assign a lock to each DN.
+
+### Global Lock
+
+Used for operations requiring the entire namespace locked.
+
+There are some operations that need to lock the entire namespace, e.g. safe mode related operations, HA service related, etc. NN uses the global lock to make these operations thread-safe. Outside of these infrequent operations that require the global write lock, all other operations have to acquire the global read lock. The only exception to this rule is JMX operations being allowed to bypass locking entirely to ensure that metrics can be collected regardless of long write lock holding.
+
+### Lock Order
+
+As mentioned above, there are the global lock, DN lock, and full path lock. NN acquires locks in this specific order to avoid deadlocks.
+
+Locks are to be acquired in this order:
+- Global > DN > Full path
+- Global > DN > Last `INodeFile`
+
+Possible lock combinations are as follows:
+- Global write lock
+- Global read lock > Full path lock
+- Global read lock > DN read/write lock
+- Global read lock > DN read/write lock > Read/Write lock of last `INodeFile`
+- Global read lock > DN read/write lock > Full path lock
+
+### Lock Pools
+
+NN allocates locks as needed to the INodes used by active threads, and deletes them after the locks are no longer in use. Locks for commonly accessed `INode`s like the root are cached.
+
+NN uses an `INodeLockPool` to manage these locks. The lock pool:
+- Returns a closeable lock for an INode based on the lock type,
+- Removes this lock if it is no longer used by any threads.
+
+Similar to `INodeLockPool`, a `DNLockPool` is used to manage the locks for DNs. Unlike `INodeLockPool`, `DNLockPool` keeps all locks in memory due to the comparatively lower number of locks.
+
+### Lock Modes
+
+Operations related to namespace tree have different semantics and may involve the modification or access of different INodes, for example: `getBlockLocation` only accesses the last iNodeFile, `delete` modifies both the parent and the last INode, `mkdir` may modify multiple ancestor INodes.
+
+Four lock modes (plus no locking):
+- LOCK_READ
+ - This lock mode acquires the read locks for all INodes down the path.
+ - Example operations: `getBlockLocation`, `getFileInfo`.
+- LOCK_WRITE
+ - This lock mode acquires the write lock for the last INode and the read locks for all ancestor INodes in the full path.
+ - Example operations: `setPermission`, `setReplication`.
+- LOCK_PARENT
+ - This lock mode acquires the write lock for the last two INodes and the read locks for all remaining ancestor INodes in the full path.
+ - Example operations: `rename`, `delete`, `create` (when the parent directory exists).
+- LOCK_ANCESTOR
+ - This lock mode acquires the write lock for the last existing INode and the read locks for all remaining ancestor INodes in the full path.
+ - Example operations: `mkdir`, `create` (when the parent directory doesn't exist).
+- NONE
+ - This lock mode does not acquire any locks for the given path.
+
+Roadmap
+-------
+
+#### Stage 1: Split the global lock into FSLock and BMLock
+
+Split the global lock into two global locks, FSLock and BMLock.
+- FSLock for operations that relate to namespace tree.
+- BMLock for operations related to blocks and/or operations related to DNs.
+- Both FSLock and BMLock for HA related operations.
+After this step, FGL contains global FSLock and global BMLock.
+
+No big logic changes in this step. The original logic with the global lock retains. This step aims to make the lock mode configurable.
+
+JIRA: [HDFS-17384](https://issues.apache.org/jira/browse/HDFS-17384) [Progress: Done]
+
+#### Stage 2: Split the global FSLock
+
+After splitting the global lock into FSLock and BMLock, this step aims to split the global FSLock into full path locks so that fully independent operations that only involve namespace tree can be processed concurrently.
+In this step, NN still uses the global BMLock to protect block related operations and DN related operations.
+After this step, FGL contains global FSLock, full path lock, and global BMLock.
+
+JIRA: [HDFS-17385](https://issues.apache.org/jira/browse/HDFS-17385) [Progress: Ongoing]
+
+#### Stage 3: Split the global BMLock
+
+This step aims to split the global BMLock into full path locks and DN locks.
+After this step, FGL contains global FSLock, DN lock, and full path lock.
+
+JIRA: [HDFS-17386](https://issues.apache.org/jira/browse/HDFS-17386) [Progress: Ongoing]
+
+Configuration
+------------
+
+NN FGL implementation can be used by adding this configuration to `hdfs-site.xml`.
+
+ <property>
+ <name>dfs.namenode.lock.model.provider.class</name>
+ <value>org.apache.hadoop.hdfs.server.namenode.fgl.FineGrainedFSNamesystemLock</value>
+ <description>
+ An implementation class of FSNamesystem lock.
+ Defaults to GlobalFSNamesystemLock.class
+ </description>
+ </property>
+
+The lock manager class must implement the interface defined by `org.apache.hadoop.hdfs.server.namenode.fgl.FSNLockManager`. Currently, there are two implementations:
+* `org.apache.hadoop.hdfs.server.namenode.fgl.GlobalFSNamesystemLock`: the original lock mode that utilizes one global FS lock, also the default value for this config;
+* `org.apache.hadoop.hdfs.server.namenode.fgl.FineGrainedFSNamesystemLock`: FGL implementation.
+
+Adding RPC
+----------
+
+For developers adding a new RPC operation, the operation should follow FGL locking schematic to ensure data integrity:
+* Global FSLock should be acquired in read mode, unless it is an administrative operation (related to HA, edit logs, etc.)
+* If the operation requires access/modification of `DatanodeDescriptor` and/or `DatanodeStorageInfo`, DN lock should be acquired in read/write mode accordingly.
+ * Only applicable in stage 3 once DN lock is implemented. During stage 1 and stage 2, global BMLock is to be used instead.
+* If the operation deals with one or more paths/blocks, the full path lock(s) should be acquired based on the implementation details described above. It is best to check an existing RPC operation that has a similar method of access to the new operation to consult the lock implementation.
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org
(hadoop) 05/23: HDFS-17390. [FGL] FSDirectory supports this fine-grained locking (#6573)
Posted by za...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zanderxu pushed a commit to branch HDFS-17384
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit 0c512c0db00cb943786f607f29e774f9e8fa1319
Author: ZanderXu <za...@apache.org>
AuthorDate: Wed Mar 6 21:43:05 2024 +0800
HDFS-17390. [FGL] FSDirectory supports this fine-grained locking (#6573)
---
.../apache/hadoop/hdfs/server/namenode/FSDirectory.java | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java
index 96fa1b4ad4d0..5b846b56b3d8 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java
@@ -17,6 +17,7 @@
*/
package org.apache.hadoop.hdfs.server.namenode;
+import org.apache.hadoop.hdfs.server.namenode.fgl.FSNamesystemLockMode;
import org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot;
import org.apache.hadoop.util.StringUtils;
@@ -262,27 +263,31 @@ public class FSDirectory implements Closeable {
* remain as placeholders only
*/
void readLock() {
- assert namesystem.hasReadLock() : "Should hold namesystem read lock";
+ assert namesystem.hasReadLock(FSNamesystemLockMode.FS) :
+ "Should hold read lock of namesystem FSLock";
}
void readUnlock() {
- assert namesystem.hasReadLock() : "Should hold namesystem read lock";
+ assert namesystem.hasReadLock(FSNamesystemLockMode.FS) :
+ "Should hold read lock of namesystem FSLock";
}
void writeLock() {
- assert namesystem.hasWriteLock() : "Should hold namesystem write lock";
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.FS) :
+ "Should hold write lock of namesystem FSLock";
}
void writeUnlock() {
- assert namesystem.hasWriteLock() : "Should hold namesystem write lock";
+ assert namesystem.hasWriteLock(FSNamesystemLockMode.FS) :
+ "Should hold write lock of namesystem FSLock";
}
boolean hasWriteLock() {
- return namesystem.hasWriteLock();
+ return namesystem.hasWriteLock(FSNamesystemLockMode.FS);
}
boolean hasReadLock() {
- return namesystem.hasReadLock();
+ return namesystem.hasReadLock(FSNamesystemLockMode.FS);
}
public int getListLimit() {
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org