DatanodeDescriptor getDatanodeByHost(String ipAddr) {
    if (ipAddr == null) {
      return null;
    }
      
    hostmapLock.readLock().lock();
    try {
      DatanodeDescriptor[] nodes = map.get(ipAddr);
      // no entry
      if (nodes== null) {
        return null;
      }
      // one node
      if (nodes.length == 1) {
        return nodes[0];
      }
      // more than one node
      return nodes[ThreadLocalRandom.current().nextInt(nodes.length)];
    } finally {
      hostmapLock.readLock().unlock();
    }
  }
@Test
  public void testGetDatanodeByHost() throws Exception {
    assertEquals(map.getDatanodeByHost("1.1.1.1"), dataNodes[0]);
    assertEquals(map.getDatanodeByHost("2.2.2.2"), dataNodes[1]);
    DatanodeDescriptor node = map.getDatanodeByHost("3.3.3.3");
    assertTrue(node == dataNodes[2] || node == dataNodes[3]);
    assertNull(map.getDatanodeByHost("4.4.4.4"));
  }