-
Notifications
You must be signed in to change notification settings - Fork 588
HDDS-7810. Support namespace summaries (du, dist & counts) for OBJECT_STORE buckets. #4245
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
49ef9e8
a47e09f
0c2005f
6031ad5
4c28bc9
fd81752
606044a
4fe5ef8
17df34d
da7f4e1
37c0438
e9f0c4b
2655425
f610de0
9c53399
c5d3b27
68ab58f
ddd1a3b
76597a4
5ab09d3
ac2f003
297be0c
01f817b
913662e
57801b2
3e8ec2a
576b4c0
76158c9
cf04f83
dca31d3
1d2d0b5
e1120ae
0555a7f
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 | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,268 @@ | ||||||||
| /* | ||||||||
| * 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.recon.api.handlers; | ||||||||
|
|
||||||||
|
|
||||||||
| import org.apache.hadoop.hdds.scm.server.OzoneStorageContainerManager; | ||||||||
| import org.apache.hadoop.hdds.utils.db.Table; | ||||||||
| import org.apache.hadoop.hdds.utils.db.TableIterator; | ||||||||
| import org.apache.hadoop.ozone.om.helpers.BucketLayout; | ||||||||
| 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.recon.api.types.DUResponse; | ||||||||
| import org.apache.hadoop.ozone.recon.api.types.EntityType; | ||||||||
| import org.apache.hadoop.ozone.recon.api.types.NSSummary; | ||||||||
| import org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager; | ||||||||
| import org.apache.hadoop.ozone.recon.spi.ReconNamespaceSummaryManager; | ||||||||
|
|
||||||||
| import java.io.IOException; | ||||||||
| import java.util.List; | ||||||||
|
|
||||||||
| import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX; | ||||||||
|
|
||||||||
| /** | ||||||||
| * Class for handling OBS buckets NameSpaceSummaries. | ||||||||
| */ | ||||||||
| public class OBSBucketHandler extends BucketHandler { | ||||||||
|
|
||||||||
| private final String vol; | ||||||||
| private final String bucket; | ||||||||
| private final OmBucketInfo omBucketInfo; | ||||||||
|
|
||||||||
| public OBSBucketHandler( | ||||||||
| ReconNamespaceSummaryManager reconNamespaceSummaryManager, | ||||||||
| ReconOMMetadataManager omMetadataManager, | ||||||||
| OzoneStorageContainerManager reconSCM, | ||||||||
| OmBucketInfo bucketInfo) { | ||||||||
| super(reconNamespaceSummaryManager, omMetadataManager, | ||||||||
| reconSCM); | ||||||||
| this.omBucketInfo = bucketInfo; | ||||||||
| this.vol = omBucketInfo.getVolumeName(); | ||||||||
| this.bucket = omBucketInfo.getBucketName(); | ||||||||
| } | ||||||||
|
|
||||||||
| /** | ||||||||
| * Helper function to check if a path is a key, or invalid. | ||||||||
| * | ||||||||
| * @param keyName key name | ||||||||
| * @return KEY, or UNKNOWN | ||||||||
| * @throws IOException | ||||||||
| */ | ||||||||
| @Override | ||||||||
| public EntityType determineKeyPath(String keyName) throws IOException { | ||||||||
| String key = OM_KEY_PREFIX + vol + | ||||||||
| OM_KEY_PREFIX + bucket + | ||||||||
| OM_KEY_PREFIX + keyName; | ||||||||
|
|
||||||||
| Table<String, OmKeyInfo> keyTable = getKeyTable(); | ||||||||
|
|
||||||||
| try ( | ||||||||
| TableIterator<String, ? extends Table.KeyValue<String, OmKeyInfo>> | ||||||||
| iterator = keyTable.iterator()) { | ||||||||
| iterator.seek(key); | ||||||||
| if (iterator.hasNext()) { | ||||||||
| Table.KeyValue<String, OmKeyInfo> kv = iterator.next(); | ||||||||
| String dbKey = kv.getKey(); | ||||||||
| if (dbKey.equals(key)) { | ||||||||
| return EntityType.KEY; | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
| return EntityType.UNKNOWN; | ||||||||
| } | ||||||||
|
|
||||||||
| /** | ||||||||
| * This method handles disk usage of direct keys. | ||||||||
| * | ||||||||
| * @param parentId The identifier for the parent bucket. | ||||||||
| * @param withReplica if withReplica is enabled, set sizeWithReplica | ||||||||
| * for each direct key's DU | ||||||||
| * @param listFile if listFile is enabled, append key DU as a children | ||||||||
| * keys | ||||||||
| * @param duData the current DU data | ||||||||
| * @param normalizedPath the normalized path request | ||||||||
| * @return the total DU of all direct keys | ||||||||
| * @throws IOException IOE | ||||||||
| */ | ||||||||
| @Override | ||||||||
| public long handleDirectKeys(long parentId, boolean withReplica, | ||||||||
| boolean listFile, | ||||||||
| List<DUResponse.DiskUsage> duData, | ||||||||
| String normalizedPath) throws IOException { | ||||||||
|
|
||||||||
| NSSummary nsSummary = getReconNamespaceSummaryManager() | ||||||||
| .getNSSummary(parentId); | ||||||||
| // Handle the case of an empty bucket. | ||||||||
| if (nsSummary == null) { | ||||||||
| return 0; | ||||||||
| } | ||||||||
|
Comment on lines
+109
to
+114
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. Check at the start of the method.
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. Thank you for the suggestion. I have implemented the recommended changes. |
||||||||
|
|
||||||||
| Table<String, OmKeyInfo> keyTable = getKeyTable(); | ||||||||
| long keyDataSizeWithReplica = 0L; | ||||||||
|
|
||||||||
| try ( | ||||||||
| TableIterator<String, ? extends Table.KeyValue<String, OmKeyInfo>> | ||||||||
| iterator = keyTable.iterator()) { | ||||||||
|
|
||||||||
| String seekPrefix = OM_KEY_PREFIX + | ||||||||
| vol + | ||||||||
| OM_KEY_PREFIX + | ||||||||
| bucket + | ||||||||
| OM_KEY_PREFIX; | ||||||||
|
|
||||||||
| iterator.seek(seekPrefix); | ||||||||
|
|
||||||||
| while (iterator.hasNext()) { | ||||||||
| // KeyName : OmKeyInfo-Object | ||||||||
| Table.KeyValue<String, OmKeyInfo> kv = iterator.next(); | ||||||||
| String dbKey = kv.getKey(); | ||||||||
|
|
||||||||
| // Exit loop if the key doesn't match the seekPrefix. | ||||||||
| if (!dbKey.startsWith(seekPrefix)) { | ||||||||
| break; | ||||||||
| } | ||||||||
|
|
||||||||
| OmKeyInfo keyInfo = kv.getValue(); | ||||||||
| if (keyInfo != null) { | ||||||||
| DUResponse.DiskUsage diskUsage = new DUResponse.DiskUsage(); | ||||||||
| String objectName = keyInfo.getKeyName(); | ||||||||
| diskUsage.setSubpath(objectName); | ||||||||
| diskUsage.setKey(true); | ||||||||
| diskUsage.setSize(keyInfo.getDataSize()); | ||||||||
|
|
||||||||
| if (withReplica) { | ||||||||
| long keyDU = keyInfo.getReplicatedSize(); | ||||||||
| keyDataSizeWithReplica += keyDU; | ||||||||
| diskUsage.setSizeWithReplica(keyDU); | ||||||||
| } | ||||||||
| // List all the keys for the OBS bucket if requested. | ||||||||
| if (listFile) { | ||||||||
| duData.add(diskUsage); | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| return keyDataSizeWithReplica; | ||||||||
| } | ||||||||
|
|
||||||||
| /** | ||||||||
| * Calculates the total disk usage (DU) for an Object Store Bucket (OBS) by | ||||||||
| * summing the sizes of all keys contained within the bucket. | ||||||||
| * Since OBS buckets operate on a flat hierarchy, this method iterates through | ||||||||
| * all the keys in the bucket without the need to traverse directories. | ||||||||
| * | ||||||||
| * @param parentId The identifier for the parent bucket. | ||||||||
| * @return The total disk usage of all keys within the specified OBS bucket. | ||||||||
| * @throws IOException | ||||||||
| */ | ||||||||
| @Override | ||||||||
| public long calculateDUUnderObject(long parentId) throws IOException { | ||||||||
| // Initialize the total disk usage variable. | ||||||||
| long totalDU = 0L; | ||||||||
|
|
||||||||
| // Access the key table for the bucket. | ||||||||
| Table<String, OmKeyInfo> keyTable = getKeyTable(); | ||||||||
|
|
||||||||
| try ( | ||||||||
| TableIterator<String, ? extends Table.KeyValue<String, OmKeyInfo>> | ||||||||
| iterator = keyTable.iterator()) { | ||||||||
| // Construct the seek prefix to filter keys under this bucket. | ||||||||
| String seekPrefix = | ||||||||
| OM_KEY_PREFIX + vol + OM_KEY_PREFIX + bucket + OM_KEY_PREFIX; | ||||||||
| iterator.seek(seekPrefix); | ||||||||
|
|
||||||||
| // Iterate over keys in the bucket. | ||||||||
| while (iterator.hasNext()) { | ||||||||
| Table.KeyValue<String, OmKeyInfo> kv = iterator.next(); | ||||||||
| String keyName = kv.getKey(); | ||||||||
|
|
||||||||
| // Break the loop if the current key does not start with the seekPrefix. | ||||||||
| if (!keyName.startsWith(seekPrefix)) { | ||||||||
| break; | ||||||||
| } | ||||||||
|
|
||||||||
| // Sum the size of each key to the total disk usage. | ||||||||
| OmKeyInfo keyInfo = kv.getValue(); | ||||||||
| if (keyInfo != null) { | ||||||||
| totalDU += keyInfo.getDataSize(); | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| // Return the total disk usage of all keys in the bucket. | ||||||||
| return totalDU; | ||||||||
| } | ||||||||
|
|
||||||||
| /** | ||||||||
| * Object stores do not support directories. | ||||||||
| * | ||||||||
| * @throws UnsupportedOperationException | ||||||||
| */ | ||||||||
| @Override | ||||||||
| public long getDirObjectId(String[] names) | ||||||||
| throws UnsupportedOperationException { | ||||||||
| throw new UnsupportedOperationException( | ||||||||
| "Object stores do not support directories."); | ||||||||
| } | ||||||||
|
|
||||||||
| /** | ||||||||
| * Object stores do not support directories. | ||||||||
| * | ||||||||
| * @throws UnsupportedOperationException | ||||||||
| */ | ||||||||
| @Override | ||||||||
| public long getDirObjectId(String[] names, int cutoff) | ||||||||
| throws UnsupportedOperationException { | ||||||||
| throw new UnsupportedOperationException( | ||||||||
| "Object stores do not support directories."); | ||||||||
| } | ||||||||
|
|
||||||||
| /** | ||||||||
| * Returns the keyInfo object from the KEY table. | ||||||||
| * @return OmKeyInfo | ||||||||
| */ | ||||||||
| @Override | ||||||||
| public OmKeyInfo getKeyInfo(String[] names) throws IOException { | ||||||||
ArafatKhan2198 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| String ozoneKey = OM_KEY_PREFIX; | ||||||||
| ozoneKey += String.join(OM_KEY_PREFIX, names); | ||||||||
|
Comment on lines
+243
to
+244
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. nit:
Suggested change
I'm guessing there must be some utility method for this.
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. I have checked the utility classes in recon, and currently there is no utility method available for this specific line. All other handlers within the codebase also utilize the same join method. |
||||||||
|
|
||||||||
| return getKeyTable().getSkipCache(ozoneKey); | ||||||||
| } | ||||||||
|
|
||||||||
| /** | ||||||||
| * Object stores do not support directories. | ||||||||
| * | ||||||||
| * @throws UnsupportedOperationException | ||||||||
| */ | ||||||||
| @Override | ||||||||
| public OmDirectoryInfo getDirInfo(String[] names) throws IOException { | ||||||||
| throw new UnsupportedOperationException( | ||||||||
| "Object stores do not support directories."); | ||||||||
| } | ||||||||
|
|
||||||||
| public Table<String, OmKeyInfo> getKeyTable() { | ||||||||
| return getOmMetadataManager().getKeyTable(getBucketLayout()); | ||||||||
| } | ||||||||
|
|
||||||||
| public BucketLayout getBucketLayout() { | ||||||||
| return BucketLayout.OBJECT_STORE; | ||||||||
| } | ||||||||
|
|
||||||||
| } | ||||||||
Uh oh!
There was an error while loading. Please reload this page.