|
@@ -29,6 +29,7 @@ import org.apache.hadoop.hdfs.DFSConfigKeys;
|
|
|
import org.apache.hadoop.hdfs.DFSUtil;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.NameNode;
|
|
|
+import org.apache.hadoop.hdfs.server.namenode.SecondaryNameNode;
|
|
|
import org.apache.hadoop.test.GenericTestUtils;
|
|
|
import org.junit.Test;
|
|
|
import org.mockito.Mockito;
|
|
@@ -39,16 +40,13 @@ import org.mockito.Mockito;
|
|
|
* which don't start daemons.
|
|
|
*/
|
|
|
public class TestHAConfiguration {
|
|
|
- private static final String NSID = "ns1";
|
|
|
- private static String HOST_A = "1.2.3.1";
|
|
|
- private static String HOST_B = "1.2.3.2";
|
|
|
|
|
|
private FSNamesystem fsn = Mockito.mock(FSNamesystem.class);
|
|
|
- private Configuration conf = new Configuration();
|
|
|
|
|
|
@Test
|
|
|
public void testCheckpointerValidityChecks() throws Exception {
|
|
|
try {
|
|
|
+ Configuration conf = new Configuration();
|
|
|
new StandbyCheckpointer(conf, fsn);
|
|
|
fail("Bad config did not throw an error");
|
|
|
} catch (IllegalArgumentException iae) {
|
|
@@ -56,30 +54,37 @@ public class TestHAConfiguration {
|
|
|
"Invalid URI for NameNode address", iae);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- @Test
|
|
|
- public void testGetOtherNNHttpAddress() {
|
|
|
- conf.set(DFSConfigKeys.DFS_FEDERATION_NAMESERVICES, NSID);
|
|
|
- conf.set(DFSConfigKeys.DFS_FEDERATION_NAMESERVICE_ID, NSID);
|
|
|
+
|
|
|
+ private Configuration getHAConf(String nsId, String host1, String host2) {
|
|
|
+ Configuration conf = new Configuration();
|
|
|
+ conf.set(DFSConfigKeys.DFS_FEDERATION_NAMESERVICES, nsId);
|
|
|
conf.set(DFSUtil.addKeySuffixes(
|
|
|
- DFSConfigKeys.DFS_HA_NAMENODES_KEY_PREFIX, NSID),
|
|
|
+ DFSConfigKeys.DFS_HA_NAMENODES_KEY_PREFIX, nsId),
|
|
|
"nn1,nn2");
|
|
|
conf.set(DFSConfigKeys.DFS_HA_NAMENODE_ID_KEY, "nn1");
|
|
|
conf.set(DFSUtil.addKeySuffixes(
|
|
|
- DFSConfigKeys.DFS_NAMENODE_RPC_ADDRESS_KEY,
|
|
|
- NSID, "nn1"),
|
|
|
- HOST_A + ":12345");
|
|
|
+ DFSConfigKeys.DFS_NAMENODE_RPC_ADDRESS_KEY, nsId, "nn1"),
|
|
|
+ host1 + ":12345");
|
|
|
conf.set(DFSUtil.addKeySuffixes(
|
|
|
- DFSConfigKeys.DFS_NAMENODE_RPC_ADDRESS_KEY,
|
|
|
- NSID, "nn2"),
|
|
|
- HOST_B + ":12345");
|
|
|
- NameNode.initializeGenericKeys(conf, NSID, "nn1");
|
|
|
+ DFSConfigKeys.DFS_NAMENODE_RPC_ADDRESS_KEY, nsId, "nn2"),
|
|
|
+ host2 + ":12345");
|
|
|
+ return conf;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testGetOtherNNHttpAddress() {
|
|
|
+ // Use non-local addresses to avoid host address matching
|
|
|
+ Configuration conf = getHAConf("ns1", "1.2.3.1", "1.2.3.2");
|
|
|
+ conf.set(DFSConfigKeys.DFS_FEDERATION_NAMESERVICE_ID, "ns1");
|
|
|
+
|
|
|
+ // This is done by the NN before the StandbyCheckpointer is created
|
|
|
+ NameNode.initializeGenericKeys(conf, "ns1", "nn1");
|
|
|
|
|
|
// Since we didn't configure the HTTP address, and the default is
|
|
|
- // 0.0.0.0, it should substitute the address from the RPC configuratoin
|
|
|
+ // 0.0.0.0, it should substitute the address from the RPC configuration
|
|
|
// above.
|
|
|
StandbyCheckpointer checkpointer = new StandbyCheckpointer(conf, fsn);
|
|
|
- assertEquals(HOST_B + ":" + DFSConfigKeys.DFS_NAMENODE_HTTP_PORT_DEFAULT,
|
|
|
+ assertEquals("1.2.3.2:" + DFSConfigKeys.DFS_NAMENODE_HTTP_PORT_DEFAULT,
|
|
|
checkpointer.getActiveNNAddress());
|
|
|
}
|
|
|
|
|
@@ -89,14 +94,33 @@ public class TestHAConfiguration {
|
|
|
*/
|
|
|
@Test
|
|
|
public void testHAUniqueEditDirs() throws IOException {
|
|
|
- Configuration config = new Configuration();
|
|
|
+ Configuration conf = new Configuration();
|
|
|
|
|
|
- config.set(DFS_NAMENODE_EDITS_DIR_KEY, "file://edits/dir, "
|
|
|
+ conf.set(DFS_NAMENODE_EDITS_DIR_KEY, "file://edits/dir, "
|
|
|
+ "file://edits/shared/dir"); // overlapping
|
|
|
- config.set(DFS_NAMENODE_SHARED_EDITS_DIR_KEY, "file://edits/shared/dir");
|
|
|
+ conf.set(DFS_NAMENODE_SHARED_EDITS_DIR_KEY, "file://edits/shared/dir");
|
|
|
|
|
|
// getNamespaceEditsDirs removes duplicates across edits and shared.edits
|
|
|
- Collection<URI> editsDirs = FSNamesystem.getNamespaceEditsDirs(config);
|
|
|
+ Collection<URI> editsDirs = FSNamesystem.getNamespaceEditsDirs(conf);
|
|
|
assertEquals(2, editsDirs.size());
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Test that the 2NN does not start if given a config with HA NNs.
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void testSecondaryNameNodeDoesNotStart() throws IOException {
|
|
|
+ // Note we're not explicitly setting the nameservice Id in the
|
|
|
+ // config as it is not required to be set and we want to test
|
|
|
+ // that we can determine if HA is enabled when the nameservice Id
|
|
|
+ // is not explicitly defined.
|
|
|
+ Configuration conf = getHAConf("ns1", "1.2.3.1", "1.2.3.2");
|
|
|
+ try {
|
|
|
+ new SecondaryNameNode(conf);
|
|
|
+ fail("Created a 2NN with an HA config");
|
|
|
+ } catch (IOException ioe) {
|
|
|
+ GenericTestUtils.assertExceptionContains(
|
|
|
+ "Cannot use SecondaryNameNode in an HA cluster", ioe);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|