priyeshkaratha commented on code in PR #11122: URL: https://github.com/apache/ozone/pull/11122#discussion_r4119443933
########## hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/BucketDeletedBytes.java: ########## @@ -0,0 +1,70 @@ +/* + * 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.om.helpers; + +/** + * Bucket-level deleted bytes split. + */ +public final class BucketDeletedBytes { + private final long snapshotTrappedBytes; Review Comment: Can you explain the relationship between these values and totalPendingDeletionBytes and totalPendingDeletionKeyCount? ########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/trapped/BucketDeletedDataCalculator.java: ########## @@ -0,0 +1,290 @@ +/* + * 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.om.snapshot.trapped; + +import java.io.IOException; +import java.util.ArrayDeque; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Queue; +import java.util.Set; +import java.util.UUID; +import org.apache.hadoop.hdds.utils.db.Table; +import org.apache.hadoop.hdds.utils.db.Table.KeyValue; +import org.apache.hadoop.hdds.utils.db.TableIterator; +import org.apache.hadoop.ozone.om.KeyManager; +import org.apache.hadoop.ozone.om.OMMetadataManager; +import org.apache.hadoop.ozone.om.OmMetadataManagerImpl; +import org.apache.hadoop.ozone.om.OmSnapshot; +import org.apache.hadoop.ozone.om.OmSnapshotManager; +import org.apache.hadoop.ozone.om.OzoneManager; +import org.apache.hadoop.ozone.om.SnapshotChainManager; +import org.apache.hadoop.ozone.om.helpers.OmKeyInfo; +import org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo; +import org.apache.hadoop.ozone.om.helpers.SnapshotInfo; +import org.apache.hadoop.ozone.om.snapshot.SnapshotUtils; +import org.apache.hadoop.ozone.om.snapshot.filter.ReclaimableDirFilter; +import org.apache.hadoop.ozone.om.snapshot.filter.ReclaimableKeyFilter; +import org.apache.ratis.util.function.UncheckedAutoCloseableSupplier; + +/** + * Computes bucket-level deleted bytes split into purgeable and snapshot-trapped. + * <p> + * This calculator follows KDS/DDS reclaimability semantics across active OM DB + * and all active snapshots in the bucket chain. + */ +public class BucketDeletedDataCalculator { + + private final OzoneManager ozoneManager; + private final OmSnapshotManager omSnapshotManager; + private final SnapshotChainManager snapshotChainManager; + + public BucketDeletedDataCalculator(OzoneManager ozoneManager) { + this.ozoneManager = ozoneManager; + this.omSnapshotManager = ozoneManager.getOmSnapshotManager(); + this.snapshotChainManager = + ((OmMetadataManagerImpl) ozoneManager.getMetadataManager()) + .getSnapshotChainManager(); + } + + public BucketDeletedBytesStats calculate(String volume, String bucket) + throws IOException { + BucketDeletedBytesStats totals = new BucketDeletedBytesStats(); + processStore(volume, bucket, null, + requireKeyManager(ozoneManager.getKeyManager(), "active store"), totals); + + Iterator<UUID> iterator = snapshotChainManager.iterator(true); + while (iterator.hasNext()) { + UUID snapshotId = iterator.next(); + SnapshotInfo snapshotInfo = SnapshotUtils.getSnapshotInfo( + ozoneManager, snapshotChainManager, snapshotId); + if (snapshotInfo == null + || snapshotInfo.getSnapshotStatus() != SnapshotInfo.SnapshotStatus.SNAPSHOT_ACTIVE + || !snapshotInfo.isDeepCleanedDeletedDir() + || !snapshotInfo.getVolumeName().equals(volume) + || !snapshotInfo.getBucketName().equals(bucket) + || !OmSnapshotManager.areSnapshotChangesFlushedToDB( + ozoneManager.getMetadataManager(), snapshotInfo)) { + continue; + } + try (UncheckedAutoCloseableSupplier<OmSnapshot> snapshot = + omSnapshotManager.getActiveSnapshot(volume, bucket, snapshotInfo.getName())) { + processStore(volume, bucket, snapshotInfo, + requireKeyManager(snapshot.get().getKeyManager(), + "snapshot " + snapshotInfo.getTableKey()), + totals); + } + } + return totals; + } + + private static KeyManager requireKeyManager(KeyManager keyManager, String scope) + throws IOException { + if (keyManager == null) { + throw new IOException("KeyManager is not available for " + scope + + ". Ensure OM is fully initialized before running the calculation."); + } + return keyManager; + } + + private void processStore( + String volume, + String bucket, + SnapshotInfo currentSnapshotInfo, + KeyManager keyManager, + BucketDeletedBytesStats totals) throws IOException { + try (ReclaimableKeyFilter reclaimableKeyFilter = new ReclaimableKeyFilter( + ozoneManager, + omSnapshotManager, + snapshotChainManager, + currentSnapshotInfo, + keyManager, + ozoneManager.getMetadataManager().getLock()); + ReclaimableDirFilter reclaimableDirFilter = new ReclaimableDirFilter( + ozoneManager, + omSnapshotManager, + snapshotChainManager, + currentSnapshotInfo, + keyManager, + ozoneManager.getMetadataManager().getLock())) { + + processDeletedKeys(volume, bucket, keyManager, reclaimableKeyFilter, totals); + processDeletedDirs(volume, bucket, keyManager, reclaimableKeyFilter, + reclaimableDirFilter, totals); + } + } + + private void processDeletedKeys( + String volume, + String bucket, + KeyManager keyManager, + ReclaimableKeyFilter reclaimableKeyFilter, + BucketDeletedBytesStats totals) throws IOException { + OMMetadataManager metadataManager = keyManager.getMetadataManager(); + Table<String, RepeatedOmKeyInfo> deletedTable = metadataManager.getDeletedTable(); + String deletedTablePrefix = metadataManager.getTableBucketPrefix( + deletedTable.getName(), volume, bucket); + try (TableIterator<String, ? extends KeyValue<String, RepeatedOmKeyInfo>> itr = + deletedTable.iterator(deletedTablePrefix)) { + while (itr.hasNext()) { + KeyValue<String, ? extends RepeatedOmKeyInfo> entry = itr.next(); + for (OmKeyInfo omKeyInfo : entry.getValue().getOmKeyInfoList()) { + if (reclaimableKeyFilter.apply(Table.newKeyValue(entry.getKey(), omKeyInfo))) { + totals.addPurgeableKey(omKeyInfo.getReplicatedSize()); + } else { + totals.addSnapshotTrappedKey(omKeyInfo.getReplicatedSize()); + } + } + } + } + } + + private void processDeletedDirs( + String volume, + String bucket, + KeyManager keyManager, + ReclaimableKeyFilter reclaimableKeyFilter, + ReclaimableDirFilter reclaimableDirFilter, + BucketDeletedBytesStats totals) throws IOException { + OMMetadataManager metadataManager = ozoneManager.getMetadataManager(); + long volumeId = metadataManager.getVolumeId(volume); + long bucketId = metadataManager.getBucketId(volume, bucket); + KeyManager traversalKeyManager = ozoneManager.getKeyManager(); Review Comment: `processDeletedDirs` always uses `ozoneManager.getKeyManager()` here instead of the `keyManager` parameter that was passed in (the store-specific one that is active or snapshot). So when this is invoked for a snapshot's deleted-dir tree, `traverseDeletedDirSubtree` below ends up calling `getPendingDeletionSubFiles`/`getPendingDeletionSubDirs` against the **active OM's** fileTable/directoryTable, not the snapshot's. A directory deleted while a snapshot existed can have children that only exist in that snapshot's tables (already gone from the active DB, or never existed there under this object ID). In that case this silently returns 0 sub-files/sub-dirs for the root, and the subtree's bytes/keys/dirs are dropped from both purgeable and snapshot-trapped totals instead of being counted as snapshot-trapped. Should this use `keyManager` (the parameter) instead of `ozoneManager.getKeyManager()`? ########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/trapped/BucketDeletedDataCalculator.java: ########## @@ -0,0 +1,290 @@ +/* + * 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.om.snapshot.trapped; + +import java.io.IOException; +import java.util.ArrayDeque; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Queue; +import java.util.Set; +import java.util.UUID; +import org.apache.hadoop.hdds.utils.db.Table; +import org.apache.hadoop.hdds.utils.db.Table.KeyValue; +import org.apache.hadoop.hdds.utils.db.TableIterator; +import org.apache.hadoop.ozone.om.KeyManager; +import org.apache.hadoop.ozone.om.OMMetadataManager; +import org.apache.hadoop.ozone.om.OmMetadataManagerImpl; +import org.apache.hadoop.ozone.om.OmSnapshot; +import org.apache.hadoop.ozone.om.OmSnapshotManager; +import org.apache.hadoop.ozone.om.OzoneManager; +import org.apache.hadoop.ozone.om.SnapshotChainManager; +import org.apache.hadoop.ozone.om.helpers.OmKeyInfo; +import org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo; +import org.apache.hadoop.ozone.om.helpers.SnapshotInfo; +import org.apache.hadoop.ozone.om.snapshot.SnapshotUtils; +import org.apache.hadoop.ozone.om.snapshot.filter.ReclaimableDirFilter; +import org.apache.hadoop.ozone.om.snapshot.filter.ReclaimableKeyFilter; +import org.apache.ratis.util.function.UncheckedAutoCloseableSupplier; + +/** + * Computes bucket-level deleted bytes split into purgeable and snapshot-trapped. + * <p> + * This calculator follows KDS/DDS reclaimability semantics across active OM DB + * and all active snapshots in the bucket chain. + */ +public class BucketDeletedDataCalculator { + + private final OzoneManager ozoneManager; + private final OmSnapshotManager omSnapshotManager; + private final SnapshotChainManager snapshotChainManager; + + public BucketDeletedDataCalculator(OzoneManager ozoneManager) { + this.ozoneManager = ozoneManager; + this.omSnapshotManager = ozoneManager.getOmSnapshotManager(); + this.snapshotChainManager = + ((OmMetadataManagerImpl) ozoneManager.getMetadataManager()) + .getSnapshotChainManager(); + } + + public BucketDeletedBytesStats calculate(String volume, String bucket) + throws IOException { + BucketDeletedBytesStats totals = new BucketDeletedBytesStats(); + processStore(volume, bucket, null, + requireKeyManager(ozoneManager.getKeyManager(), "active store"), totals); + + Iterator<UUID> iterator = snapshotChainManager.iterator(true); + while (iterator.hasNext()) { + UUID snapshotId = iterator.next(); + SnapshotInfo snapshotInfo = SnapshotUtils.getSnapshotInfo( + ozoneManager, snapshotChainManager, snapshotId); + if (snapshotInfo == null + || snapshotInfo.getSnapshotStatus() != SnapshotInfo.SnapshotStatus.SNAPSHOT_ACTIVE + || !snapshotInfo.isDeepCleanedDeletedDir() Review Comment: Snapshots that haven't been deep-cleaned yet (`!isDeepCleanedDeletedDir()`) are skipped entirely via `continue`, so their deleted data isn't added to either `purgeableBytes` or `snapshotTrappedBytes`. This tool's stated purpose is to explain why deletion looks stuck. But a snapshot that hasn't finished deep-cleaning is exactly the case an admin would be investigating, and here it's silently reported as 0 rather than as "unknown/pending". Should this category be surfaced separately (e.g. a `pendingDeepCleanBytes` counter) instead of being dropped from the totals? ########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/trapped/BucketDeletedDataCalculator.java: ########## @@ -0,0 +1,290 @@ +/* + * 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.om.snapshot.trapped; + +import java.io.IOException; +import java.util.ArrayDeque; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Queue; +import java.util.Set; +import java.util.UUID; +import org.apache.hadoop.hdds.utils.db.Table; +import org.apache.hadoop.hdds.utils.db.Table.KeyValue; +import org.apache.hadoop.hdds.utils.db.TableIterator; +import org.apache.hadoop.ozone.om.KeyManager; +import org.apache.hadoop.ozone.om.OMMetadataManager; +import org.apache.hadoop.ozone.om.OmMetadataManagerImpl; +import org.apache.hadoop.ozone.om.OmSnapshot; +import org.apache.hadoop.ozone.om.OmSnapshotManager; +import org.apache.hadoop.ozone.om.OzoneManager; +import org.apache.hadoop.ozone.om.SnapshotChainManager; +import org.apache.hadoop.ozone.om.helpers.OmKeyInfo; +import org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo; +import org.apache.hadoop.ozone.om.helpers.SnapshotInfo; +import org.apache.hadoop.ozone.om.snapshot.SnapshotUtils; +import org.apache.hadoop.ozone.om.snapshot.filter.ReclaimableDirFilter; +import org.apache.hadoop.ozone.om.snapshot.filter.ReclaimableKeyFilter; +import org.apache.ratis.util.function.UncheckedAutoCloseableSupplier; + +/** + * Computes bucket-level deleted bytes split into purgeable and snapshot-trapped. + * <p> + * This calculator follows KDS/DDS reclaimability semantics across active OM DB + * and all active snapshots in the bucket chain. + */ +public class BucketDeletedDataCalculator { + + private final OzoneManager ozoneManager; + private final OmSnapshotManager omSnapshotManager; + private final SnapshotChainManager snapshotChainManager; + + public BucketDeletedDataCalculator(OzoneManager ozoneManager) { + this.ozoneManager = ozoneManager; + this.omSnapshotManager = ozoneManager.getOmSnapshotManager(); + this.snapshotChainManager = + ((OmMetadataManagerImpl) ozoneManager.getMetadataManager()) + .getSnapshotChainManager(); + } + + public BucketDeletedBytesStats calculate(String volume, String bucket) + throws IOException { + BucketDeletedBytesStats totals = new BucketDeletedBytesStats(); + processStore(volume, bucket, null, + requireKeyManager(ozoneManager.getKeyManager(), "active store"), totals); + + Iterator<UUID> iterator = snapshotChainManager.iterator(true); + while (iterator.hasNext()) { + UUID snapshotId = iterator.next(); + SnapshotInfo snapshotInfo = SnapshotUtils.getSnapshotInfo( + ozoneManager, snapshotChainManager, snapshotId); + if (snapshotInfo == null + || snapshotInfo.getSnapshotStatus() != SnapshotInfo.SnapshotStatus.SNAPSHOT_ACTIVE + || !snapshotInfo.isDeepCleanedDeletedDir() + || !snapshotInfo.getVolumeName().equals(volume) + || !snapshotInfo.getBucketName().equals(bucket) + || !OmSnapshotManager.areSnapshotChangesFlushedToDB( + ozoneManager.getMetadataManager(), snapshotInfo)) { + continue; + } + try (UncheckedAutoCloseableSupplier<OmSnapshot> snapshot = + omSnapshotManager.getActiveSnapshot(volume, bucket, snapshotInfo.getName())) { + processStore(volume, bucket, snapshotInfo, + requireKeyManager(snapshot.get().getKeyManager(), + "snapshot " + snapshotInfo.getTableKey()), + totals); + } + } + return totals; + } + + private static KeyManager requireKeyManager(KeyManager keyManager, String scope) + throws IOException { + if (keyManager == null) { + throw new IOException("KeyManager is not available for " + scope + + ". Ensure OM is fully initialized before running the calculation."); + } + return keyManager; + } + + private void processStore( + String volume, + String bucket, + SnapshotInfo currentSnapshotInfo, + KeyManager keyManager, + BucketDeletedBytesStats totals) throws IOException { + try (ReclaimableKeyFilter reclaimableKeyFilter = new ReclaimableKeyFilter( + ozoneManager, + omSnapshotManager, + snapshotChainManager, + currentSnapshotInfo, + keyManager, + ozoneManager.getMetadataManager().getLock()); + ReclaimableDirFilter reclaimableDirFilter = new ReclaimableDirFilter( + ozoneManager, + omSnapshotManager, + snapshotChainManager, + currentSnapshotInfo, + keyManager, + ozoneManager.getMetadataManager().getLock())) { + + processDeletedKeys(volume, bucket, keyManager, reclaimableKeyFilter, totals); + processDeletedDirs(volume, bucket, keyManager, reclaimableKeyFilter, + reclaimableDirFilter, totals); + } + } + + private void processDeletedKeys( + String volume, + String bucket, + KeyManager keyManager, + ReclaimableKeyFilter reclaimableKeyFilter, + BucketDeletedBytesStats totals) throws IOException { + OMMetadataManager metadataManager = keyManager.getMetadataManager(); + Table<String, RepeatedOmKeyInfo> deletedTable = metadataManager.getDeletedTable(); + String deletedTablePrefix = metadataManager.getTableBucketPrefix( + deletedTable.getName(), volume, bucket); + try (TableIterator<String, ? extends KeyValue<String, RepeatedOmKeyInfo>> itr = + deletedTable.iterator(deletedTablePrefix)) { + while (itr.hasNext()) { + KeyValue<String, ? extends RepeatedOmKeyInfo> entry = itr.next(); + for (OmKeyInfo omKeyInfo : entry.getValue().getOmKeyInfoList()) { + if (reclaimableKeyFilter.apply(Table.newKeyValue(entry.getKey(), omKeyInfo))) { + totals.addPurgeableKey(omKeyInfo.getReplicatedSize()); + } else { + totals.addSnapshotTrappedKey(omKeyInfo.getReplicatedSize()); + } + } + } + } + } + + private void processDeletedDirs( + String volume, + String bucket, + KeyManager keyManager, + ReclaimableKeyFilter reclaimableKeyFilter, + ReclaimableDirFilter reclaimableDirFilter, + BucketDeletedBytesStats totals) throws IOException { + OMMetadataManager metadataManager = ozoneManager.getMetadataManager(); + long volumeId = metadataManager.getVolumeId(volume); + long bucketId = metadataManager.getBucketId(volume, bucket); + KeyManager traversalKeyManager = ozoneManager.getKeyManager(); + + try (TableIterator<String, Table.KeyValue<String, OmKeyInfo>> deletedDirItr = + keyManager.getDeletedDirEntries(volume, bucket)) { + while (deletedDirItr.hasNext()) { + Table.KeyValue<String, OmKeyInfo> rootEntry = deletedDirItr.next(); + traverseDeletedDirSubtree( + traversalKeyManager, reclaimableKeyFilter, reclaimableDirFilter, + volumeId, bucketId, rootEntry, totals); + } + } + } + + private void traverseDeletedDirSubtree( + KeyManager keyManager, + ReclaimableKeyFilter reclaimableKeyFilter, + ReclaimableDirFilter reclaimableDirFilter, + long volumeId, + long bucketId, + Table.KeyValue<String, OmKeyInfo> rootEntry, + BucketDeletedBytesStats totals) throws IOException { + Queue<OmKeyInfo> queue = new ArrayDeque<>(); + Set<Long> visitedDirIds = new HashSet<>(); + Set<Long> visitedFileIds = new HashSet<>(); + + queue.add(rootEntry.getValue()); + visitedDirIds.add(rootEntry.getValue().getObjectID()); + + while (!queue.isEmpty()) { + OmKeyInfo currentDir = queue.poll(); + boolean currentDirReclaimable = + reclaimableDirFilter.apply(Table.newKeyValue("", currentDir)); + if (currentDirReclaimable) { + totals.addPurgeableDir(); + } else { + totals.addSnapshotTrappedDir(); + } + + for (OmKeyInfo subFile : keyManager.getPendingDeletionSubFiles( + volumeId, bucketId, currentDir, keyValue -> true, Integer.MAX_VALUE).getKeysToDelete()) { + if (!visitedFileIds.add(subFile.getObjectID())) { + continue; + } + boolean fileReclaimable = currentDirReclaimable Review Comment: `fileReclaimable = currentDirReclaimable || reclaimableKeyFilter.apply(...)` treats a purgeable parent directory as implying all of its sub-files are purgeable too, skipping the per-file reclaimability check whenever `currentDirReclaimable` is true. Is that assumption safe for every case here? If a sub-file is independently referenced by an older snapshot generation through a different chain path than its parent directory, this would count it as purgeable purely because the parent dir is purgeable, undercounting snapshot-trapped bytes. Worth double-checking against `DirectoryDeletingService`'s actual purge-time semantics (which apply `purgeDir || reclaimableFileFilter.apply(keyInfo)` per file, not as a blanket skip). -- 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]
