diff --git a/hadoop-common-project/hadoop-common/CHANGES.HDFS-3042.txt b/hadoop-common-project/hadoop-common/CHANGES.HDFS-3042.txt index bb171adb8e..8bf3d88c9a 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.HDFS-3042.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.HDFS-3042.txt @@ -25,3 +25,5 @@ HADOOP-8306. ZKFC: improve error message when ZK is not running. (todd) HADOOP-8279. Allow manual failover to be invoked when auto-failover is enabled. (todd) HADOOP-8276. Auto-HA: add config for java options to pass to zkfc daemon (todd via eli) + +HADOOP-8405. ZKFC tests leak ZK instances. (todd) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ActiveStandbyElector.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ActiveStandbyElector.java index 2081755fbf..a4ed255deb 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ActiveStandbyElector.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ActiveStandbyElector.java @@ -717,11 +717,20 @@ private boolean reEstablishSession() { } private void createConnection() throws IOException { + if (zkClient != null) { + try { + zkClient.close(); + } catch (InterruptedException e) { + throw new IOException("Interrupted while closing ZK", + e); + } + zkClient = null; + } zkClient = getNewZooKeeper(); LOG.debug("Created new connection for " + this); } - private void terminateConnection() { + void terminateConnection() { if (zkClient == null) { return; } diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ZKFailoverController.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ZKFailoverController.java index 7b423d3b67..c02fe0d163 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ZKFailoverController.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ZKFailoverController.java @@ -163,6 +163,10 @@ public Integer run() { return doRun(args); } catch (Exception t) { throw new RuntimeException(t); + } finally { + if (elector != null) { + elector.terminateConnection(); + } } } });