|
@@ -48,6 +48,11 @@ import java.util.List;
|
|
|
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_QUOTA_BY_STORAGETYPE_ENABLED_KEY;
|
|
|
|
|
|
public class FSDirAttrOp {
|
|
|
+
|
|
|
+ protected enum SetRepStatus {
|
|
|
+ UNCHANGED, INVALID, SUCCESS
|
|
|
+ }
|
|
|
+
|
|
|
static FileStatus setPermission(
|
|
|
FSDirectory fsd, FSPermissionChecker pc, final String src,
|
|
|
FsPermission permission) throws IOException {
|
|
@@ -134,11 +139,11 @@ public class FSDirAttrOp {
|
|
|
return fsd.getAuditFileInfo(iip);
|
|
|
}
|
|
|
|
|
|
- static boolean setReplication(
|
|
|
+ static SetRepStatus setReplication(
|
|
|
FSDirectory fsd, FSPermissionChecker pc, BlockManager bm, String src,
|
|
|
final short replication) throws IOException {
|
|
|
bm.verifyReplication(src, replication, null);
|
|
|
- final boolean isFile;
|
|
|
+ final SetRepStatus status;
|
|
|
fsd.writeLock();
|
|
|
try {
|
|
|
final INodesInPath iip = fsd.resolvePath(pc, src, DirOp.WRITE);
|
|
@@ -146,16 +151,14 @@ public class FSDirAttrOp {
|
|
|
fsd.checkPathAccess(pc, iip, FsAction.WRITE);
|
|
|
}
|
|
|
|
|
|
- final BlockInfo[] blocks = unprotectedSetReplication(fsd, iip,
|
|
|
- replication);
|
|
|
- isFile = blocks != null;
|
|
|
- if (isFile) {
|
|
|
+ status = unprotectedSetReplication(fsd, iip, replication);
|
|
|
+ if (status == SetRepStatus.SUCCESS) {
|
|
|
fsd.getEditLog().logSetReplication(iip.getPath(), replication);
|
|
|
}
|
|
|
} finally {
|
|
|
fsd.writeUnlock();
|
|
|
}
|
|
|
- return isFile;
|
|
|
+ return status;
|
|
|
}
|
|
|
|
|
|
static FileStatus unsetStoragePolicy(FSDirectory fsd, FSPermissionChecker pc,
|
|
@@ -381,7 +384,7 @@ public class FSDirAttrOp {
|
|
|
return dirNode;
|
|
|
}
|
|
|
|
|
|
- static BlockInfo[] unprotectedSetReplication(
|
|
|
+ static SetRepStatus unprotectedSetReplication(
|
|
|
FSDirectory fsd, INodesInPath iip, short replication)
|
|
|
throws QuotaExceededException, UnresolvedLinkException,
|
|
|
SnapshotAccessControlException, UnsupportedActionException {
|
|
@@ -391,12 +394,20 @@ public class FSDirAttrOp {
|
|
|
final INode inode = iip.getLastINode();
|
|
|
if (inode == null || !inode.isFile() || inode.asFile().isStriped()) {
|
|
|
// TODO we do not support replication on stripe layout files yet
|
|
|
- return null;
|
|
|
+ // We return invalid here, so we skip writing an edit, but also write an
|
|
|
+ // unsuccessful audit message.
|
|
|
+ return SetRepStatus.INVALID;
|
|
|
}
|
|
|
|
|
|
INodeFile file = inode.asFile();
|
|
|
// Make sure the directory has sufficient quotas
|
|
|
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);
|
|
|
// Ensure the quota does not exceed
|
|
@@ -427,7 +438,7 @@ public class FSDirAttrOp {
|
|
|
oldBR, iip.getPath());
|
|
|
}
|
|
|
}
|
|
|
- return file.getBlocks();
|
|
|
+ return SetRepStatus.SUCCESS;
|
|
|
}
|
|
|
|
|
|
static void unprotectedSetStoragePolicy(FSDirectory fsd, BlockManager bm,
|