Gargi-jais11 commented on code in PR #8972: URL: https://github.com/apache/ozone/pull/8972#discussion_r2376174697
########## hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/diskbalancer/DiskBalancerVolumeCalculation.java: ########## @@ -0,0 +1,125 @@ +/* + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.ozone.container.diskbalancer; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; +import java.util.List; +import java.util.Map; +import org.apache.hadoop.hdds.fs.SpaceUsageSource; +import org.apache.hadoop.ozone.container.common.utils.StorageVolumeUtil; +import org.apache.hadoop.ozone.container.common.volume.HddsVolume; +import org.apache.hadoop.ozone.container.common.volume.MutableVolumeSet; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Utility class for disk balancer volume calculations. + * + * This class provides shared functionality for + * creating immutable volume snapshots, + * calculating ideal usage, and + * volume data density + * ensuring consistency across all disk balancing components and preventing race conditions. + */ +public final class DiskBalancerVolumeCalculation { + + private static final Logger LOG = LoggerFactory.getLogger(DiskBalancerVolumeCalculation.class); + + private DiskBalancerVolumeCalculation() { + // Utility class - prevent instantiation + } + + /** + * Get an immutable snapshot of volumes from a MutableVolumeSet. + * + * @param volumeSet The MutableVolumeSet to create a snapshot from + * @return Immutable list of HddsVolume objects + */ + public static ImmutableList<HddsVolume> getImmutableVolumeSet(MutableVolumeSet volumeSet) { + // Create an immutable copy of the volume list at this point in time + List<HddsVolume> volumes = StorageVolumeUtil.getHddsVolumesList(volumeSet.getVolumesList()); Review Comment: We cannot use StorageVolume instead of HddsVolume although **getCurrentUsage()** is available in StorageVolume but ** getCommittedBytes() ** is only available in HddsVolume which is needed for calculation. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
