sumangala-patki commented on a change in pull request #2549: URL: https://github.com/apache/hadoop/pull/2549#discussion_r548951898
########## File path: hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ContentSummaryProcessor.java ########## @@ -0,0 +1,123 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.fs.azurebfs.services; + +import java.io.IOException; +import java.util.Collections; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.SynchronousQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.azurebfs.AzureBlobFileSystemStore; +import org.apache.hadoop.fs.azurebfs.utils.ABFSContentSummary; + +public class ContentSummaryProcessor { + private final AtomicLong fileCount = new AtomicLong(0L); + private final AtomicLong directoryCount = new AtomicLong(0L); + private final AtomicLong totalBytes = new AtomicLong(0L); + private final AtomicInteger numTasks = new AtomicInteger(0); + private final AzureBlobFileSystemStore abfsStore; + private final ExecutorService executorService = new ThreadPoolExecutor(1, + NUM_THREADS, 5, TimeUnit.SECONDS, new SynchronousQueue<>()); + private final LinkedBlockingQueue<FileStatus> queue = new LinkedBlockingQueue<>(); + private final Set<Future<Object>> futures = + Collections.newSetFromMap(new ConcurrentHashMap<>()); + private static final Logger LOG = + LoggerFactory.getLogger(ContentSummaryProcessor.class); + private static final int NUM_THREADS = 16; + private static final int POLL_TIMEOUT = 100; + + public ContentSummaryProcessor(AzureBlobFileSystemStore abfsStore) { + this.abfsStore = abfsStore; + } + + public ABFSContentSummary getContentSummary(Path path) + throws IOException, InterruptedException { + processDirectoryTree(path); + + while (!queue.isEmpty() || numTasks.get() > 0) { + for (Future<Object> future : futures) { + try { + future.get(10, TimeUnit.MILLISECONDS); Review comment: This is not really needed for termination since the while condition is sufficient. Findbugs requires us to use returned values from functions, so one way out is to collect the future objects returned and wait on them at the end of main process. In our case, the callable returns null on successful completion of task. Had we used a runnable task (void return type), this would not be necessary. But runnable does not allow us to throw checked exceptions, so we have to use callable (and the returned future). The other option is to SuppressWarnings by findbugs. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
