HDFS-6959 Make the HDFS home directory location customizable. Contributed by Yongjun Zhang
(cherry picked from commit f4caedfcbf
)
This commit is contained in:
parent
69ee11dc93
commit
23c41897cb
|
@ -176,6 +176,9 @@ Release 2.6.0 - UNRELEASED
|
||||||
HDFS-4257. The ReplaceDatanodeOnFailure policies could have a forgiving
|
HDFS-4257. The ReplaceDatanodeOnFailure policies could have a forgiving
|
||||||
option (szetszwo via cmccabe)
|
option (szetszwo via cmccabe)
|
||||||
|
|
||||||
|
HDFS-6959. Make the HDFS home directory location customizable. (yzhang via
|
||||||
|
cmccabe)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
HDFS-6690. Deduplicate xattr names in memory. (wang)
|
HDFS-6690. Deduplicate xattr names in memory. (wang)
|
||||||
|
|
|
@ -41,6 +41,8 @@ public class DFSConfigKeys extends CommonConfigurationKeys {
|
||||||
public static final int DFS_STREAM_BUFFER_SIZE_DEFAULT = 4096;
|
public static final int DFS_STREAM_BUFFER_SIZE_DEFAULT = 4096;
|
||||||
public static final String DFS_BYTES_PER_CHECKSUM_KEY = "dfs.bytes-per-checksum";
|
public static final String DFS_BYTES_PER_CHECKSUM_KEY = "dfs.bytes-per-checksum";
|
||||||
public static final int DFS_BYTES_PER_CHECKSUM_DEFAULT = 512;
|
public static final int DFS_BYTES_PER_CHECKSUM_DEFAULT = 512;
|
||||||
|
public static final String DFS_USER_HOME_DIR_PREFIX_KEY = "dfs.user.home.dir.prefix";
|
||||||
|
public static final String DFS_USER_HOME_DIR_PREFIX_DEFAULT = "/user";
|
||||||
public static final String DFS_CLIENT_RETRY_POLICY_ENABLED_KEY = "dfs.client.retry.policy.enabled";
|
public static final String DFS_CLIENT_RETRY_POLICY_ENABLED_KEY = "dfs.client.retry.policy.enabled";
|
||||||
public static final boolean DFS_CLIENT_RETRY_POLICY_ENABLED_DEFAULT = false;
|
public static final boolean DFS_CLIENT_RETRY_POLICY_ENABLED_DEFAULT = false;
|
||||||
public static final String DFS_CLIENT_RETRY_POLICY_SPEC_KEY = "dfs.client.retry.policy.spec";
|
public static final String DFS_CLIENT_RETRY_POLICY_SPEC_KEY = "dfs.client.retry.policy.spec";
|
||||||
|
|
|
@ -102,6 +102,8 @@ import com.google.common.base.Preconditions;
|
||||||
public class DistributedFileSystem extends FileSystem {
|
public class DistributedFileSystem extends FileSystem {
|
||||||
private Path workingDir;
|
private Path workingDir;
|
||||||
private URI uri;
|
private URI uri;
|
||||||
|
private String homeDirPrefix =
|
||||||
|
DFSConfigKeys.DFS_USER_HOME_DIR_PREFIX_DEFAULT;
|
||||||
|
|
||||||
DFSClient dfs;
|
DFSClient dfs;
|
||||||
private boolean verifyChecksum = true;
|
private boolean verifyChecksum = true;
|
||||||
|
@ -136,7 +138,10 @@ public class DistributedFileSystem extends FileSystem {
|
||||||
if (host == null) {
|
if (host == null) {
|
||||||
throw new IOException("Incomplete HDFS URI, no host: "+ uri);
|
throw new IOException("Incomplete HDFS URI, no host: "+ uri);
|
||||||
}
|
}
|
||||||
|
homeDirPrefix = conf.get(
|
||||||
|
DFSConfigKeys.DFS_USER_HOME_DIR_PREFIX_KEY,
|
||||||
|
DFSConfigKeys.DFS_USER_HOME_DIR_PREFIX_DEFAULT);
|
||||||
|
|
||||||
this.dfs = new DFSClient(uri, conf, statistics);
|
this.dfs = new DFSClient(uri, conf, statistics);
|
||||||
this.uri = URI.create(uri.getScheme()+"://"+uri.getAuthority());
|
this.uri = URI.create(uri.getScheme()+"://"+uri.getAuthority());
|
||||||
this.workingDir = getHomeDirectory();
|
this.workingDir = getHomeDirectory();
|
||||||
|
@ -167,10 +172,10 @@ public class DistributedFileSystem extends FileSystem {
|
||||||
workingDir = fixRelativePart(dir);
|
workingDir = fixRelativePart(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Path getHomeDirectory() {
|
public Path getHomeDirectory() {
|
||||||
return makeQualified(new Path("/user/" + dfs.ugi.getShortUserName()));
|
return makeQualified(new Path(homeDirPrefix + "/"
|
||||||
|
+ dfs.ugi.getShortUserName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2090,4 +2090,12 @@
|
||||||
</description>
|
</description>
|
||||||
</property>
|
</property>
|
||||||
|
|
||||||
|
<property>
|
||||||
|
<name>dfs.user.home.dir.prefix</name>
|
||||||
|
<value>/user</value>
|
||||||
|
<description>The directory to prepend to user name to get the user's
|
||||||
|
home direcotry.
|
||||||
|
</description>
|
||||||
|
</property>
|
||||||
|
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
|
@ -90,7 +90,9 @@ public class TestLocalDFS {
|
||||||
|
|
||||||
// test home directory
|
// test home directory
|
||||||
Path home =
|
Path home =
|
||||||
fileSys.makeQualified(new Path("/user/" + getUserName(fileSys)));
|
fileSys.makeQualified(
|
||||||
|
new Path(DFSConfigKeys.DFS_USER_HOME_DIR_PREFIX_DEFAULT
|
||||||
|
+ "/" + getUserName(fileSys)));
|
||||||
Path fsHome = fileSys.getHomeDirectory();
|
Path fsHome = fileSys.getHomeDirectory();
|
||||||
assertEquals(home, fsHome);
|
assertEquals(home, fsHome);
|
||||||
|
|
||||||
|
@ -99,4 +101,29 @@ public class TestLocalDFS {
|
||||||
cluster.shutdown();
|
cluster.shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests get/set working directory in DFS.
|
||||||
|
*/
|
||||||
|
@Test(timeout=30000)
|
||||||
|
public void testHomeDirectory() throws IOException {
|
||||||
|
final String[] homeBases = new String[] {"/home", "/home/user"};
|
||||||
|
Configuration conf = new HdfsConfiguration();
|
||||||
|
for (final String homeBase : homeBases) {
|
||||||
|
conf.set(DFSConfigKeys.DFS_USER_HOME_DIR_PREFIX_KEY, homeBase);
|
||||||
|
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build();
|
||||||
|
FileSystem fileSys = cluster.getFileSystem();
|
||||||
|
try {
|
||||||
|
// test home directory
|
||||||
|
Path home =
|
||||||
|
fileSys.makeQualified(
|
||||||
|
new Path(homeBase + "/" + getUserName(fileSys)));
|
||||||
|
Path fsHome = fileSys.getHomeDirectory();
|
||||||
|
assertEquals(home, fsHome);
|
||||||
|
} finally {
|
||||||
|
fileSys.close();
|
||||||
|
cluster.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue