|
@@ -17,6 +17,7 @@
|
|
|
*/
|
|
|
package org.apache.hadoop.hdfs.server.namenode.ha;
|
|
|
|
|
|
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_OBSERVER_ENABLED_KEY;
|
|
|
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_STATE_CONTEXT_ENABLED_KEY;
|
|
|
import static org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter.getServiceState;
|
|
|
import static org.apache.hadoop.hdfs.server.namenode.ha.ObserverReadProxyProvider.*;
|
|
@@ -215,6 +216,65 @@ public class TestObserverNode {
|
|
|
assertSentTo(0);
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testConfigStartup() throws Exception {
|
|
|
+ int nnIdx = dfsCluster.getNumNameNodes() - 1;
|
|
|
+
|
|
|
+ // Transition all current observers to standby
|
|
|
+ for (int i = 0; i < dfsCluster.getNumNameNodes(); i++) {
|
|
|
+ if (dfsCluster.getNameNode(i).isObserverState()) {
|
|
|
+ dfsCluster.transitionToStandby(i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Confirm that the namenode at nnIdx is standby
|
|
|
+ assertTrue("The NameNode is observer despite being transitioned to standby",
|
|
|
+ dfsCluster.getNameNode(nnIdx).isStandbyState());
|
|
|
+
|
|
|
+ // Restart the NameNode with observer startup option as false
|
|
|
+ dfsCluster.getConfiguration(nnIdx)
|
|
|
+ .setBoolean(DFS_NAMENODE_OBSERVER_ENABLED_KEY, false);
|
|
|
+ dfsCluster.restartNameNode(nnIdx);
|
|
|
+
|
|
|
+ // Verify that the NameNode is not in Observer state
|
|
|
+ dfsCluster.waitNameNodeUp(nnIdx);
|
|
|
+ assertTrue("The NameNode started as Observer despite "
|
|
|
+ + DFS_NAMENODE_OBSERVER_ENABLED_KEY + " being false",
|
|
|
+ dfsCluster.getNameNode(nnIdx).isStandbyState());
|
|
|
+
|
|
|
+ dfs.mkdir(testPath, FsPermission.getDefault());
|
|
|
+ assertSentTo(0);
|
|
|
+
|
|
|
+ // The first request goes to the active because it has not refreshed yet;
|
|
|
+ // the second would go to the observer if it was not in standby
|
|
|
+ dfsCluster.rollEditLogAndTail(0);
|
|
|
+ dfs.getFileStatus(testPath);
|
|
|
+ dfs.getFileStatus(testPath);
|
|
|
+ assertSentTo(0);
|
|
|
+
|
|
|
+ Path testPath2 = new Path(testPath, "test2");
|
|
|
+ // Restart the NameNode with the observer startup option as true
|
|
|
+ dfsCluster.getConfiguration(nnIdx)
|
|
|
+ .setBoolean(DFS_NAMENODE_OBSERVER_ENABLED_KEY, true);
|
|
|
+ dfsCluster.restartNameNode(nnIdx);
|
|
|
+
|
|
|
+ // Check that the NameNode is in Observer state
|
|
|
+ dfsCluster.waitNameNodeUp(nnIdx);
|
|
|
+ assertTrue("The NameNode did not start as Observer despite "
|
|
|
+ + DFS_NAMENODE_OBSERVER_ENABLED_KEY + " being true",
|
|
|
+ dfsCluster.getNameNode(nnIdx).isObserverState());
|
|
|
+
|
|
|
+ dfs.mkdir(testPath2, FsPermission.getDefault());
|
|
|
+ assertSentTo(0);
|
|
|
+
|
|
|
+ // The first request goes to the active because it has not refreshed yet;
|
|
|
+ // the second will properly go to the observer
|
|
|
+ dfsCluster.rollEditLogAndTail(0);
|
|
|
+ dfs.getFileStatus(testPath2);
|
|
|
+ dfs.getFileStatus(testPath2);
|
|
|
+ assertSentTo(nnIdx);
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testFailover() throws Exception {
|
|
|
Path testPath2 = new Path(testPath, "test2");
|