This is an automated email from the ASF dual-hosted git repository. zanderxu pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit 6d888d599f4eddd4697979510a379a2a70203e9c Author: ZanderXu <zande...@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 a1f5d46ebef..1de284e65b5 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 @@ -7196,13 +7196,13 @@ void allowSnapshot(String path) throws IOException { 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); @@ -7213,13 +7213,13 @@ void disallowSnapshot(String path) throws IOException { 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); @@ -7238,14 +7238,15 @@ String createSnapshot(String snapshotRoot, String snapshotName, 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); @@ -7275,15 +7276,15 @@ void renameSnapshot( 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, @@ -7310,13 +7311,13 @@ public SnapshottableDirectoryStatus[] getSnapshottableDirListing() 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); @@ -7341,14 +7342,14 @@ public SnapshotStatus[] getSnapshotListing(String snapshotRoot) 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); @@ -7386,14 +7387,14 @@ SnapshotDiffReport getSnapshotDiffReport(String path, 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, @@ -7460,7 +7461,7 @@ SnapshotDiffReportListing getSnapshotDiffReportListing(String path, final FSPermissionChecker pc = getPermissionChecker(); FSPermissionChecker.setOperationType(operationName); try { - readLock(); + readLock(FSNamesystemLockMode.FS); try { checkOperation(OperationCategory.READ); diffs = FSDirSnapshotOp @@ -7468,8 +7469,8 @@ SnapshotDiffReportListing getSnapshotDiffReportListing(String path, 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, @@ -7497,7 +7498,8 @@ void deleteSnapshot(String snapshotRoot, String snapshotName, 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); @@ -7505,7 +7507,8 @@ void deleteSnapshot(String snapshotRoot, String snapshotName, 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 c62455c724f..5b509a7d85f 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 @@ 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 void cancel() { 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 2759b9e20d7..6be34537a05 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.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 @@ private static FSNamesystem makeMockFsNameSystem() { 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-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org