阿短发的

来源:互联网 发布:网络新手游 编辑:程序博客网 时间:2024/04/27 20:52
void heartbeatCheck() {    boolean allAlive = false;    while (!allAlive) {      boolean foundDead = false;      DatanodeID nodeID = null;      // locate the first dead node.      synchronized(heartbeats) {        for (Iterator<DatanodeDescriptor> it = heartbeats.iterator();it.hasNext();) {          DatanodeDescriptor nodeInfo = it.next();          if (isDatanodeDead(nodeInfo)) {                        foundDead = true;            nodeID = nodeInfo;            break;          }        }      }      // acquire the fsnamesystem lock, and then remove the dead node.      if (foundDead) {        synchronized (this) {          synchronized(heartbeats) {            synchronized (datanodeMap) {              DatanodeDescriptor nodeInfo = null;              try {                nodeInfo = getDatanode(nodeID);              } catch (IOException e) {                nodeInfo = null;              }              if (nodeInfo != null && isDatanodeDead(nodeInfo)) {                NameNode.stateChangeLog.info("BLOCK* NameSystem.heartbeatCheck: " + "lost heartbeat from " + nodeInfo.getName());                removeDatanode(nodeInfo);//清除与该数据节点相关的数据信息              }            }          }        }      }      allAlive = !foundDead;    }private boolean isDatanodeDead(DatanodeDescriptor node) {    return (node.getLastUpdate() < (now() - heartbeatExpireInterval));  }

0 0