-------------------再来看看NameNode端-------------------
public DatanodeCommand[] sendHeartbeat(DatanodeRegistration nodeReg,
long capacity,
long dfSUSEd,
long remaining,
int xmitsInProgress,
int xceiverCount) throws IOException {
verifyRequest(nodeReg);
return namesystem.handleHeartbeat(nodeReg, capacity, dfsUsed, remaining,
xceiverCount, xmitsInProgress);
}
最终是由namesystem来处理的,二namesystem就是FSNamesystem的一个实例(在NameNode.java中public FSNamesystem namesystem; )
FSNamesystem处理完后返回一个an array of datanode commands 交由DataNode处理,
另外:
/**
* Periodically calls heartbeatCheck().
*/
class HeartbeatMonitor implements Runnable {
/**
*/
public void run() {
while (fsRunning) {
try {
heartbeatCheck();
} catch (Exception e) {
FSNamesystem.LOG.error(StringUtils.stringifyException(e));
}
try {
Thread.sleep(heartbeatRecheckInterval);
} catch (InterruptedException ie) {
}
}
}
}
其中的HeartbeatMonitor 处理失效的DataNode,将其移除removeDatanode(nodeInfo);