private ActiveNodeProtos.ActiveNodeProto convertANToResponseProto(ActiveNode p) {
   ActiveNodeProtos.ActiveNodeProto.Builder anp = ActiveNodeProtos.ActiveNodeProto.newBuilder();
   anp.setId(p.getId());
   anp.setHostname(p.getHostname());
   anp.setIpAddress(p.getIpAddress());
   anp.setPort(p.getPort());
   anp.setHttpAddress(p.getHttpAddress());
   return anp.build();
 }
Esempio n. 2
0
  public static boolean isNameNodeAlive(Collection<ActiveNode> activeNamenodes, long namenodeId) {
    if (activeNamenodes == null) {
      // We do not know yet, be conservative
      return true;
    }

    for (ActiveNode namenode : activeNamenodes) {
      if (namenode.getId() == namenodeId) {
        return true;
      }
    }
    return false;
  }
Esempio n. 3
0
 public ActiveNode getNextNamenodeToSendBlockReport() throws IOException {
   List<ActiveNode> allNodes = getActiveNameNodes().getActiveNodes();
   if (this.isLeader()) {
     // Use the modulo to roundrobin b/w namenodes
     nnIndex = ++nnIndex % allNodes.size();
     ActiveNode ann = allNodes.get(nnIndex);
     return ann;
   } else {
     // random allocation of NN
     Random rand = new Random();
     rand.setSeed(System.currentTimeMillis());
     ActiveNode ann = allNodes.get(rand.nextInt(allNodes.size()));
     LOG.debug("XXX Returning " + ann.getIpAddress() + " for Next Block report");
     return ann;
   }
 }
Esempio n. 4
0
  /** Test if the NN are correctly removed from the Active NN list */
  @Test
  public void testDeadNodesRemoval()
      throws IOException, InterruptedException, CloneNotSupportedException {
    LOG.debug("start testDeadNodesRemoval");
    List<InetSocketAddress> isaList = new ArrayList<InetSocketAddress>();
    // create 10 NN
    for (int i = 0; i < 10; i++) {
      LightWeightNameNode nn =
          new LightWeightNameNode(
              new HdfsLeDescriptorFactory(),
              DFS_LEADER_CHECK_INTERVAL_IN_MS,
              DFS_LEADER_MISSED_HB_THRESHOLD,
              TIME_PERIOD_INCREMENT,
              HTTP_ADDRESS,
              "127.0.0.1:" + (50000 + i));
      nnList.add(nn);
      isaList.add(nn.getNameNodeAddress());
    }

    // wait for one HB and the first node should have complete list of nodes
    Thread.sleep(DFS_LEADER_CHECK_INTERVAL_IN_MS * DFS_LEADER_MISSED_HB_THRESHOLD);
    // verify that the number of active nn is equal to the number of started NN
    List<ActiveNode> activesNNs = nnList.get(0).getActiveNameNodes().getActiveNodes();
    assertTrue(
        "wrong number of active NN " + activesNNs.size(), activesNNs.size() == nnList.size());

    // verify that there is one and only one leader.
    int leaderId = 0;
    int nbLeaders = 0;
    for (int i = 0; i < nnList.size(); i++) {
      if (nnList.get(i).isLeader()) {
        nbLeaders++;
        leaderId = i;
      }
    }
    assertTrue("there is no leader", nbLeaders > 0);
    assertTrue("there is more than one leader", nbLeaders == 1);

    // stop the leader
    nnList.get(leaderId).stop();

    Thread.sleep(DFS_LEADER_CHECK_INTERVAL_IN_MS * (DFS_LEADER_MISSED_HB_THRESHOLD + 2));

    // verify that there is one and only one leader.
    int newLeaderId = 0;
    nbLeaders = 0;
    for (int i = 0; i < nnList.size(); i++) {
      if (i != leaderId) {
        if (nnList.get(i).isLeader()) {
          nbLeaders++;
          newLeaderId = i;
        }
      }
    }

    assertTrue("there is no leader", nbLeaders > 0);
    assertTrue("there is more than one leader", nbLeaders == 1);

    // verify that the stoped leader is not in the active list anymore
    activesNNs = nnList.get(newLeaderId).getActiveNameNodes().getActiveNodes();
    for (ActiveNode ann : activesNNs) {
      assertFalse(
          "previous is stil in active nn",
          ann.getInetSocketAddress().equals(isaList.get(leaderId)));
    }

    // stop NN last alive NN
    int tokill = nnList.size() - 1;
    while (leaderId == tokill || newLeaderId == tokill) {
      tokill--;
    }
    LOG.debug("stopping node: " + nnList.get(tokill).getLeCurrentId());
    nnList.get(tokill).stop();
    Thread.sleep(DFS_LEADER_CHECK_INTERVAL_IN_MS * (DFS_LEADER_MISSED_HB_THRESHOLD + 2));

    // verify that the killed NN is not in the active NN list anymore
    activesNNs = nnList.get(newLeaderId).getActiveNameNodes().getActiveNodes();
    assertTrue("wrong nb of active nn " + activesNNs.size(), activesNNs.size() == 8);
    for (ActiveNode ann : activesNNs) {
      assertFalse(
          "killed nn is stil in active nn", ann.getInetSocketAddress().equals(isaList.get(tokill)));
    }
  }