-
Notifications
You must be signed in to change notification settings - Fork 622
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 9 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,223 @@ | ||||||||||
| /* | ||||||||||
| * 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 org.slf4j.Logger; | ||||||||||
| import org.slf4j.LoggerFactory; | ||||||||||
|
|
||||||||||
| import java.io.IOException; | ||||||||||
| import java.util.List; | ||||||||||
|
|
||||||||||
| import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX; | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Class for handling Legacy buckets. | ||||||||||
|
ArafatKhan2198 marked this conversation as resolved.
Outdated
|
||||||||||
| */ | ||||||||||
| public class OBSBucketHandler extends BucketHandler { | ||||||||||
|
|
||||||||||
| private static final Logger LOG = LoggerFactory.getLogger( | ||||||||||
| OBSBucketHandler.class); | ||||||||||
|
|
||||||||||
| 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 | ||||||||||
| */ | ||||||||||
| public EntityType determineKeyPath(String keyName) | ||||||||||
|
ArafatKhan2198 marked this conversation as resolved.
Outdated
|
||||||||||
| throws IOException { | ||||||||||
| String key = OM_KEY_PREFIX + vol + | ||||||||||
| OM_KEY_PREFIX + bucket + | ||||||||||
| OM_KEY_PREFIX + keyName; | ||||||||||
|
|
||||||||||
| Table<String, OmKeyInfo> keyTable = getKeyTable(); | ||||||||||
|
|
||||||||||
| TableIterator<String, ? extends Table.KeyValue<String, OmKeyInfo>> | ||||||||||
| iterator = keyTable.iterator(); | ||||||||||
|
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.
Also in all other similar code.
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. |
||||||||||
|
|
||||||||||
| 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 parent OBS 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 | ||||||||||
| */ | ||||||||||
| public long handleDirectKeys(long parentId, boolean withReplica, | ||||||||||
|
ArafatKhan2198 marked this conversation as resolved.
|
||||||||||
| boolean listFile, | ||||||||||
| List<DUResponse.DiskUsage> duData, | ||||||||||
| String normalizedPath) throws IOException { | ||||||||||
|
|
||||||||||
| Table<String, OmKeyInfo> keyTable = getKeyTable(); | ||||||||||
| long keyDataSizeWithReplica = 0L; | ||||||||||
|
|
||||||||||
| TableIterator<String, ? extends Table.KeyValue<String, OmKeyInfo>> | ||||||||||
| iterator = keyTable.iterator(); | ||||||||||
|
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. This one needs to be closed, too.
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. Thanks for pointing it out. |
||||||||||
|
|
||||||||||
| String seekPrefix = OM_KEY_PREFIX + | ||||||||||
| vol + | ||||||||||
| OM_KEY_PREFIX + | ||||||||||
| bucket + | ||||||||||
| OM_KEY_PREFIX; | ||||||||||
|
|
||||||||||
| 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. |
||||||||||
|
|
||||||||||
| 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; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Object stores do not support directories, hence return null. | ||||||||||
| * | ||||||||||
| * @return null | ||||||||||
| */ | ||||||||||
| public long calculateDUUnderObject(long parentId) | ||||||||||
|
ArafatKhan2198 marked this conversation as resolved.
Outdated
|
||||||||||
| throws IOException { | ||||||||||
| return Long.parseLong(null); | ||||||||||
|
ArafatKhan2198 marked this conversation as resolved.
Outdated
|
||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Object stores do not support directories, hence return null. | ||||||||||
| * | ||||||||||
| * @return null | ||||||||||
| */ | ||||||||||
| public long getDirObjectId(String[] names) throws IOException { | ||||||||||
|
ArafatKhan2198 marked this conversation as resolved.
Outdated
|
||||||||||
| return Long.parseLong(null); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Object stores do not support directories, hence return null. | ||||||||||
| * | ||||||||||
| * @return null | ||||||||||
| */ | ||||||||||
| public long getDirObjectId(String[] names, int cutoff) throws IOException { | ||||||||||
|
ArafatKhan2198 marked this conversation as resolved.
Outdated
|
||||||||||
| return Long.parseLong(null); | ||||||||||
|
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. This will throw NumberFormatException as null is not valid long. Can throw UnsupportedOperationException as this is not supported
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. Agreed.
(also for other similar code)
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. |
||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
| public OmKeyInfo getKeyInfo(String[] names) throws IOException { | ||||||||||
|
ArafatKhan2198 marked this conversation as 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. |
||||||||||
|
|
||||||||||
| OmKeyInfo keyInfo = getKeyTable().getSkipCache(ozoneKey); | ||||||||||
| return keyInfo; | ||||||||||
|
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: inline the variable
Suggested change
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. |
||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Object stores do not support directories, hence return null. | ||||||||||
| * | ||||||||||
| * @return null | ||||||||||
| */ | ||||||||||
| @Override | ||||||||||
| public OmDirectoryInfo getDirInfo(String[] names) throws IOException { | ||||||||||
| return null; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public Table<String, OmKeyInfo> getKeyTable() { | ||||||||||
| Table keyTable = | ||||||||||
| getOmMetadataManager().getKeyTable(getBucketLayout()); | ||||||||||
| return keyTable; | ||||||||||
|
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
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. |
||||||||||
| } | ||||||||||
|
|
||||||||||
| public BucketLayout getBucketLayout() { | ||||||||||
| return BucketLayout.OBJECT_STORE; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| } | ||||||||||
Uh oh!
There was an error while loading. Please reload this page.