测试

来源:互联网 发布:mac手写输入法怎么取消 编辑:程序博客网 时间:2024/05/16 15:00
<div></div><pre name="code" class="java">Java code?12345678910111213141516171819202122232425262728293031323334353637383940414243void 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));  }

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) { } } } }

0 0
原创粉丝点击