hanishakoneru commented on a change in pull request #271: HDDS-1812. Du while calculating used disk space reports that chunk files are file not found URL: https://github.com/apache/hadoop-ozone/pull/271#discussion_r366107142
########## File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/fs/CachingSpaceUsageSource.java ########## @@ -0,0 +1,137 @@ +/* + * 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.hdds.fs; + +import com.google.common.base.Preconditions; +import com.google.common.util.concurrent.ThreadFactoryBuilder; +import org.apache.hadoop.classification.InterfaceAudience; +import org.apache.hadoop.classification.InterfaceStability; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.annotation.Nullable; +import java.time.Duration; +import java.util.OptionalLong; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicLong; + +import static java.util.concurrent.TimeUnit.MILLISECONDS; + +/** + * Stores space usage and refreshes it periodically. + */ [email protected] [email protected] +public class CachingSpaceUsageSource implements SpaceUsageSource { + + private static final Logger LOG = + LoggerFactory.getLogger(CachingSpaceUsageSource.class); + + private final ScheduledExecutorService executor; + private final AtomicLong cachedValue = new AtomicLong(); + private final Duration refresh; + private final SpaceUsageSource source; + private final SpaceUsagePersistence persistence; + private boolean running; + private ScheduledFuture<?> scheduledFuture; + + public CachingSpaceUsageSource(SpaceUsageCheckParams params) { + this(params, createExecutor(params)); + } + + public CachingSpaceUsageSource(SpaceUsageCheckParams params, + ScheduledExecutorService executor) { + Preconditions.checkArgument(params != null, "params == null"); + + refresh = params.getRefresh(); + source = params.getSource(); + persistence = params.getPersistence(); + this.executor = refresh.isZero() ? null : executor; + Review comment: refresh.isZero() check is also done in createExecutor. We can remove it from one place. ---------------------------------------------------------------- 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] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
