This is an automated email from the ASF dual-hosted git repository. ferhui pushed a commit to branch HDFS-17384 in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/HDFS-17384 by this push: new ae11d05aedcf HDFS-17412. [FGL] Client RPCs involving maintenance supports fine-grained lock (#6667) ae11d05aedcf is described below commit ae11d05aedcf5ad11c7cf1b4208cd52c42fc0284 Author: ZanderXu <zande...@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 a0dc2ee70fbf..daa30ed250a3 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 df7e2bcc2dab..7be490576817 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 @@ -1991,7 +1991,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) { @@ -2004,13 +2004,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 @@ -4984,14 +4986,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; @@ -5012,14 +5014,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; @@ -5031,13 +5033,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; @@ -5056,7 +5058,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); @@ -5066,7 +5070,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) { @@ -5088,7 +5092,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); @@ -5100,7 +5104,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); @@ -5116,12 +5120,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); @@ -7518,7 +7522,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()) { @@ -7528,7 +7532,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; @@ -7538,7 +7542,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()) { @@ -7558,7 +7562,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-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org