HDFS-2109. Store uMask as member variable to DFSClient.Conf. Contributed by Bharath Mundlapudi
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1141767 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7bd41f031f
commit
09c8adfb18
|
@ -537,6 +537,9 @@ Trunk (unreleased changes)
|
||||||
HDFS-2107. Move block management code from o.a.h.h.s.namenode to a new
|
HDFS-2107. Move block management code from o.a.h.h.s.namenode to a new
|
||||||
package o.a.h.h.s.blockmanagement. (szetszwo)
|
package o.a.h.h.s.blockmanagement. (szetszwo)
|
||||||
|
|
||||||
|
HDFS-2109. Store uMask as member variable to DFSClient.Conf. (Bharath
|
||||||
|
Mundlapudi via szetszwo)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
HDFS-1458. Improve checkpoint performance by avoiding unnecessary image
|
HDFS-1458. Improve checkpoint performance by avoiding unnecessary image
|
||||||
|
|
|
@ -156,6 +156,7 @@ public class DFSClient implements FSConstants, java.io.Closeable {
|
||||||
final long prefetchSize;
|
final long prefetchSize;
|
||||||
final short defaultReplication;
|
final short defaultReplication;
|
||||||
final String taskId;
|
final String taskId;
|
||||||
|
final FsPermission uMask;
|
||||||
|
|
||||||
Conf(Configuration conf) {
|
Conf(Configuration conf) {
|
||||||
maxBlockAcquireFailures = conf.getInt(
|
maxBlockAcquireFailures = conf.getInt(
|
||||||
|
@ -201,6 +202,7 @@ public class DFSClient implements FSConstants, java.io.Closeable {
|
||||||
.DFS_CLIENT_BLOCK_WRITE_LOCATEFOLLOWINGBLOCK_RETRIES_KEY,
|
.DFS_CLIENT_BLOCK_WRITE_LOCATEFOLLOWINGBLOCK_RETRIES_KEY,
|
||||||
DFSConfigKeys
|
DFSConfigKeys
|
||||||
.DFS_CLIENT_BLOCK_WRITE_LOCATEFOLLOWINGBLOCK_RETRIES_DEFAULT);
|
.DFS_CLIENT_BLOCK_WRITE_LOCATEFOLLOWINGBLOCK_RETRIES_DEFAULT);
|
||||||
|
uMask = FsPermission.getUMask(conf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -789,7 +791,7 @@ public class DFSClient implements FSConstants, java.io.Closeable {
|
||||||
if (permission == null) {
|
if (permission == null) {
|
||||||
permission = FsPermission.getDefault();
|
permission = FsPermission.getDefault();
|
||||||
}
|
}
|
||||||
FsPermission masked = permission.applyUMask(FsPermission.getUMask(conf));
|
FsPermission masked = permission.applyUMask(dfsClientConf.uMask);
|
||||||
if(LOG.isDebugEnabled()) {
|
if(LOG.isDebugEnabled()) {
|
||||||
LOG.debug(src + ": masked=" + masked);
|
LOG.debug(src + ": masked=" + masked);
|
||||||
}
|
}
|
||||||
|
@ -856,7 +858,7 @@ public class DFSClient implements FSConstants, java.io.Closeable {
|
||||||
throws IOException {
|
throws IOException {
|
||||||
try {
|
try {
|
||||||
FsPermission dirPerm =
|
FsPermission dirPerm =
|
||||||
FsPermission.getDefault().applyUMask(FsPermission.getUMask(conf));
|
FsPermission.getDefault().applyUMask(dfsClientConf.uMask);
|
||||||
namenode.createSymlink(target, link, dirPerm, createParent);
|
namenode.createSymlink(target, link, dirPerm, createParent);
|
||||||
} catch (RemoteException re) {
|
} catch (RemoteException re) {
|
||||||
throw re.unwrapRemoteException(AccessControlException.class,
|
throw re.unwrapRemoteException(AccessControlException.class,
|
||||||
|
@ -1424,7 +1426,7 @@ public class DFSClient implements FSConstants, java.io.Closeable {
|
||||||
if (permission == null) {
|
if (permission == null) {
|
||||||
permission = FsPermission.getDefault();
|
permission = FsPermission.getDefault();
|
||||||
}
|
}
|
||||||
FsPermission masked = permission.applyUMask(FsPermission.getUMask(conf));
|
FsPermission masked = permission.applyUMask(dfsClientConf.uMask);
|
||||||
if(LOG.isDebugEnabled()) {
|
if(LOG.isDebugEnabled()) {
|
||||||
LOG.debug(src + ": masked=" + masked);
|
LOG.debug(src + ": masked=" + masked);
|
||||||
}
|
}
|
||||||
|
@ -1451,7 +1453,7 @@ public class DFSClient implements FSConstants, java.io.Closeable {
|
||||||
checkOpen();
|
checkOpen();
|
||||||
if (absPermission == null) {
|
if (absPermission == null) {
|
||||||
absPermission =
|
absPermission =
|
||||||
FsPermission.getDefault().applyUMask(FsPermission.getUMask(conf));
|
FsPermission.getDefault().applyUMask(dfsClientConf.uMask);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(LOG.isDebugEnabled()) {
|
if(LOG.isDebugEnabled()) {
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
package org.apache.hadoop.hdfs;
|
package org.apache.hadoop.hdfs;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
@ -31,7 +30,6 @@ import junit.framework.TestCase;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.fs.CreateFlag;
|
|
||||||
import org.apache.hadoop.fs.FSDataInputStream;
|
import org.apache.hadoop.fs.FSDataInputStream;
|
||||||
import org.apache.hadoop.fs.FSDataOutputStream;
|
import org.apache.hadoop.fs.FSDataOutputStream;
|
||||||
import org.apache.hadoop.fs.FileStatus;
|
import org.apache.hadoop.fs.FileStatus;
|
||||||
|
@ -68,7 +66,6 @@ public class TestDFSPermission extends TestCase {
|
||||||
final static private int NUM_TEST_PERMISSIONS =
|
final static private int NUM_TEST_PERMISSIONS =
|
||||||
conf.getInt("test.dfs.permission.num", 10) * (MAX_PERMISSION + 1) / 100;
|
conf.getInt("test.dfs.permission.num", 10) * (MAX_PERMISSION + 1) / 100;
|
||||||
|
|
||||||
|
|
||||||
final private static String PATH_NAME = "xx";
|
final private static String PATH_NAME = "xx";
|
||||||
final private static Path FILE_DIR_PATH = new Path("/", PATH_NAME);
|
final private static Path FILE_DIR_PATH = new Path("/", PATH_NAME);
|
||||||
final private static Path NON_EXISTENT_PATH = new Path("/parent", PATH_NAME);
|
final private static Path NON_EXISTENT_PATH = new Path("/parent", PATH_NAME);
|
||||||
|
@ -115,44 +112,66 @@ public class TestDFSPermission extends TestCase {
|
||||||
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(3).build();
|
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(3).build();
|
||||||
try {
|
try {
|
||||||
cluster.waitActive();
|
cluster.waitActive();
|
||||||
fs = FileSystem.get(conf);
|
|
||||||
LOG.info("ROOT=" + fs.getFileStatus(new Path("/")));
|
|
||||||
testPermissionSetting(OpType.CREATE); // test file creation
|
testPermissionSetting(OpType.CREATE); // test file creation
|
||||||
testPermissionSetting(OpType.MKDIRS); // test directory creation
|
testPermissionSetting(OpType.MKDIRS); // test directory creation
|
||||||
} finally {
|
} finally {
|
||||||
fs.close();
|
|
||||||
cluster.shutdown();
|
cluster.shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initFileSystem(short umask) throws Exception {
|
||||||
|
// set umask in configuration, converting to padded octal
|
||||||
|
conf.set(FsPermission.UMASK_LABEL, String.format("%1$03o", umask));
|
||||||
|
fs = FileSystem.get(conf);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void closeFileSystem() throws Exception {
|
||||||
|
fs.close();
|
||||||
|
}
|
||||||
|
|
||||||
/* check permission setting works correctly for file or directory */
|
/* check permission setting works correctly for file or directory */
|
||||||
private void testPermissionSetting(OpType op) throws Exception {
|
private void testPermissionSetting(OpType op) throws Exception {
|
||||||
|
short uMask = DEFAULT_UMASK;
|
||||||
// case 1: use default permission but all possible umasks
|
// case 1: use default permission but all possible umasks
|
||||||
PermissionGenerator generator = new PermissionGenerator(r);
|
PermissionGenerator generator = new PermissionGenerator(r);
|
||||||
|
FsPermission permission = new FsPermission(DEFAULT_PERMISSION);
|
||||||
for (short i = 0; i < NUM_TEST_PERMISSIONS; i++) {
|
for (short i = 0; i < NUM_TEST_PERMISSIONS; i++) {
|
||||||
createAndCheckPermission(op, FILE_DIR_PATH, generator.next(),
|
uMask = generator.next();
|
||||||
new FsPermission(DEFAULT_PERMISSION), true);
|
initFileSystem(uMask);
|
||||||
|
createAndCheckPermission(op, FILE_DIR_PATH, uMask, permission, true);
|
||||||
|
closeFileSystem();
|
||||||
}
|
}
|
||||||
|
|
||||||
// case 2: use permission 0643 and the default umask
|
// case 2: use permission 0643 and the default umask
|
||||||
createAndCheckPermission(op, FILE_DIR_PATH, DEFAULT_UMASK,
|
uMask = DEFAULT_UMASK;
|
||||||
new FsPermission((short) 0643), true);
|
initFileSystem(uMask);
|
||||||
|
createAndCheckPermission(op, FILE_DIR_PATH, uMask, new FsPermission(
|
||||||
|
(short) 0643), true);
|
||||||
|
closeFileSystem();
|
||||||
|
|
||||||
// case 3: use permission 0643 and umask 0222
|
// case 3: use permission 0643 and umask 0222
|
||||||
createAndCheckPermission(op, FILE_DIR_PATH, (short) 0222,
|
uMask = (short) 0222;
|
||||||
new FsPermission((short) 0643), false);
|
initFileSystem(uMask);
|
||||||
|
createAndCheckPermission(op, FILE_DIR_PATH, uMask, new FsPermission(
|
||||||
|
(short) 0643), false);
|
||||||
|
closeFileSystem();
|
||||||
|
|
||||||
// case 4: set permission
|
// case 4: set permission
|
||||||
fs.setPermission(FILE_DIR_PATH, new FsPermission((short) 0111));
|
uMask = (short) 0111;
|
||||||
|
initFileSystem(uMask);
|
||||||
|
fs.setPermission(FILE_DIR_PATH, new FsPermission(uMask));
|
||||||
short expectedPermission = (short) ((op == OpType.CREATE) ? 0 : 0111);
|
short expectedPermission = (short) ((op == OpType.CREATE) ? 0 : 0111);
|
||||||
checkPermission(FILE_DIR_PATH, expectedPermission, true);
|
checkPermission(FILE_DIR_PATH, expectedPermission, true);
|
||||||
|
closeFileSystem();
|
||||||
|
|
||||||
// case 5: test non-existent parent directory
|
// case 5: test non-existent parent directory
|
||||||
assertFalse(fs.exists(NON_EXISTENT_PATH));
|
uMask = DEFAULT_UMASK;
|
||||||
createAndCheckPermission(op, NON_EXISTENT_PATH, DEFAULT_UMASK,
|
initFileSystem(uMask);
|
||||||
new FsPermission(DEFAULT_PERMISSION), false);
|
assertFalse("File shouldn't exists", fs.exists(NON_EXISTENT_PATH));
|
||||||
|
createAndCheckPermission(op, NON_EXISTENT_PATH, uMask, new FsPermission(
|
||||||
|
DEFAULT_PERMISSION), false);
|
||||||
Path parent = NON_EXISTENT_PATH.getParent();
|
Path parent = NON_EXISTENT_PATH.getParent();
|
||||||
checkPermission(parent, getPermission(parent.getParent()), true);
|
checkPermission(parent, getPermission(parent.getParent()), true);
|
||||||
|
closeFileSystem();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get the permission of a file/directory */
|
/* get the permission of a file/directory */
|
||||||
|
|
Loading…
Reference in New Issue