HDFS-7553. fix the TestDFSUpgradeWithHA due to BindException. Contributed by Xiao Chen.

(cherry picked from commit 1f8162b74e)
This commit is contained in:
cnauroth 2015-12-29 10:56:59 -08:00
parent 2139458a98
commit 6d9f210c4d
5 changed files with 46 additions and 10 deletions

View File

@ -1626,6 +1626,9 @@ Release 2.8.0 - UNRELEASED
HDFS-9458. TestBackupNode always binds to port 50070, which can cause bind
failures. (Xiao Chen via cnauroth)
HDFS-7553. fix the TestDFSUpgradeWithHA due to BindException.
(Xiao Chen via cnauroth)
Release 2.7.3 - UNRELEASED
INCOMPATIBLE CHANGES

View File

@ -1022,6 +1022,22 @@ public class NameNode implements NameNodeStatusMXBean {
return httpServer.getHttpsAddress();
}
/**
* @return NameNodeHttpServer, used by unit tests to ensure a full shutdown,
* so that no bind exception is thrown during restart.
*/
@VisibleForTesting
public void joinHttpServer() {
if (httpServer != null) {
try {
httpServer.join();
} catch (InterruptedException e) {
LOG.info("Caught InterruptedException joining NameNodeHttpServer", e);
Thread.currentThread().interrupt();
}
}
}
/**
* Verify that configured directories exist, then
* Interactively confirm that formatting is desired

View File

@ -195,6 +195,15 @@ public class NameNodeHttpServer {
return params;
}
/**
* Joins the httpserver.
*/
public void join() throws InterruptedException {
if (httpServer != null) {
httpServer.join();
}
}
void stop() throws Exception {
if (httpServer != null) {
httpServer.stop();

View File

@ -1805,12 +1805,7 @@ public class MiniDFSCluster {
shutdownDataNodes();
for (NameNodeInfo nnInfo : nameNodes) {
if (nnInfo == null) continue;
NameNode nameNode = nnInfo.nameNode;
if (nameNode != null) {
nameNode.stop();
nameNode.join();
nameNode = null;
}
stopAndJoinNameNode(nnInfo.nameNode);
}
ShutdownHookManager.get().clearShutdownHooks();
if (base_dir != null) {
@ -1851,14 +1846,25 @@ public class MiniDFSCluster {
public synchronized void shutdownNameNode(int nnIndex) {
NameNode nn = nameNodes[nnIndex].nameNode;
if (nn != null) {
LOG.info("Shutting down the namenode");
nn.stop();
nn.join();
stopAndJoinNameNode(nn);
Configuration conf = nameNodes[nnIndex].conf;
nameNodes[nnIndex] = new NameNodeInfo(null, null, null, null, conf);
}
}
/**
* Fully stop the NameNode by stop and join.
*/
private void stopAndJoinNameNode(NameNode nn) {
if (nn == null) {
return;
}
LOG.info("Shutting down the namenode");
nn.stop();
nn.join();
nn.joinHttpServer();
}
/**
* Restart all namenodes.
*/

View File

@ -459,6 +459,7 @@ public class TestStartup {
nnRpc.saveNamespace();
namenode.stop();
namenode.join();
namenode.joinHttpServer();
// compress image using default codec
LOG.info("Read an uncomressed image and store it compressed using default codec.");
@ -489,6 +490,7 @@ public class TestStartup {
nnRpc.saveNamespace();
namenode.stop();
namenode.join();
namenode.joinHttpServer();
}
@Test