Revert "HDFS-16531. Avoid setReplication writing an edit record if old replication equals the new value (#4148). Contributed by Stephen O'Donnell."

This reverts commit 045d48530c.
This commit is contained in:
S O'Donnell 2022-04-20 20:57:23 +01:00
parent 4fed01ef21
commit bacd0b9a92
3 changed files with 15 additions and 33 deletions

View File

@ -50,11 +50,6 @@ import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_QUOTA_BY_STORAGETYPE_ENAB
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_STORAGE_POLICY_ENABLED_KEY; import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_STORAGE_POLICY_ENABLED_KEY;
public class FSDirAttrOp { public class FSDirAttrOp {
protected enum SetRepStatus {
UNCHANGED, INVALID, SUCCESS
}
static FileStatus setPermission( static FileStatus setPermission(
FSDirectory fsd, FSPermissionChecker pc, final String src, FSDirectory fsd, FSPermissionChecker pc, final String src,
FsPermission permission) throws IOException { FsPermission permission) throws IOException {
@ -135,11 +130,11 @@ public class FSDirAttrOp {
return fsd.getAuditFileInfo(iip); return fsd.getAuditFileInfo(iip);
} }
static SetRepStatus setReplication( static boolean setReplication(
FSDirectory fsd, FSPermissionChecker pc, BlockManager bm, String src, FSDirectory fsd, FSPermissionChecker pc, BlockManager bm, String src,
final short replication) throws IOException { final short replication) throws IOException {
bm.verifyReplication(src, replication, null); bm.verifyReplication(src, replication, null);
final SetRepStatus status; final boolean isFile;
fsd.writeLock(); fsd.writeLock();
try { try {
final INodesInPath iip = fsd.resolvePath(pc, src, DirOp.WRITE); final INodesInPath iip = fsd.resolvePath(pc, src, DirOp.WRITE);
@ -147,14 +142,16 @@ public class FSDirAttrOp {
fsd.checkPathAccess(pc, iip, FsAction.WRITE); fsd.checkPathAccess(pc, iip, FsAction.WRITE);
} }
status = unprotectedSetReplication(fsd, iip, replication); final BlockInfo[] blocks = unprotectedSetReplication(fsd, iip,
if (status == SetRepStatus.SUCCESS) { replication);
isFile = blocks != null;
if (isFile) {
fsd.getEditLog().logSetReplication(iip.getPath(), replication); fsd.getEditLog().logSetReplication(iip.getPath(), replication);
} }
} finally { } finally {
fsd.writeUnlock(); fsd.writeUnlock();
} }
return status; return isFile;
} }
static FileStatus unsetStoragePolicy(FSDirectory fsd, FSPermissionChecker pc, static FileStatus unsetStoragePolicy(FSDirectory fsd, FSPermissionChecker pc,
@ -379,7 +376,7 @@ public class FSDirAttrOp {
} }
} }
static SetRepStatus unprotectedSetReplication( static BlockInfo[] unprotectedSetReplication(
FSDirectory fsd, INodesInPath iip, short replication) FSDirectory fsd, INodesInPath iip, short replication)
throws QuotaExceededException, UnresolvedLinkException, throws QuotaExceededException, UnresolvedLinkException,
SnapshotAccessControlException, UnsupportedActionException { SnapshotAccessControlException, UnsupportedActionException {
@ -389,20 +386,12 @@ public class FSDirAttrOp {
final INode inode = iip.getLastINode(); final INode inode = iip.getLastINode();
if (inode == null || !inode.isFile() || inode.asFile().isStriped()) { if (inode == null || !inode.isFile() || inode.asFile().isStriped()) {
// TODO we do not support replication on stripe layout files yet // TODO we do not support replication on stripe layout files yet
// We return invalid here, so we skip writing an edit, but also write an return null;
// unsuccessful audit message.
return SetRepStatus.INVALID;
} }
INodeFile file = inode.asFile(); INodeFile file = inode.asFile();
// Make sure the directory has sufficient quotas // Make sure the directory has sufficient quotas
short oldBR = file.getPreferredBlockReplication(); short oldBR = file.getPreferredBlockReplication();
if (oldBR == replication) {
// No need to do anything as the requested rep factor is the same as
// existing. Returning UNCHANGED to we can skip writing edits, but still
// log a successful audit message.
return SetRepStatus.UNCHANGED;
}
long size = file.computeFileSize(true, true); long size = file.computeFileSize(true, true);
// Ensure the quota does not exceed // Ensure the quota does not exceed
@ -433,7 +422,7 @@ public class FSDirAttrOp {
oldBR, iip.getPath()); oldBR, iip.getPath());
} }
} }
return SetRepStatus.SUCCESS; return file.getBlocks();
} }
static void unprotectedSetStoragePolicy(FSDirectory fsd, BlockManager bm, static void unprotectedSetStoragePolicy(FSDirectory fsd, BlockManager bm,

View File

@ -2239,14 +2239,14 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
boolean setReplication(final String src, final short replication) boolean setReplication(final String src, final short replication)
throws IOException { throws IOException {
final String operationName = "setReplication"; final String operationName = "setReplication";
FSDirAttrOp.SetRepStatus status; boolean success = false;
checkOperation(OperationCategory.WRITE); checkOperation(OperationCategory.WRITE);
final FSPermissionChecker pc = getPermissionChecker(); final FSPermissionChecker pc = getPermissionChecker();
writeLock(); writeLock();
try { try {
checkOperation(OperationCategory.WRITE); checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot set replication for " + src); checkNameNodeSafeMode("Cannot set replication for " + src);
status = FSDirAttrOp.setReplication(dir, pc, blockManager, src, success = FSDirAttrOp.setReplication(dir, pc, blockManager, src,
replication); replication);
} catch (AccessControlException e) { } catch (AccessControlException e) {
logAuditEvent(false, operationName, src); logAuditEvent(false, operationName, src);
@ -2254,12 +2254,11 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
} finally { } finally {
writeUnlock(operationName); writeUnlock(operationName);
} }
if (status == FSDirAttrOp.SetRepStatus.SUCCESS) { if (success) {
getEditLog().logSync(); getEditLog().logSync();
logAuditEvent(true, operationName, src);
} }
logAuditEvent(status != FSDirAttrOp.SetRepStatus.INVALID, return success;
operationName, src);
return status != FSDirAttrOp.SetRepStatus.INVALID;
} }
/** /**

View File

@ -82,12 +82,6 @@ public class TestSetrepIncreasing {
public void testSetrepIncreasing() throws IOException { public void testSetrepIncreasing() throws IOException {
setrep(3, 7, false); setrep(3, 7, false);
} }
@Test(timeout=120000)
public void testSetrepSameRepValue() throws IOException {
setrep(3, 3, false);
}
@Test(timeout=120000) @Test(timeout=120000)
public void testSetrepIncreasingSimulatedStorage() throws IOException { public void testSetrepIncreasingSimulatedStorage() throws IOException {
setrep(3, 7, true); setrep(3, 7, true);