Hadoop中DataNode与NameNode之间的心跳机制(3)

-------------------再来看看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);

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/204c7d4107a94d109ba99a03d8f8edb7.html