@VisibleForTesting
  void checkPartitionDirs(final ExecutorService executor,
      final Path basePath, final Set<Path> result,
      final FileSystem fs, final List<String> partColNames) throws MetastoreException {
    try {
      Queue<Future<Path>> futures = new LinkedList<>();
      ConcurrentLinkedQueue<PathDepthInfo> nextLevel = new ConcurrentLinkedQueue<>();
      nextLevel.add(new PathDepthInfo(basePath, 0));
      //Uses level parallel implementation of a bfs. Recursive DFS implementations
      //have a issue where the number of threads can run out if the number of
      //nested sub-directories is more than the pool size.
      //Using a two queue implementation is simpler than one queue since then we will
      //have to add the complex mechanisms to let the free worker threads know when new levels are
      //discovered using notify()/wait() mechanisms which can potentially lead to bugs if
      //not done right
      while(!nextLevel.isEmpty()) {
        ConcurrentLinkedQueue<PathDepthInfo> tempQueue = new ConcurrentLinkedQueue<>();
        //process each level in parallel
        while(!nextLevel.isEmpty()) {
          futures.add(
              executor.submit(new PathDepthInfoCallable(nextLevel.poll(), partColNames, fs, tempQueue)));
        }
        while(!futures.isEmpty()) {
          Path p = futures.poll().get();
          if (p != null) {
            result.add(p);
          }
        }
        //update the nextlevel with newly discovered sub-directories from the above
        nextLevel = tempQueue;
      }
    } catch (InterruptedException | ExecutionException e) {
      LOG.error("Exception received while listing partition directories", e);
      executor.shutdownNow();
      throw new MetastoreException(e.getCause());
    }
  }
Assume that depth is 2, i.e., partition columns are a and b
tblPath/a=1  => throw exception
tblPath/a=1/file => throw exception
tblPath/a=1/b=2/file => return a=1/b=2
tblPath/a=1/b=2/c=3 => return a=1/b=2
tblPath/a=1/b=2/c=3/file => return a=1/b=2

@param basePath
         Start directory
@param allDirs
         This set will contain the leaf paths at the end.
@param partColNames
         Partition column names
@throws IOException
          Thrown if we can't get lists from the fs.
@throws MetastoreException ex
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreChecker.java