code: 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;
    }
docs: Iterates through files in the directory dir, and counts the number
  of usages of datanodes for the files in the directory dir.
  Just iterates through threshold number of blocks.