/** * Ensure that the given NameNode marks the specified DataNode as entirely dead/expired. * * @param nn the NameNode to manipulate * @param dnName the name of the DataNode */ public static void noticeDeadDatanode(NameNode nn, String dnName) { FSNamesystem namesystem = nn.getNamesystem(); namesystem.writeLock(); try { DatanodeManager dnm = namesystem.getBlockManager().getDatanodeManager(); HeartbeatManager hbm = dnm.getHeartbeatManager(); DatanodeDescriptor[] dnds = hbm.getDatanodes(); DatanodeDescriptor theDND = null; for (DatanodeDescriptor dnd : dnds) { if (dnd.getXferAddr().equals(dnName)) { theDND = dnd; } } Assert.assertNotNull("Could not find DN with name: " + dnName, theDND); synchronized (hbm) { DFSTestUtil.setDatanodeDead(theDND); hbm.heartbeatCheck(); } } finally { namesystem.writeUnlock(); } }
/** * Stop decommissioning the specified datanode. * * @param node */ @VisibleForTesting public void stopDecommission(DatanodeDescriptor node) { if (node.isDecommissionInProgress() || node.isDecommissioned()) { // Update DN stats maintained by HeartbeatManager hbManager.stopDecommission(node); // Over-replicated blocks will be detected and processed when // the dead node comes back and send in its full block report. if (node.isAlive) { blockManager.processOverReplicatedBlocksOnReCommission(node); } // Remove from tracking in DecommissionManager pendingNodes.remove(node); decomNodeBlocks.remove(node); } else { LOG.trace("stopDecommission: Node {} in {}, nothing to do." + node, node.getAdminState()); } }
/** * Start decommissioning the specified datanode. * * @param node */ @VisibleForTesting public void startDecommission(DatanodeDescriptor node) { if (!node.isDecommissionInProgress() && !node.isDecommissioned()) { // Update DN stats maintained by HeartbeatManager hbManager.startDecommission(node); // hbManager.startDecommission will set dead node to decommissioned. if (node.isDecommissionInProgress()) { for (DatanodeStorageInfo storage : node.getStorageInfos()) { LOG.info( "Starting decommission of {} {} with {} blocks", node, storage, storage.numBlocks()); } node.decommissioningStatus.setStartTime(monotonicNow()); pendingNodes.add(node); } } else { LOG.trace("startDecommission: Node {} in {}, nothing to do." + node, node.getAdminState()); } }
@Test public void testHeartbeatStopWatch() throws Exception { Namesystem ns = Mockito.mock(Namesystem.class); BlockManager bm = Mockito.mock(BlockManager.class); Configuration conf = new Configuration(); long recheck = 2000; conf.setLong(DFSConfigKeys.DFS_NAMENODE_HEARTBEAT_RECHECK_INTERVAL_KEY, recheck); HeartbeatManager monitor = new HeartbeatManager(ns, bm, conf); monitor.restartHeartbeatStopWatch(); assertFalse(monitor.shouldAbortHeartbeatCheck(0)); // sleep shorter than recheck and verify shouldn't abort Thread.sleep(100); assertFalse(monitor.shouldAbortHeartbeatCheck(0)); // sleep longer than recheck and verify should abort unless ignore delay Thread.sleep(recheck); assertTrue(monitor.shouldAbortHeartbeatCheck(0)); assertFalse(monitor.shouldAbortHeartbeatCheck(-recheck * 3)); // ensure it resets properly monitor.restartHeartbeatStopWatch(); assertFalse(monitor.shouldAbortHeartbeatCheck(0)); }
public void run() { while (Server.leaderNode == HeartbeatManager.nodeId) { if (queue.isEmpty()) { continue; } else { String node = queue.poll(); if (node == HeartbeatManager.nodeId) HeartbeatListener.leadack = 1; else HeartbeatManager.broadcast(node, "1"); System.out.println("Lead ack sent"); while (HeartbeatListener.leadack != 2) { continue; } System.out.println("Lead complete"); } } }