@Test public void testConnectToDatanodeFailed() throws IOException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InterruptedException, NoSuchFieldException { Field xceiverServerDaemonField = DataNode.class.getDeclaredField("dataXceiverServer"); xceiverServerDaemonField.setAccessible(true); Class<?> xceiverServerClass = Class.forName("org.apache.hadoop.hdfs.server.datanode.DataXceiverServer"); Method numPeersMethod = xceiverServerClass.getDeclaredMethod("getNumPeers"); numPeersMethod.setAccessible(true); // make one datanode broken DataNodeProperties dnProp = TEST_UTIL.getDFSCluster().stopDataNode(0); Path f = new Path("/test"); EventLoop eventLoop = EVENT_LOOP_GROUP.next(); try (FanOutOneBlockAsyncDFSOutput output = FanOutOneBlockAsyncDFSOutputHelper.createOutput(FS, f, true, false, (short) 3, FS.getDefaultBlockSize(), eventLoop, CHANNEL_CLASS)) { // should exclude the dead dn when retry so here we only have 2 DNs in pipeline assertEquals(2, output.getPipeline().length); } finally { TEST_UTIL.getDFSCluster().restartDataNode(dnProp); } }
UTIL.getDFSCluster().stopDataNode(0); assertEquals(2, UTIL.getDFSCluster().getDataNodes().size());
@Test(expected=RuntimeException.class) public void testWalAbortOnLowReplication() throws Exception { setupDFS(); assertEquals(3, UTIL.getDFSCluster().getDataNodes().size()); LOG.info("Stop DataNode"); UTIL.getDFSCluster().stopDataNode(0); assertEquals(2, UTIL.getDFSCluster().getDataNodes().size()); store.insert(new TestProcedure(1, -1), null); for (long i = 2; store.isRunning(); ++i) { assertEquals(2, UTIL.getDFSCluster().getDataNodes().size()); store.insert(new TestProcedure(i, -1), null); Thread.sleep(100); } assertFalse(store.isRunning()); }
for (int i = allNodes.size() - 1; i >= 0; i--) { if (existingNodes.contains(allNodes.get(i))) { dfsCluster.stopDataNode(i); assertTrue(dfsCluster.stopDataNode(pipeline[0].getName()) != null); assertTrue(dfsCluster.stopDataNode(pipeline[1].getName()) != null);
@Test public void testLogRollOnDatanodeDeath() throws IOException, InterruptedException { dfsCluster.startDataNodes(TEST_UTIL.getConfiguration(), 3, true, null, null); tableName = getName(); Table table = createTestTable(tableName); TEST_UTIL.waitUntilAllRegionsAssigned(table.getName()); doPut(table, 1); server = TEST_UTIL.getRSForFirstRegionInTable(table.getName()); RegionInfo hri = server.getRegions(table.getName()).get(0).getRegionInfo(); AsyncFSWAL wal = (AsyncFSWAL) server.getWAL(hri); int numRolledLogFiles = AsyncFSWALProvider.getNumRolledLogFiles(wal); DatanodeInfo[] dnInfos = wal.getPipeline(); DataNodeProperties dnProp = TEST_UTIL.getDFSCluster().stopDataNode(dnInfos[0].getName()); TEST_UTIL.getDFSCluster().restartDataNode(dnProp); doPut(table, 2); assertEquals(numRolledLogFiles + 1, AsyncFSWALProvider.getNumRolledLogFiles(wal)); } }
public synchronized DataNodeProperties stopDataNode(String name) { int i; for (i = 0; i < dataNodes.size(); i++) { DataNode dn = dataNodes.get(i).datanode; if (dn.dnRegistration.getName().equals(name)) { break; } } return stopDataNode(i); }
public synchronized boolean restartDataNode(int i, boolean keepPort) throws IOException { DataNodeProperties dnprop = stopDataNode(i); if (dnprop == null) { return false; } else { return restartDataNode(dnprop, keepPort); } }
@Test public void testExcludedNodes() throws IOException { Configuration conf = new HdfsConfiguration(); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(3).build(); FileSystem fs = cluster.getFileSystem(); Path filePath = new Path("/testExcludedNodes"); // kill a datanode cluster.stopDataNode(AppendTestUtil.nextInt(3)); OutputStream out = fs.create(filePath, true, 4096); out.write(20); try { out.close(); } catch (Exception e) { fail("DataNode failure should not result in a block abort: \n" + e.getMessage()); } }
public synchronized DataNodeProperties stopDataNode(String dnName) { int node = -1; for (int i = 0; i < dataNodes.size(); i++) { DataNode dn = dataNodes.get(i).datanode; LOG.info("DN name=" + dnName + " found DN=" + dn + " with name=" + dn.getDisplayName()); if (dnName.equals(dn.getDatanodeId().getXferAddr())) { node = i; break; } } return stopDataNode(node); }
private static boolean wipeAndRestartDn(MiniDFSCluster cluster, int dnIndex) throws IOException { // stop the DN, reformat it, then start it again with the same xfer port. DataNodeProperties dnProps = cluster.stopDataNode(dnIndex); cluster.formatDataNodeDirs(); return cluster.restartDataNode(dnProps, true); }
/** * Restart a particular DataNode. * @param idn index of the DataNode * @param keepPort true if should restart on the same port * @param expireOnNN true if NameNode should expire the DataNode heartbeat * @return * @throws IOException */ public synchronized boolean restartDataNode( int idn, boolean keepPort, boolean expireOnNN) throws IOException { DataNodeProperties dnprop = stopDataNode(idn); if(expireOnNN) { setDataNodeDead(dnprop.datanode.getDatanodeId()); } if (dnprop == null) { return false; } else { return restartDataNode(dnprop, keepPort); } }
@Test public void testConnectToDatanodeFailed() throws IOException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InterruptedException, NoSuchFieldException { Field xceiverServerDaemonField = DataNode.class.getDeclaredField("dataXceiverServer"); xceiverServerDaemonField.setAccessible(true); Class<?> xceiverServerClass = Class.forName("org.apache.hadoop.hdfs.server.datanode.DataXceiverServer"); Method numPeersMethod = xceiverServerClass.getDeclaredMethod("getNumPeers"); numPeersMethod.setAccessible(true); // make one datanode broken DataNodeProperties dnProp = TEST_UTIL.getDFSCluster().stopDataNode(0); Path f = new Path("/test"); EventLoop eventLoop = EVENT_LOOP_GROUP.next(); try (FanOutOneBlockAsyncDFSOutput output = FanOutOneBlockAsyncDFSOutputHelper.createOutput(FS, f, true, false, (short) 3, FS.getDefaultBlockSize(), eventLoop, CHANNEL_CLASS)) { // should exclude the dead dn when retry so here we only have 2 DNs in pipeline assertEquals(2, output.getPipeline().length); } finally { TEST_UTIL.getDFSCluster().restartDataNode(dnProp); } }
@Test(timeout=60000) public void testExcludedNodes() throws IOException { cluster = new MiniDFSCluster.Builder(conf).numDataNodes(3).build(); FileSystem fs = cluster.getFileSystem(); Path filePath = new Path("/testExcludedNodes"); // kill a datanode cluster.stopDataNode(AppendTestUtil.nextInt(3)); OutputStream out = fs.create( filePath, true, 4096, (short) 3, fs.getDefaultBlockSize(filePath) ); out.write(20); try { out.close(); } catch (Exception e) { fail("Single DN failure should not result in a block abort: \n" + e.getMessage()); } }
private void rollbackRollingUpgrade() throws Exception { // Shutdown datanodes and namenodes // Restart the namenode with rolling upgrade rollback LOG.info("Starting rollback of the rolling upgrade"); MiniDFSCluster.DataNodeProperties dnprop = cluster.stopDataNode(0); dnprop.setDnArgs("-rollback"); cluster.shutdownNameNodes(); cluster.restartNameNode("-rollingupgrade", "rollback"); cluster.restartDataNode(dnprop); cluster.waitActive(); nn = cluster.getNameNode(0); dn0 = cluster.getDataNodes().get(0); triggerHeartBeats(); LOG.info("The cluster is active after rollback"); }
@Test(expected=RuntimeException.class) public void testWalAbortOnLowReplication() throws Exception { setupDFS(); assertEquals(3, UTIL.getDFSCluster().getDataNodes().size()); LOG.info("Stop DataNode"); UTIL.getDFSCluster().stopDataNode(0); assertEquals(2, UTIL.getDFSCluster().getDataNodes().size()); store.insert(new TestProcedure(1, -1), null); for (long i = 2; store.isRunning(); ++i) { assertEquals(2, UTIL.getDFSCluster().getDataNodes().size()); store.insert(new TestProcedure(i, -1), null); Thread.sleep(100); } assertFalse(store.isRunning()); }
private static void rollbackRollingUpgrade(Path foo, Path bar, Path file, byte[] data, MiniDFSCluster cluster) throws IOException { final DataNodeProperties dnprop = cluster.stopDataNode(0); cluster.restartNameNode("-rollingUpgrade", "rollback"); cluster.restartDataNode(dnprop, true); final DistributedFileSystem dfs = cluster.getFileSystem(); Assert.assertTrue(dfs.exists(foo)); Assert.assertFalse(dfs.exists(bar)); AppendTestUtil.checkFullFile(dfs, file, data.length, data); }
/** * Make sure that when we transition to active in safe mode that we don't * prematurely consider blocks missing just because not all DNs have reported * yet. * * This is a regression test for HDFS-3921. */ @Test public void testNoPopulatingReplQueuesWhenStartingActiveInSafeMode() throws IOException { DFSTestUtil.createFile(fs, new Path("/test"), 15*BLOCK_SIZE, (short)3, 1L); // Stop the DN so that when the NN restarts not all blocks wil be reported // and the NN won't leave safe mode. cluster.stopDataNode(1); // Restart the namenode but don't wait for it to hear from all DNs (since // one DN is deliberately shut down.) cluster.restartNameNode(0, false); cluster.transitionToActive(0); assertTrue(cluster.getNameNode(0).isInSafeMode()); // We shouldn't yet consider any blocks "missing" since we're in startup // safemode, i.e. not all DNs may have reported. assertEquals(0, cluster.getNamesystem(0).getMissingBlocksCount()); }
@Test(timeout = 600000) public void testDatanodeRUwithRegularUpgrade() throws Exception { try { startCluster(); rollingUpgradeAndFinalize(); DataNodeProperties dn = cluster.stopDataNode(0); cluster.restartNameNode(0, true, "-upgrade"); cluster.restartDataNode(dn, true); cluster.waitActive(); fs = cluster.getFileSystem(0); Path testFile3 = new Path("/" + GenericTestUtils.getMethodName() + ".03.dat"); DFSTestUtil.createFile(fs, testFile3, FILE_SIZE, REPL_FACTOR, SEED); cluster.getFileSystem().finalizeUpgrade(); } finally { shutdownCluster(); } }
/** * Reformatted DataNodes will replace the original UUID in the * {@link DatanodeManager#datanodeMap}. This tests if block * invalidation work on the original DataNode can be skipped. */ @Test(timeout=120000) public void testDatanodeReformat() throws Exception { namesystem.writeLock(); try { // Change the datanode UUID to emulate a reformat String poolId = cluster.getNamesystem().getBlockPoolId(); DatanodeRegistration dnr = cluster.getDataNode(nodes[0].getIpcPort()) .getDNRegistrationForBP(poolId); dnr = new DatanodeRegistration(UUID.randomUUID().toString(), dnr); cluster.stopDataNode(nodes[0].getXferAddr()); Block block = new Block(0, 0, GenerationStamp.LAST_RESERVED_STAMP); bm.addToInvalidates(block, nodes[0]); bm.getDatanodeManager().registerDatanode(dnr); // Since UUID has changed, the invalidation work should be skipped assertEquals(0, bm.computeInvalidateWork(1)); assertEquals(0, bm.getPendingDeletionBlocksCount()); } finally { namesystem.writeUnlock(); } }
@Test public void testLogRollOnDatanodeDeath() throws IOException, InterruptedException { dfsCluster.startDataNodes(TEST_UTIL.getConfiguration(), 3, true, null, null); tableName = getName(); Table table = createTestTable(tableName); TEST_UTIL.waitUntilAllRegionsAssigned(table.getName()); doPut(table, 1); server = TEST_UTIL.getRSForFirstRegionInTable(table.getName()); RegionInfo hri = server.getRegions(table.getName()).get(0).getRegionInfo(); AsyncFSWAL wal = (AsyncFSWAL) server.getWAL(hri); int numRolledLogFiles = AsyncFSWALProvider.getNumRolledLogFiles(wal); DatanodeInfo[] dnInfos = wal.getPipeline(); DataNodeProperties dnProp = TEST_UTIL.getDFSCluster().stopDataNode(dnInfos[0].getName()); TEST_UTIL.getDFSCluster().restartDataNode(dnProp); doPut(table, 2); assertEquals(numRolledLogFiles + 1, AsyncFSWALProvider.getNumRolledLogFiles(wal)); } }