-
Notifications
You must be signed in to change notification settings - Fork 621
HDDS-15624. Resolve link bucket properties in listBucket. #10745
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
09b7638
8e4b1d3
64acd33
87b4d42
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 |
|---|---|---|
|
|
@@ -2993,8 +2993,18 @@ public List<OmBucketInfo> listBuckets(String volumeName, String startKey, | |
| volumeName, null, null); | ||
| } | ||
| metrics.incNumBucketLists(); | ||
| return bucketManager.listBuckets(volumeName, | ||
| List<OmBucketInfo> buckets = bucketManager.listBuckets(volumeName, | ||
|
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. i don't like that the list buckets is a short lived object. it would be nice if we can reuse this list object.
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. Updated the commit to reuse the list. |
||
| startKey, prefix, maxNumOfBuckets, hasSnapshot); | ||
| Map<Pair<String, String>, OmBucketInfo> resolvedSourceCache = new HashMap<>(); | ||
| for (int i = 0; i < buckets.size(); i++) { | ||
| try { | ||
| buckets.set(i, enrichLinkBucketInfo(buckets.get(i), resolvedSourceCache)); | ||
| } catch (IOException e) { | ||
| LOG.debug("Failed to enrich listBuckets entry for {}/{}; returning raw entry", | ||
| volumeName, buckets.get(i).getBucketName(), e); | ||
| } | ||
| } | ||
| return buckets; | ||
| } catch (IOException ex) { | ||
| metrics.incNumBucketListFails(); | ||
| auditSuccess = false; | ||
|
|
@@ -3009,6 +3019,62 @@ public List<OmBucketInfo> listBuckets(String volumeName, String startKey, | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * For link buckets, follows the link chain and overlays the source bucket's | ||
| * operational properties onto the link's {@link OmBucketInfo}. Non-link | ||
| * buckets and dangling links are returned unchanged. | ||
| */ | ||
| private OmBucketInfo enrichLinkBucketInfo(OmBucketInfo bucketInfo) | ||
| throws IOException { | ||
| return enrichLinkBucketInfo(bucketInfo, null); | ||
| } | ||
|
|
||
| private OmBucketInfo enrichLinkBucketInfo( | ||
| OmBucketInfo bucketInfo, | ||
| Map<Pair<String, String>, OmBucketInfo> resolvedSourceCache) | ||
| throws IOException { | ||
| if (!bucketInfo.isLink()) { | ||
| return bucketInfo; | ||
| } | ||
| // We already know that `bucketInfo` is a linked one, | ||
| // so we skip one `getBucketInfo` and start with the known link. | ||
| ResolvedBucket resolvedBucket = | ||
| resolveBucketLink(Pair.of( | ||
| bucketInfo.getSourceVolume(), | ||
| bucketInfo.getSourceBucket()), | ||
| true); | ||
|
|
||
| // If it is a dangling link it means no real bucket exists, | ||
| // for example, it could have been deleted, but the links still present. | ||
| if (resolvedBucket.isDangling()) { | ||
| return bucketInfo; | ||
| } | ||
| OmBucketInfo realBucket = getResolvedSourceBucket(resolvedBucket, resolvedSourceCache); | ||
| return bucketInfo.withOperationalPropertiesFrom(realBucket); | ||
| } | ||
|
|
||
| private OmBucketInfo getResolvedSourceBucket( | ||
| ResolvedBucket resolvedBucket, | ||
| Map<Pair<String, String>, OmBucketInfo> resolvedSourceCache) | ||
| throws IOException { | ||
| Pair<String, String> sourceKey = Pair.of( | ||
| resolvedBucket.realVolume(), | ||
| resolvedBucket.realBucket()); | ||
| if (resolvedSourceCache != null) { | ||
| OmBucketInfo cachedSource = resolvedSourceCache.get(sourceKey); | ||
| if (cachedSource != null) { | ||
| return cachedSource; | ||
| } | ||
| } | ||
| OmBucketInfo realBucket = bucketManager.getBucketInfo( | ||
| resolvedBucket.realVolume(), | ||
| resolvedBucket.realBucket()); | ||
| if (resolvedSourceCache != null) { | ||
| resolvedSourceCache.put(sourceKey, realBucket); | ||
| } | ||
| return realBucket; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the bucket information. | ||
| * | ||
|
|
@@ -3030,46 +3096,8 @@ public OmBucketInfo getBucketInfo(String volume, String bucket) | |
| } | ||
| metrics.incNumBucketInfos(); | ||
|
|
||
| OmBucketInfo bucketInfo = bucketManager.getBucketInfo(volume, bucket); | ||
|
|
||
| // No links - return the bucket info right away. | ||
| if (!bucketInfo.isLink()) { | ||
| return bucketInfo; | ||
| } | ||
| // Otherwise follow the links to find the real bucket. | ||
| // We already know that `bucketInfo` is a linked one, | ||
| // so we skip one `getBucketInfo` and start with the known link. | ||
| ResolvedBucket resolvedBucket = | ||
| resolveBucketLink(Pair.of( | ||
| bucketInfo.getSourceVolume(), | ||
| bucketInfo.getSourceBucket()), | ||
| true); | ||
|
|
||
| // If it is a dangling link it means no real bucket exists, | ||
| // for example, it could have been deleted, but the links still present. | ||
| if (!resolvedBucket.isDangling()) { | ||
| OmBucketInfo realBucket = | ||
| bucketManager.getBucketInfo( | ||
| resolvedBucket.realVolume(), | ||
| resolvedBucket.realBucket()); | ||
| // Pass the real bucket metadata in the link bucket info. | ||
| return bucketInfo.toBuilder() | ||
| .setDefaultReplicationConfig( | ||
| realBucket.getDefaultReplicationConfig()) | ||
| .setIsVersionEnabled(realBucket.getIsVersionEnabled()) | ||
| .setStorageType(realBucket.getStorageType()) | ||
| .setQuotaInBytes(realBucket.getQuotaInBytes()) | ||
| .setQuotaInNamespace(realBucket.getQuotaInNamespace()) | ||
| .setUsedBytes(realBucket.getUsedBytes()) | ||
| .setSnapshotUsedBytes(realBucket.getSnapshotUsedBytes()) | ||
| .setSnapshotUsedNamespace(realBucket.getSnapshotUsedNamespace()) | ||
| .setUsedNamespace(realBucket.getUsedNamespace()) | ||
| .addAllMetadata(realBucket.getMetadata()) | ||
| .setBucketLayout(realBucket.getBucketLayout()) | ||
| .build(); | ||
| } | ||
| // If no real bucket exists, return the requested one's info. | ||
| return bucketInfo; | ||
| return enrichLinkBucketInfo( | ||
| bucketManager.getBucketInfo(volume, bucket)); | ||
| } catch (Exception ex) { | ||
| metrics.incNumBucketInfoFails(); | ||
| auditSuccess = false; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is good.