diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HealthMonitor.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HealthMonitor.java index 753352945d..a349626ece 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HealthMonitor.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HealthMonitor.java @@ -22,6 +22,7 @@ import java.util.LinkedList; import java.util.List; +import org.apache.hadoop.classification.InterfaceAudience; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; @@ -43,7 +44,8 @@ * Classes which need callbacks should implement the {@link Callback} * interface. */ -class HealthMonitor { +@InterfaceAudience.Private +public class HealthMonitor { private static final Log LOG = LogFactory.getLog( HealthMonitor.class); @@ -75,7 +77,8 @@ class HealthMonitor { private HAServiceStatus lastServiceState = new HAServiceStatus( HAServiceState.INITIALIZING); - enum State { + @InterfaceAudience.Private + public enum State { /** * The health monitor is still starting up. */ diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/MiniZKFCCluster.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/MiniZKFCCluster.java index 76d273552d..1db792453a 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/MiniZKFCCluster.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/MiniZKFCCluster.java @@ -170,11 +170,7 @@ public void waitForHAState(int idx, HAServiceState state) */ public void waitForHealthState(int idx, State state) throws Exception { - ZKFailoverController zkfc = thrs[idx].zkfc; - while (zkfc.getLastHealthState() != state) { - ctx.checkException(); - Thread.sleep(50); - } + ZKFCTestUtil.waitForHealthState(thrs[idx].zkfc, state, ctx); } /** diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/ZKFCTestUtil.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/ZKFCTestUtil.java new file mode 100644 index 0000000000..4a5eacd4ba --- /dev/null +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/ZKFCTestUtil.java @@ -0,0 +1,34 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.ha; + +import org.apache.hadoop.test.MultithreadedTestUtil; + +public class ZKFCTestUtil { + + public static void waitForHealthState(ZKFailoverController zkfc, + HealthMonitor.State state, + MultithreadedTestUtil.TestContext ctx) throws Exception { + while (zkfc.getLastHealthState() != state) { + if (ctx != null) { + ctx.checkException(); + } + Thread.sleep(50); + } + } +} diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-3042.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-3042.txt index 678766cbdd..394064f36e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-3042.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-3042.txt @@ -15,3 +15,5 @@ HDFS-3261. TestHASafeMode fails on HDFS-3042 branch (todd) HDFS-3159. Document NN auto-failover setup and configuration (todd) HDFS-3412. Fix findbugs warnings in auto-HA branch (todd) + +HDFS-3432. TestDFSZKFailoverController tries to fail over too early (todd) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestDFSZKFailoverController.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestDFSZKFailoverController.java index d1d1991218..52e136940d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestDFSZKFailoverController.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestDFSZKFailoverController.java @@ -26,6 +26,8 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.ha.ClientBaseWithFixes; +import org.apache.hadoop.ha.HealthMonitor; +import org.apache.hadoop.ha.ZKFCTestUtil; import org.apache.hadoop.ha.ZKFailoverController; import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState; import org.apache.hadoop.ha.TestNodeFencer.AlwaysSucceedFencer; @@ -91,6 +93,12 @@ public void setup() throws Exception { ctx.addThread(thr2 = new ZKFCThread(ctx, 1)); thr2.start(); + // Wait for the ZKFCs to fully start up + ZKFCTestUtil.waitForHealthState(thr1.zkfc, + HealthMonitor.State.SERVICE_HEALTHY, ctx); + ZKFCTestUtil.waitForHealthState(thr2.zkfc, + HealthMonitor.State.SERVICE_HEALTHY, ctx); + fs = HATestUtil.configureFailoverFs(cluster, conf); } @@ -160,10 +168,12 @@ public void testManualFailover() throws Exception { public void testManualFailoverWithDFSHAAdmin() throws Exception { DFSHAAdmin tool = new DFSHAAdmin(); tool.setConf(conf); - tool.run(new String[]{"-failover", "nn1", "nn2"}); + assertEquals(0, + tool.run(new String[]{"-failover", "nn1", "nn2"})); waitForHAState(0, HAServiceState.STANDBY); waitForHAState(1, HAServiceState.ACTIVE); - tool.run(new String[]{"-failover", "nn2", "nn1"}); + assertEquals(0, + tool.run(new String[]{"-failover", "nn2", "nn1"})); waitForHAState(0, HAServiceState.ACTIVE); waitForHAState(1, HAServiceState.STANDBY); }