HDFS-12748. NameNode memory leak when accessing webhdfs GETHOMEDIRECTORY. Contributed by Weiwei Yang.

This commit is contained in:
Weiwei Yang 2019-07-04 09:37:24 +08:00
parent acd2d524e8
commit 729cb3aefe
3 changed files with 23 additions and 10 deletions

View File

@ -994,4 +994,24 @@ public static Path makePathFromFileId(long fileId) {
return new Path(sb.toString()); return new Path(sb.toString());
} }
/**
* Returns current user home directory under a home directory prefix.
* The home directory prefix can be defined by
* {@link HdfsClientConfigKeys#DFS_USER_HOME_DIR_PREFIX_KEY}.
* User info is obtained from given {@link UserGroupInformation}.
* @param conf configuration
* @param ugi {@link UserGroupInformation} of current user.
* @return the home directory of current user.
*/
public static Path getHomeDirectory(Configuration conf,
UserGroupInformation ugi) {
String userHomePrefix = HdfsClientConfigKeys
.DFS_USER_HOME_DIR_PREFIX_DEFAULT;
if (conf != null) {
userHomePrefix = conf.get(
HdfsClientConfigKeys.DFS_USER_HOME_DIR_PREFIX_KEY,
HdfsClientConfigKeys.DFS_USER_HOME_DIR_PREFIX_DEFAULT);
}
return new Path(userHomePrefix + "/" + ugi.getShortUserName());
}
} }

View File

@ -132,8 +132,6 @@ public class DistributedFileSystem extends FileSystem
implements KeyProviderTokenIssuer { implements KeyProviderTokenIssuer {
private Path workingDir; private Path workingDir;
private URI uri; private URI uri;
private String homeDirPrefix =
HdfsClientConfigKeys.DFS_USER_HOME_DIR_PREFIX_DEFAULT;
DFSClient dfs; DFSClient dfs;
private boolean verifyChecksum = true; private boolean verifyChecksum = true;
@ -169,9 +167,6 @@ public void initialize(URI uri, Configuration conf) throws IOException {
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(
HdfsClientConfigKeys.DFS_USER_HOME_DIR_PREFIX_KEY,
HdfsClientConfigKeys.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());
@ -214,8 +209,7 @@ public void setWorkingDirectory(Path dir) {
@Override @Override
public Path getHomeDirectory() { public Path getHomeDirectory() {
return makeQualified(new Path(homeDirPrefix + "/" return makeQualified(DFSUtilClient.getHomeDirectory(getConf(), dfs.ugi));
+ dfs.ugi.getShortUserName()));
} }
/** /**

View File

@ -1205,9 +1205,8 @@ protected Response get(
return Response.ok(js).type(MediaType.APPLICATION_JSON).build(); return Response.ok(js).type(MediaType.APPLICATION_JSON).build();
} }
case GETHOMEDIRECTORY: { case GETHOMEDIRECTORY: {
final String js = JsonUtil.toJsonString("Path", String userHome = DFSUtilClient.getHomeDirectory(conf, ugi).toString();
FileSystem.get(conf != null ? conf : new Configuration()) final String js = JsonUtil.toJsonString("Path", userHome);
.getHomeDirectory().toUri().getPath());
return Response.ok(js).type(MediaType.APPLICATION_JSON).build(); return Response.ok(js).type(MediaType.APPLICATION_JSON).build();
} }
case GETACLSTATUS: { case GETACLSTATUS: {