BackupNode extends NameNode { @Override public void stop() { if(checkpointManager != null) { checkpointManager.shouldRun = false; } if(namenode != null && getRegistration() != null) { try { namenode.errorReport(getRegistration(), NamenodeProtocol.FATAL, "Shutting down."); } catch(IOException e) { LOG.error("Failed to report to name-node.", e); } } if (namenode != null) { RPC.stopProxy(namenode); } namenode = null; if(checkpointManager != null) { checkpointManager.interrupt(); checkpointManager = null; } getFSImage().getEditLog().abortCurrentLogSegment(); super.stop(); } BackupNode(Configuration conf, NamenodeRole role); @Override // NameNode void stop(); boolean setSafeMode(SafeModeAction action);  }
@Test public void testCanReadData() throws IOException { Path file1 = new Path("/fileToRead.dat"); Configuration conf = new HdfsConfiguration(); MiniDFSCluster cluster = null; FileSystem fileSys = null; BackupNode backup = null; try { cluster = new MiniDFSCluster.Builder(conf) .numDataNodes(0).format(true).build(); fileSys = cluster.getFileSystem(); long txid = cluster.getNameNodeRpc().getTransactionID(); backup = startBackupNode(conf, StartupOption.BACKUP, 1); waitCheckpointDone(cluster, txid); String rpcAddrKeyPreffix = DFSConfigKeys.DFS_NAMENODE_RPC_ADDRESS_KEY + ".bnCluster"; String nnAddr = cluster.getNameNode().getNameNodeAddressHostPortString(); conf.get(DFSConfigKeys.DFS_NAMENODE_RPC_ADDRESS_KEY); String bnAddr = backup.getNameNodeAddressHostPortString(); conf.set(DFSConfigKeys.DFS_NAMESERVICES, "bnCluster"); conf.set(DFSConfigKeys.DFS_NAMESERVICE_ID, "bnCluster"); conf.set(DFSConfigKeys.DFS_HA_NAMENODES_KEY_PREFIX + ".bnCluster", "nnActive, nnBackup"); conf.set(rpcAddrKeyPreffix + ".nnActive", nnAddr); conf.set(rpcAddrKeyPreffix + ".nnBackup", bnAddr); cluster.startDataNodes(conf, 3, true, StartupOption.REGULAR, null); DFSTestUtil.createFile( fileSys, file1, 8192, (short)3, 0); FileSystem bnFS = FileSystem.get( new Path("hdfs: String nnData = DFSTestUtil.readFile(fileSys, file1); String bnData = DFSTestUtil.readFile(bnFS, file1); assertEquals("Data read from BackupNode and NameNode is not the same.", nnData, bnData); } catch(IOException e) { LOG.error("Error in TestBackupNode: ", e); assertTrue(e.getLocalizedMessage(), false); } finally { if(fileSys != null) fileSys.close(); if(backup != null) backup.stop(); if(cluster != null) cluster.shutdown(); } }