code: 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();
      }
    }
docs: 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