HDFS-4392. Merge 1433578 change from trunk

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1433579 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Suresh Srinivas 2013-01-15 18:50:33 +00:00
parent 44b3be14bc
commit 896c21ee69
2 changed files with 4 additions and 15 deletions

View File

@ -199,6 +199,9 @@ Release 2.0.3-alpha - Unreleased
HDFS-4375. Use token request messages defined in hadoop common.
(suresh)
HDFS-4392. Use NetUtils#getFreeSocketPort in MiniDFSCluster.
(Andrew Purtell via suresh)
OPTIMIZATIONS
HDFS-3429. DataNode reads checksums even if client does not need them (todd)

View File

@ -48,7 +48,6 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.io.RandomAccessFile;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.channels.FileChannel;
@ -2288,19 +2287,6 @@ public class MiniDFSCluster {
return nameNodes[nnIndex].nameNode;
}
private int getFreeSocketPort() {
int port = 0;
try {
ServerSocket s = new ServerSocket(0);
port = s.getLocalPort();
s.close();
return port;
} catch (IOException e) {
// Could not get a free port. Return default port 0.
}
return port;
}
private void setupDatanodeAddress(Configuration conf, boolean setupHostsFile,
boolean checkDataNodeAddrConfig) throws IOException {
if (setupHostsFile) {
@ -2309,7 +2295,7 @@ public class MiniDFSCluster {
throw new IOException("Parameter dfs.hosts is not setup in conf");
}
// Setup datanode in the include file, if it is defined in the conf
String address = "127.0.0.1:" + getFreeSocketPort();
String address = "127.0.0.1:" + NetUtils.getFreeSocketPort();
if (checkDataNodeAddrConfig) {
conf.setIfUnset(DFS_DATANODE_ADDRESS_KEY, address);
} else {