Skip to content

Commit

Permalink
[MINOR] Fix BindException when running tests of shared machines. (#2070)
Browse files Browse the repository at this point in the history
When unit tests are run on shared machines (e.g. jenkins cluster), the unit tests sometimes fail due to BindException in starting HDFS Cluster. This is because the port chosen may have been bound by another process using the same machine. The fix is to retry the port selection a few times.
  • Loading branch information
prashantwason authored Sep 8, 2020
1 parent 83e39e2 commit fe7c9e7
Showing 1 changed file with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import java.io.File;
import java.io.IOException;
import java.net.BindException;
import java.nio.file.Files;
import java.util.Objects;

Expand Down Expand Up @@ -72,20 +73,32 @@ public MiniDFSCluster start(boolean format) throws IOException {
FileIOUtils.deleteDirectory(file);
}

int namenodeRpcPort = NetworkTestUtils.nextFreePort();
int datanodePort = NetworkTestUtils.nextFreePort();
int datanodeIpcPort = NetworkTestUtils.nextFreePort();
int datanodeHttpPort = NetworkTestUtils.nextFreePort();

// Configure and start the HDFS cluster
// boolean format = shouldFormatDFSCluster(localDFSLocation, clean);
String bindIP = "127.0.0.1";
configureDFSCluster(hadoopConf, localDFSLocation, bindIP, namenodeRpcPort,
datanodePort, datanodeIpcPort, datanodeHttpPort);
miniDfsCluster = new MiniDFSCluster.Builder(hadoopConf).numDataNodes(1).format(format).checkDataNodeAddrConfig(true)
.checkDataNodeHostConfig(true).build();
LOG.info("HDFS Minicluster service started.");
return miniDfsCluster;
int loop = 0;
while (true) {
try {
int namenodeRpcPort = NetworkTestUtils.nextFreePort();
int datanodePort = NetworkTestUtils.nextFreePort();
int datanodeIpcPort = NetworkTestUtils.nextFreePort();
int datanodeHttpPort = NetworkTestUtils.nextFreePort();

// Configure and start the HDFS cluster
// boolean format = shouldFormatDFSCluster(localDFSLocation, clean);
String bindIP = "127.0.0.1";
configureDFSCluster(hadoopConf, localDFSLocation, bindIP, namenodeRpcPort,
datanodePort, datanodeIpcPort, datanodeHttpPort);
miniDfsCluster = new MiniDFSCluster.Builder(hadoopConf).numDataNodes(1).format(format).checkDataNodeAddrConfig(true)
.checkDataNodeHostConfig(true).build();
LOG.info("HDFS Minicluster service started.");
return miniDfsCluster;
} catch (BindException ex) {
++loop;
if (loop < 5) {
stop();
} else {
throw ex;
}
}
}
}

public void stop() {
Expand Down

0 comments on commit fe7c9e7

Please sign in to comment.