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:58 UTC
(hadoop) 17/23: HDFS-17389. [FGL] Client RPCs involving read process supports fine-grained lock (#6590)
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