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 fe...@apache.org on 2024/03/27 01:41:25 UTC
(hadoop) branch HDFS-17384 updated: HDFS-17410. [FGL] Client RPCs that changes file attributes supports fine-grained lock (#6634)
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 123915508b61 HDFS-17410. [FGL] Client RPCs that changes file attributes supports fine-grained lock (#6634)
123915508b61 is described below
commit 123915508b61978ac448d6951184194ea58e35d4
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 6a0c97c5798c..3610ca4b9621 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
@@ -2146,13 +2146,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) {
@@ -2178,13 +2178,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) {
@@ -2314,13 +2314,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) {
@@ -2343,13 +2343,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) {
@@ -2387,7 +2387,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);
@@ -2396,7 +2396,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();
@@ -2467,14 +2467,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);
@@ -2527,14 +2527,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) {
@@ -2561,14 +2561,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) {
@@ -2609,13 +2609,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) {
@@ -2637,12 +2637,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");
}
}
@@ -2652,12 +2652,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");
}
}
@@ -2921,7 +2921,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()) {
//
@@ -3263,7 +3263,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));
@@ -3616,12 +3616,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);
@@ -3654,14 +3654,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);
@@ -5852,7 +5853,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);
@@ -7984,13 +7985,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) {
@@ -8009,13 +8010,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) {
@@ -8033,13 +8034,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) {
@@ -8057,13 +8058,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) {
@@ -8081,13 +8082,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) {
@@ -8105,12 +8106,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);
@@ -8177,7 +8178,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
@@ -8185,7 +8186,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) {
@@ -8202,7 +8203,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 =
@@ -8210,7 +8211,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);
}
}
@@ -8239,7 +8240,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 =
@@ -8247,7 +8248,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);
}
}
@@ -8270,7 +8271,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
@@ -8302,7 +8303,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();
}
@@ -8628,14 +8630,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) {
@@ -8654,12 +8656,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);
@@ -8676,12 +8678,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);
@@ -8699,14 +8701,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