return a list of blocks & their locations on <code>datanode</code> whose
total size is <code>size</code>

@param datanode on which blocks are located
@param size     total size of blocks
482191
BlocksWithLocations getBlocks(DatanodeID datanode, long size)
    throws IOException {
    readLock();
    try {
      checkSuperuserPrivilege();

      DatanodeDescriptor node = getDatanode(datanode);
      if (node == null) {
        NameNode.stateChangeLog.warn("BLOCK* NameSystem.getBlocks: "
          + "Asking for blocks from an unrecorded node " + datanode.getName());
        throw new IllegalArgumentException(
          "Unexpected exception.  Got getBlocks message for datanode " +
            datanode.getName() + ", but there is no info for it");
      }

      int numBlocks = node.numBlocks();
      if (numBlocks == 0) {
        return new BlocksWithLocations(new BlockWithLocations[0]);
      }
      Iterator<BlockInfo> iter = node.getBlockIterator();
      int startBlock = r.nextInt(numBlocks); // starting from a random block
      // skip blocks
      for (int i = 0; i < startBlock; i++) {
        iter.next();
      }
      List<BlockWithLocations> results = new ArrayList<BlockWithLocations>();
      long totalSize = 0;
      while (totalSize < size && iter.hasNext()) {
        totalSize += addBlock(iter.next(), results);
      }
      if (totalSize < size) {
        iter = node.getBlockIterator(); // start from the beginning
        for (int i = 0; i < startBlock && totalSize < size; i++) {
          totalSize += addBlock(iter.next(), results);
        }
      }

      return new BlocksWithLocations(
        results.toArray(new BlockWithLocations[results.size()]));
    } finally {
      readUnlock();
    }
  }
994990
private Map<String, String> toMetadata( NodeList blocks ) {
        Map<String, String> dimensions = new HashMap<String, String>();

        for( int i = 0; i < blocks.getLength(); i++ ) {
            Node dimensionNode = blocks.item(i);

            if( dimensionNode.getNodeName().equals("member") ) {
                String dimensionName = null;
                String dimensionValue = null;

                NodeList dimensionAttributes = dimensionNode.getChildNodes();
                for( int j = 0; j < dimensionAttributes.getLength(); j++ ) {
                    Node attribute = dimensionAttributes.item(j);
                    String name = attribute.getNodeName();

                    if( name.equals("Name") ) {
                        dimensionName = provider.getTextValue(attribute);
                    }
                    else if( name.equals("Value") ) {
                        dimensionValue = provider.getTextValue(attribute);
                    }
                }
                if( dimensionName != null ) {
                    dimensions.put(dimensionName, dimensionValue);
                }
            }
        }

        if( dimensions.size() == 0 ) {
            return null;
        }
        return dimensions;
    }
855070
private static BlockLocation[] getParityBlocks(final Path filePath,
                                          final long blockSize,
                                          final long numStripes,
                                          final RaidInfo raidInfo) 
    throws IOException {
    FileSystem parityFS = raidInfo.parityPair.getFileSystem();
    
    // get parity file metadata
    FileStatus parityFileStatus = raidInfo.parityPair.getFileStatus(); 
    long parityFileLength = parityFileStatus.getLen();

    if (parityFileLength != numStripes * raidInfo.parityBlocksPerStripe *
        blockSize) {
      throw new IOException("expected parity file of length" + 
                            (numStripes * raidInfo.parityBlocksPerStripe *
                             blockSize) +
                            " but got parity file of length " + 
                            parityFileLength);
    }

    BlockLocation[] parityBlocks = 
      parityFS.getFileBlockLocations(parityFileStatus, 0L, parityFileLength);
    
    if (parityFS instanceof DistributedFileSystem ||
        parityFS instanceof DistributedRaidFileSystem) {
      long parityBlockSize = parityFileStatus.getBlockSize();
      if (parityBlockSize != blockSize) {
        throw new IOException("file block size is " + blockSize + 
                              " but parity file block size is " + 
                              parityBlockSize);
      }
    } else if (parityFS instanceof HarFileSystem) {
      LOG.debug("HAR FS found");
    } else {
      LOG.warn("parity file system is not of a supported type");
    }
    
    return parityBlocks;
  }
216181
@Override
  public DatanodeDescriptor[] chooseTarget(FSInodeInfo srcInode,
      int numOfReplicas,
      DatanodeDescriptor writer, List<DatanodeDescriptor> chosenNodes,
      List<Node> excludesNodes, long blocksize) {
    if (numOfReplicas == 0 || clusterMap.getNumOfLeaves() == 0) {
      return new DatanodeDescriptor[0];
    }

    int[] result = getActualReplicas(numOfReplicas, chosenNodes);
    numOfReplicas = result[0];
    int maxNodesPerRack = result[1];

    HashMap<Node, Node> excludedNodes = new HashMap<Node, Node>();
    List<DatanodeDescriptor> results = new ArrayList<DatanodeDescriptor>(
        chosenNodes.size() + numOfReplicas);

    updateExcludedAndChosen(null, excludedNodes, results, chosenNodes);

    if (!clusterMap.contains(writer)) {
      writer = null;
    }

    DatanodeDescriptor localNode = super.chooseTarget(numOfReplicas, writer,
        excludedNodes, blocksize, maxNodesPerRack, results,
        chosenNodes.isEmpty());

    return this.finalizeTargets(results, chosenNodes, writer, localNode);
  }
424609
private HashMap<DatanodeDescriptor, Integer> directoryDataNodeUsage(INodeDirectory dir,
      int threshold) {
    HashMap<DatanodeDescriptor, Integer> dataNodeUsage = new HashMap<DatanodeDescriptor, Integer>();

    List<INode> children;
    nameSystem.readLock();
    try {
      if (dir.getChildrenRaw() == null) {
        return dataNodeUsage;
      }
      children = new ArrayList<INode>(dir.getChildrenRaw());
      Collections.shuffle(children);

      for (INode node : children) {
        if (!(node instanceof INodeFile)) { // The condition is always false.
          continue;
        }

        INodeFile file = (INodeFile) node;
        BlockInfo[] blocks = file.getBlocks();

        for (BlockInfo block : blocks) {
          if (threshold == 0) {
            return dataNodeUsage;
          }

          int replication = block.numNodes();
          for (int i = 0; i < replication; i++) {
            DatanodeDescriptor datanode = block.getDatanode(i);
            Integer currentUsage = dataNodeUsage.get(datanode);
            dataNodeUsage.put(datanode, currentUsage == null ? 1 : currentUsage + 1);
          }
          threshold--;
        }
      }
    } finally {
      nameSystem.readUnlock();
    }
    return dataNodeUsage;
  }
384063
void findLargestAnglesForAllNodes() {
		for (int i = 0; i < listInfo.size(); i++) {
			NodeInfo info = listInfo.get(i);

			if( info.edges.size < 2 )
				continue;

			for (int k = 0, j = info.edges.size-1; k < info.edges.size; j=k,k++) {
				double angleA = info.edges.get(j).angle;
				double angleB = info.edges.get(k).angle;

				double distance = UtilAngle.distanceCCW(angleA,angleB);

				if( distance > info.angleBetween ) {
					info.angleBetween = distance;
					info.left = info.edges.get(j).target;
					info.right = info.edges.get(k).target;
				}
			}
		}
	}
571225
boolean removeNode(Block b, DatanodeDescriptor node) {
    BlockInfo info = blocks.get(b);
    if (info == null)
      return false;

    // remove block from the data-node list and the node from the block info
    boolean removed = node.removeBlock(info);

    if (info.getDatanode(0) == null     // no datanodes left
              && info.inode == null) {  // does not belong to a file
      removeBlockFromMap(b); // remove block from the map
    }
    return removed;
  }
1348835
private int countLiveNodes(Block b, Iterator<DatanodeDescriptor> nodeIter) {
    int live = 0;
    Collection<DatanodeDescriptor> nodesCorrupt = null;
    if (corruptReplicas.size() != 0) {
      nodesCorrupt = corruptReplicas.getNodes(b);
    }
    while (nodeIter.hasNext()) {
      DatanodeDescriptor node = nodeIter.next();
      if (((nodesCorrupt != null) && (nodesCorrupt.contains(node))) ||
        node.isDecommissionInProgress() || node.isDecommissioned()) {
        // do nothing
      } else {
        live++;
      }
    }
    return live;
  }
197370
LocatedBlocks getBlockLocations(String clientMachine, String src,
                                  long offset, long length,
                                  BlockMetaInfoType type) throws IOException {
    INode[] inodes = dir.getExistingPathINodes(src);
    if (isPermissionEnabled && 
        isPermissionCheckingEnabled(inodes)) {
      checkPathAccess(src, inodes, FsAction.READ);
    }

    LocatedBlocks blocks = getBlockLocations(src, inodes[inodes.length-1],
        offset, length, false, type);
    if (blocks != null) {
      //sort the blocks
      DatanodeDescriptor client = host2DataNodeMap.getDatanodeByHost(
        clientMachine);
      for (LocatedBlock b : blocks.getLocatedBlocks()) {
        clusterMap.pseudoSortByDistance(client, b.getLocations());
        // Move decommissioned datanodes to the bottom
        Arrays.sort(b.getLocations(), DFSUtil.DECOM_COMPARATOR);
      }
    }
    return blocks;
  }
212715
public void getAndSetNodeDataSize(String nodePath)
   {
      try
      {
         long dataSize = getNodeDataSizeDirectly(nodePath);
         quotaPersister.setNodeDataSizeIfQuotaExists(rName, wsName, nodePath, dataSize);
      }
      catch (QuotaManagerException e)
      {
         LOG.warn("Can't calculate node data size " + nodePath + " because: " + e.getCause().getMessage());
      }
   }
744712
function getBlockNodes(nodes) {
  // TODO(perf): just check if all items in `nodes` are siblings and if they are return the original
  //             collection, otherwise update the original collection.
  var node = nodes[0];
  var endNode = nodes[nodes.length - 1];
  var blockNodes = [node];

  do {
    node = node.nextSibling;
    if (!node) break;
    blockNodes.push(node);
  } while (node !== endNode);

  return jqLite(blockNodes);
}
212580
private BitSet findPreviouslyDeadBlocks() throws DataflowAnalysisException, CFGBuilderException {
        BitSet deadBlocks = new BitSet();
        ValueNumberDataflow vnaDataflow = classContext.getValueNumberDataflow(method);
        for (Iterator<BasicBlock> i = vnaDataflow.getCFG().blockIterator(); i.hasNext();) {
            BasicBlock block = i.next();
            ValueNumberFrame vnaFrame = vnaDataflow.getStartFact(block);
            if (vnaFrame.isTop()) {
                deadBlocks.set(block.getLabel());
            }
        }

        return deadBlocks;
    }
403050
int numNodes(Block b) {
    BlockInfo info = blocks.get(b);
    return info == null ? 0 : info.numNodes();
  }
1335822
private static LocatedBlock convertLocatedBlock(TLocatedBlock tblk) {
    TBlock one = tblk.block;
    Block hblock = new Block(one.getBlockId(), 
                             one.getNumBytes(),
                             one.getGenerationStamp());
    List<TDatanodeID> locs = tblk.location;
    DatanodeInfo[] dn = new DatanodeInfo[locs.size()];
    for (int j = 0; j < dn.length; j++) {
      String name = locs.get(j).name;
      dn[j] = new DatanodeInfo(new DatanodeID(name, "", -1, getPort(name)));
    }
    return new LocatedBlock(hblock, dn);
  }
510093
public LocatedBlocks getBlockLocations(String src, long offset, long length) throws IOException {
    INode[] inodes = dir.getExistingPathINodes(src);
    return getBlockLocations(src, inodes[inodes.length-1],
        offset, length, false, BlockMetaInfoType.NONE);
  }
1000148
public long getFinalizedBlockLength(int namespaceId, Block b) throws IOException {
    DatanodeBlockInfo info = volumeMap.get(namespaceId, b);
    if (info == null) {
      throw new IOException("Can't find block " + b + " in volumeMap");
    }
    return info.getFinalizedSize();
  }
68679
public static BlockLocation[] locatedBlocks2Locations(LocatedBlocks blocks) {
    if (blocks == null) {
      return new BlockLocation[0];
    }
    int nrBlocks = blocks.locatedBlockCount();
    BlockLocation[] blkLocations = new BlockLocation[nrBlocks];
    if (nrBlocks == 0) {
      return blkLocations;
    }
    int idx = 0;
    for (LocatedBlock blk : blocks.getLocatedBlocks()) {
      assert idx < nrBlocks : "Incorrect index";
      DatanodeInfo[] locations = blk.getLocations();
      String[] hosts = new String[locations.length];
      String[] names = new String[locations.length];
      String[] racks = new String[locations.length];
      for (int hCnt = 0; hCnt < locations.length; hCnt++) {
        hosts[hCnt] = locations[hCnt].getHostName();
        names[hCnt] = locations[hCnt].getName();
        NodeBase node = new NodeBase(names[hCnt],
                                     locations[hCnt].getNetworkLocation());
        racks[hCnt] = node.toString();
      }
      blkLocations[idx] = new BlockLocation(names, hosts, racks,
                                            blk.getStartOffset(),
                                            blk.getBlockSize(),
                                            blk.isCorrupt());
      idx++;
    }
    return blkLocations;
  }