Cyrill commented on code in PR #5144:
URL: https://github.com/apache/ozone/pull/5144#discussion_r1320758353


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManagerUtils.java:
##########
@@ -81,122 +110,79 @@ public static BucketLayout 
getBucketLayout(OMMetadataManager metadataManager,
                                              String volName,
                                              String buckName)
       throws IOException {
-    return getBucketLayout(metadataManager, volName, buckName, new 
HashSet<>());
+    return getResolvedBucketInfo(metadataManager, volName, buckName, false)
+        .getBucketLayout();
   }
 
   /**
-   * Get bucket layout for the given volume and bucket name.
+   * Get bucket info for the given volume and bucket name.
    *
    * @param metadataManager metadata manager
    * @param volName         volume name
    * @param buckName        bucket name
-   * @return bucket layout
+   * @return bucket info
    * @throws IOException
    */
-  private static BucketLayout getBucketLayout(OMMetadataManager 
metadataManager,
-                                              String volName,
-                                              String buckName,
-                                              Set<Pair<String, String>> 
visited)
+  public static OmBucketInfo getResolvedBucketInfo(
+      OMMetadataManager metadataManager,
+      String volName,
+      String buckName,
+      boolean allowDanglingBuckets)
       throws IOException {
-
-    OmBucketInfo buckInfo = getOmBucketInfo(metadataManager, volName, 
buckName);
-
-    if (buckInfo != null) {
-      // If this is a link bucket, we fetch the BucketLayout from the
-      // source bucket.
-      if (buckInfo.isLink()) {
-        // Check if this bucket was already visited - to avoid loops
-        if (!visited.add(Pair.of(volName, buckName))) {
-          throw new OMException("Detected loop in bucket links. Bucket name: " 
+
-              buckName + ", Volume name: " + volName,
-              DETECTED_LOOP_IN_BUCKET_LINKS);
-        }
-        OmBucketInfo sourceBuckInfo =
-            getOmBucketInfo(metadataManager, buckInfo.getSourceVolume(),
-                buckInfo.getSourceBucket());
-        if (sourceBuckInfo != null) {
-          /** If the source bucket is again a link, we recursively resolve the
-           * link bucket.
-           *
-           * For example:
-           * buck-link1 -> buck-link2 -> buck-link3 -> buck-src
-           * buck-src has the actual BucketLayout that will be used by the
-           * links.
-           */
-          if (sourceBuckInfo.isLink()) {
-            return getBucketLayout(metadataManager,
-                sourceBuckInfo.getVolumeName(),
-                sourceBuckInfo.getBucketName(), visited);
-          }
-          return sourceBuckInfo.getBucketLayout();
-        }
-      }
-      return buckInfo.getBucketLayout();
-    }
-
-    if (!metadataManager.getVolumeTable()
-        .isExist(metadataManager.getVolumeKey(volName))) {
-      throw new OMException("Volume not found: " + volName,
-          OMException.ResultCodes.VOLUME_NOT_FOUND);
-    }
-
-    throw new OMException("Bucket not found: " + volName + "/" + buckName,
-        OMException.ResultCodes.BUCKET_NOT_FOUND);
+    return resolveBucketInfoLink(metadataManager, volName, buckName,
+        new HashSet<>(), allowDanglingBuckets);
   }
 
   /**
-   * Resolve bucket layout for a given link bucket's OmBucketInfo.
+   * Get bucket info for the given volume and bucket name.
    *
-   * @param bucketInfo
-   * @return {@code OmBucketInfo} with
+   * @param metadataManager metadata manager
+   * @param volName         volume name
+   * @param buckName        bucket name
+   * @return bucket info

Review Comment:
   Done



-- 
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: issues-unsubscr...@ozone.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org
For additional commands, e-mail: issues-h...@ozone.apache.org

Reply via email to