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

startDistributedUpgradeIfNeeded();
offerService();

这里还是如题说说心跳机制吧,心跳由DataNode发起,

心跳首先是由DataNode的一个线程开启的,一直循环调用 offerService();方法,DataNode在这个方法中发送心跳

while (shouldRun) {
try {
long startTime = now();


//
// Every so often, send heartbeat or block-report
//

if (startTime - lastHeartbeat > heartBeatInterval) {
//
// All heartbeat messages include following info:
// -- Datanode name
// -- data transfer port
// -- Total capacity
// -- Bytes remaining
//
lastHeartbeat = startTime;
DatanodeCommand[] cmds = namenode.sendHeartbeat(dnRegistration,
data.getCapacity(),
data.getDfSUSEd(),
data.getRemaining(),
xmitsInProgress.get(),
getXceiverCount());

myMetrics.heartbeats.inc(now() - startTime);
//LOG.info("Just sent heartbeat, with name " + localName);
if (!processCommand(cmds))
continue;
}

在这个方法中通过调用NameNode的RPC调用namenode.sendHeartbeat()发送心跳,之后就是处理返回的请求

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

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