-
Notifications
You must be signed in to change notification settings - Fork 588
HDDS-12562. Reclaimable Directory entry filter for reclaiming deleted directory entries #8055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7327b47
bd5b0c6
2018370
f1c85fd
4c74de1
43ab7b7
51c88f1
adc4bae
b901166
690eae9
865f3a5
5743edb
abcfaff
a2127a4
9f6d2a0
9d6bae3
7d785ab
e1d2317
215b8cc
93ba939
3935bf8
6d638a0
681bb3d
8fd746c
b69182e
d32bcf0
f8a2b6e
f323e3e
29a26d2
1ebba73
164303e
2c1d267
4febc9c
3e06491
45cb588
27b3604
b47f986
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,8 @@ | |
| import org.apache.hadoop.ozone.om.fs.OzoneManagerFS; | ||
| import org.apache.hadoop.ozone.om.helpers.BucketLayout; | ||
| import org.apache.hadoop.ozone.om.helpers.ListKeysResult; | ||
| import org.apache.hadoop.ozone.om.helpers.OmBucketInfo; | ||
| import org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo; | ||
| import org.apache.hadoop.ozone.om.helpers.OmKeyArgs; | ||
| import org.apache.hadoop.ozone.om.helpers.OmKeyInfo; | ||
| import org.apache.hadoop.ozone.om.helpers.OmMultipartUploadList; | ||
|
|
@@ -41,6 +43,7 @@ | |
| import org.apache.hadoop.ozone.om.service.SnapshotDeletingService; | ||
| import org.apache.hadoop.ozone.om.service.SnapshotDirectoryCleaningService; | ||
| import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.ExpiredMultipartUploadsBucket; | ||
| import org.apache.ratis.util.function.CheckedFunction; | ||
|
|
||
| /** | ||
| * Handles key level commands. | ||
|
|
@@ -84,7 +87,6 @@ OmKeyInfo lookupKey(OmKeyArgs args, ResolvedBucket bucketLayout, | |
| OmKeyInfo getKeyInfo(OmKeyArgs args, ResolvedBucket buctket, | ||
| String clientAddress) throws IOException; | ||
|
|
||
|
|
||
| /** | ||
| * Returns a list of keys represented by {@link OmKeyInfo} | ||
| * in the given bucket. | ||
|
|
@@ -135,6 +137,18 @@ List<Table.KeyValue<String, String>> getRenamesKeyEntries( | |
| String volume, String bucket, String startKey, int size) throws IOException; | ||
|
|
||
|
|
||
| /** | ||
| * Returns the previous snapshot's ozone directorInfo corresponding for the object. | ||
| */ | ||
| CheckedFunction<KeyManager, OmDirectoryInfo, IOException> getPreviousSnapshotOzoneDirInfo( | ||
| long volumeId, OmBucketInfo bucketInfo, OmDirectoryInfo directoryInfo) throws IOException; | ||
|
|
||
| /** | ||
| * Returns the previous snapshot's ozone directoryInfo corresponding for the object. | ||
| */ | ||
| CheckedFunction<KeyManager, OmDirectoryInfo, IOException> getPreviousSnapshotOzoneDirInfo( | ||
| long volumeId, OmBucketInfo bucketInfo, OmKeyInfo directoryInfo) throws IOException; | ||
|
Comment on lines
+149
to
+150
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it supposed to be a |
||
|
|
||
| /** | ||
| * Returns a list deleted entries from the deletedTable. | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -174,6 +174,7 @@ | |
| import org.apache.hadoop.security.SecurityUtil; | ||
| import org.apache.hadoop.util.ReflectionUtils; | ||
| import org.apache.hadoop.util.Time; | ||
| import org.apache.ratis.util.function.CheckedFunction; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
|
|
@@ -774,6 +775,33 @@ public List<Table.KeyValue<String, String>> getRenamesKeyEntries( | |
| } | ||
| } | ||
|
|
||
| @Override | ||
| public CheckedFunction<KeyManager, OmDirectoryInfo, IOException> getPreviousSnapshotOzoneDirInfo( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where and how will this be used?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be used in the DirectoryDeletingService where the deletedDeletedDirectory table would have OmKeyInfo whereas the directory table would have OmDirectoryInfo |
||
| long volumeId, OmBucketInfo bucketInfo, OmDirectoryInfo keyInfo) throws IOException { | ||
| String currentKeyPath = metadataManager.getOzonePathKey(volumeId, bucketInfo.getObjectID(), | ||
| keyInfo.getParentObjectID(), keyInfo.getName()); | ||
| return getPreviousSnapshotOzonePathInfo(bucketInfo, keyInfo.getObjectID(), currentKeyPath, | ||
| (km) -> km.getMetadataManager().getDirectoryTable()); | ||
| } | ||
|
|
||
| @Override | ||
| public CheckedFunction<KeyManager, OmDirectoryInfo, IOException> getPreviousSnapshotOzoneDirInfo( | ||
| long volumeId, OmBucketInfo bucketInfo, OmKeyInfo keyInfo) throws IOException { | ||
| String currentKeyPath = metadataManager.getOzonePathKey(volumeId, bucketInfo.getObjectID(), | ||
| keyInfo.getParentObjectID(), keyInfo.getFileName()); | ||
| return getPreviousSnapshotOzonePathInfo(bucketInfo, keyInfo.getObjectID(), currentKeyPath, | ||
| (previousSnapshotKM) -> previousSnapshotKM.getMetadataManager().getDirectoryTable()); | ||
| } | ||
|
|
||
| private <T> CheckedFunction<KeyManager, T, IOException> getPreviousSnapshotOzonePathInfo( | ||
| OmBucketInfo bucketInfo, long objectId, String currentKeyPath, | ||
| Function<KeyManager, Table<String, T>> table) throws IOException { | ||
| String renameKey = metadataManager.getRenameKey(bucketInfo.getVolumeName(), bucketInfo.getBucketName(), objectId); | ||
| String renamedKey = metadataManager.getSnapshotRenamedTable().getIfExist(renameKey); | ||
| return (previousSnapshotKM) -> table.apply(previousSnapshotKM).get( | ||
| renamedKey != null ? renamedKey : currentKeyPath); | ||
| } | ||
|
|
||
| @Override | ||
| public List<Table.KeyValue<String, List<OmKeyInfo>>> getDeletedKeyEntries( | ||
| String volume, String bucket, String startKey, int size) throws IOException { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| * 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.filter; | ||
|
|
||
| import java.io.IOException; | ||
| import org.apache.hadoop.hdds.utils.db.Table; | ||
| import org.apache.hadoop.ozone.om.KeyManager; | ||
| 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.OmBucketInfo; | ||
| import org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo; | ||
| import org.apache.hadoop.ozone.om.helpers.OmKeyInfo; | ||
| import org.apache.hadoop.ozone.om.helpers.SnapshotInfo; | ||
| import org.apache.hadoop.ozone.om.lock.IOzoneManagerLock; | ||
| import org.apache.hadoop.ozone.om.snapshot.ReferenceCounted; | ||
|
|
||
| /** | ||
| * Class to filter out deleted directories which are reclaimable based on their presence in previous snapshot in | ||
| * the snapshot chain. | ||
| */ | ||
| public class ReclaimableDirFilter extends ReclaimableFilter<OmKeyInfo> { | ||
|
|
||
| public ReclaimableDirFilter(OzoneManager ozoneManager, | ||
| OmSnapshotManager omSnapshotManager, SnapshotChainManager snapshotChainManager, | ||
| SnapshotInfo currentSnapshotInfo, KeyManager keyManager, | ||
| IOzoneManagerLock lock) { | ||
| super(ozoneManager, omSnapshotManager, snapshotChainManager, currentSnapshotInfo, keyManager, lock, 1); | ||
| } | ||
|
|
||
| @Override | ||
| protected String getVolumeName(Table.KeyValue<String, OmKeyInfo> keyValue) throws IOException { | ||
| return keyValue.getValue().getVolumeName(); | ||
| } | ||
|
|
||
| @Override | ||
| protected String getBucketName(Table.KeyValue<String, OmKeyInfo> keyValue) throws IOException { | ||
| return keyValue.getValue().getBucketName(); | ||
| } | ||
|
|
||
| @Override | ||
| protected Boolean isReclaimable(Table.KeyValue<String, OmKeyInfo> deletedDirInfo) throws IOException { | ||
| ReferenceCounted<OmSnapshot> previousSnapshot = getPreviousOmSnapshot(0); | ||
swamirishi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| KeyManager prevKeyManager = previousSnapshot == null ? null : previousSnapshot.get().getKeyManager(); | ||
| return isDirReclaimable(getVolumeId(), getBucketInfo(), deletedDirInfo.getValue(), getKeyManager(), prevKeyManager); | ||
| } | ||
|
|
||
| private boolean isDirReclaimable(long volumeId, OmBucketInfo bucketInfo, OmKeyInfo dirInfo, | ||
| KeyManager keyManager, KeyManager previousKeyManager) throws IOException { | ||
| if (previousKeyManager == null) { | ||
| return true; | ||
| } | ||
| OmDirectoryInfo prevDirectoryInfo = | ||
| keyManager.getPreviousSnapshotOzoneDirInfo(volumeId, bucketInfo, dirInfo).apply(previousKeyManager); | ||
| return prevDirectoryInfo == null || prevDirectoryInfo.getObjectID() != dirInfo.getObjectID(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if the directory object is not in the previous snapshot, or the object id is not the same (the directory was deleted and then a new one was created), then it is reclaimable.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah |
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.