this.heartbeatManager = new HeartbeatManager(namesystem, blockManager, conf); this.datanodeAdminManager = new DatanodeAdminManager(namesystem,
synchronized void register(final DatanodeDescriptor d) { if (!d.isAlive()) { addDatanode(d); //update its timestamp d.updateHeartbeatState(StorageReport.EMPTY_ARRAY, 0L, 0L, 0, 0, null); stats.add(d); } }
@Override public void run() { while(namesystem.isRunning()) { restartHeartbeatStopWatch(); try { final long now = Time.monotonicNow(); if (lastHeartbeatCheck + heartbeatRecheckInterval < now) { heartbeatCheck(); lastHeartbeatCheck = now; if (shouldAbortHeartbeatCheck(-5000)) { LOG.warn("Skipping next heartbeat scan due to excessive pause"); lastHeartbeatCheck = Time.monotonicNow();
@Override public synchronized long[] getStats() { return new long[] {getCapacityTotal(), getCapacityUsed(), getCapacityRemaining(), -1L, -1L, -1L, -1L, -1L, -1L}; }
@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)); } }
heartbeatManager.register(nodeS); incrementVersionCount(nodeS.getSoftwareVersion()); startAdminOperationIfNecessary(nodeS); heartbeatManager.addDatanode(nodeDescr); heartbeatManager.updateDnStat(nodeDescr); incrementVersionCount(nodeReg.getSoftwareVersion()); startAdminOperationIfNecessary(nodeDescr);
heartbeatManager.register(nodeS); incrementVersionCount(nodeS.getSoftwareVersion()); startDecommissioningIfExcluded(nodeS); heartbeatManager.addDatanode(nodeDescr); incrementVersionCount(nodeReg.getSoftwareVersion()); startDecommissioningIfExcluded(nodeDescr);
@Override public void run() { while(namesystem.isRunning()) { try { final long now = Time.monotonicNow(); if (lastHeartbeatCheck + heartbeatRecheckInterval < now) { heartbeatCheck(); lastHeartbeatCheck = now; } if (blockManager.shouldUpdateBlockKey(now - lastBlockKeyUpdate)) { synchronized(HeartbeatManager.this) { for(DatanodeDescriptor d : datanodes) { d.needKeyUpdate = true; } } lastBlockKeyUpdate = now; } } catch (Exception e) { LOG.error("Exception while checking heartbeat", e); } try { Thread.sleep(5000); // 5 seconds } catch (InterruptedException ie) { } } } }
/** * Call heartbeat check function of HeartbeatManager * @param bm the BlockManager to manipulate */ public static void checkHeartbeat(BlockManager bm) { HeartbeatManager hbm = bm.getDatanodeManager().getHeartbeatManager(); hbm.restartHeartbeatStopWatch(); hbm.heartbeatCheck(); }
/** * Whether stale datanodes should be avoided as targets on the write path. * The result of this function may change if the number of stale datanodes * eclipses a configurable threshold. * * @return whether stale datanodes should be avoided on the write path */ public boolean shouldAvoidStaleDataNodesForWrite() { // If # stale exceeds maximum staleness ratio, disable stale // datanode avoidance on the write path return avoidStaleDataNodesForWrite && (numStaleNodes <= heartbeatManager.getLiveDatanodeCount() * ratioUseStaleDataNodesForWrite); }
/** * 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(); } }
void close() { datanodeAdminManager.close(); heartbeatManager.close(); }
@Override public double getInServiceXceiverAverage() { double avgLoad = 0; final int nodes = getNumDatanodesInService(); if (nodes != 0) { final int xceivers = heartbeatManager .getInServiceXceiverCount(); avgLoad = (double)xceivers/nodes; } return avgLoad; } };
void activate(final Configuration conf) { datanodeAdminManager.activate(conf); heartbeatManager.activate(); }
@Override public synchronized long[] getStats() { return new long[] {getCapacityTotal(), getCapacityUsed(), getCapacityRemaining(), -1L, -1L, -1L, -1L}; }
heartbeatManager.register(nodeS); incrementVersionCount(nodeS.getSoftwareVersion()); startDecommissioningIfExcluded(nodeS); heartbeatManager.addDatanode(nodeDescr); incrementVersionCount(nodeReg.getSoftwareVersion()); startDecommissioningIfExcluded(nodeDescr);
/** * Call heartbeat check function of HeartbeatManager and get * under replicated blocks count within write lock to make sure * computeDatanodeWork doesn't interfere. * @param namesystem the FSNamesystem * @param bm the BlockManager to manipulate * @return the number of under replicated blocks */ public static int checkHeartbeatAndGetUnderReplicatedBlocksCount( FSNamesystem namesystem, BlockManager bm) { namesystem.writeLock(); try { bm.getDatanodeManager().getHeartbeatManager().heartbeatCheck(); return bm.getUnderReplicatedNotMissingBlocks(); } finally { namesystem.writeUnlock(); } }
final int numlive = heartbeatManager.getLiveDatanodeCount(); final int blocksToProcess = numlive * this.blocksReplWorkMultiplier;
void close() { decomManager.close(); heartbeatManager.close(); }
@Override public double getInServiceXceiverAverage() { double avgLoad = 0; final int nodes = getNumDatanodesInService(); if (nodes != 0) { final int xceivers = heartbeatManager .getInServiceXceiverCount(); avgLoad = (double)xceivers/nodes; } return avgLoad; } };