rakeshadr commented on code in PR #3277:
URL: https://github.com/apache/ozone/pull/3277#discussion_r843772443
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/KeyManagerImpl.java:
##########
@@ -830,7 +831,9 @@ public boolean addAcl(OzoneObj obj, OzoneAcl acl) throws
IOException {
OMFileRequest.validateBucket(metadataManager, volume, bucket);
String objectKey = metadataManager.getOzoneKey(volume, bucket, keyName);
OmKeyInfo keyInfo = metadataManager
- .getKeyTable(getBucketLayout(metadataManager, volume, bucket))
+ .getKeyTable(
Review Comment:
Instead of chained calls, would be good to keep the calls separately for
better readability. Please do like below. Also, please apply this to all the
similar occurrences in this class and other places in the patch.
```
BucketLayout bLayout = OzoneManagerUtils.getBucketLayout(volume, bucket,
ozoneManager, new HashSet<>();
metadataManager.getKeyTable(bLayout).get(objectKey);
```
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManagerUtils.java:
##########
@@ -121,11 +122,19 @@ public static BucketLayout getBucketLayout(String volName,
}
}
return buckInfo.getBucketLayout();
- } else {
- LOG.error("Bucket not found: {}/{} ", volName, buckName);
- // TODO: Handle bucket validation
}
- return BucketLayout.DEFAULT;
+ LOG.error("Could not get BucketLayout. Volume: {}, Bucket: {} ", volName,
+ buckName);
+ OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
+ OmVolumeArgs volumeArgs = omMetadataManager.getVolumeTable()
+ .get(omMetadataManager.getVolumeKey(volName));
+ if (volumeArgs == null) {
+ throw new OMException("Could not get BucketLayout. Volume not found: "
+ + volName, OMException.ResultCodes.VOLUME_NOT_FOUND);
+ }
+ throw new OMException("Could not get BucketLayout." +
Review Comment:
I think exception/log details are redundant and can be improved. How about
to modify the code:
```
OzoneManagerUtils.java
private static OmBucketInfo getOmBucketInfo(OzoneManager ozoneManager,
String volName, String buckName) throws IOException {
String buckKey =
ozoneManager.getMetadataManager().getBucketKey(volName, buckName);
return ozoneManager.getMetadataManager().getBucketTable().get(buckKey);
}
```
```
public static BucketLayout getBucketLayout(...) {
OmBucketInfo buckInfo = getOmBucketInfo(ozoneManager, volName, buckName);
if (buckInfo != null) {
.........
.........
return buckInfo.getBucketLayout();
}
OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
if (!omMetadataManager.getVolumeTable()
.isExist(omMetadataManager.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);
```
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/KeyManagerImpl.java:
##########
@@ -2339,8 +2360,8 @@ public OmKeyInfo getPendingDeletionDir() throws
IOException {
long countEntries = 0;
Table fileTable = metadataManager.getKeyTable(
- getBucketLayout(metadataManager, parentInfo.getVolumeName(),
- parentInfo.getBucketName()));
+ OzoneManagerUtils.getBucketLayout(parentInfo.getVolumeName(),
Review Comment:
Please add an overloaded method in `OzoneManagerUtils.java` to reduce the
number of args at the caller side. Many places its passing `new HashSet<>()`,
this can be moved to inside overloaded new method. Also, you can make the
existing `#getBucketLayout()` method to private access specifier.
**OzoneManagerUtils.java**
```
/**
* Get bucket layout for the given volume and bucket name.
*
* @param volName volume name
* @param buckName bucket name
* @param ozoneManager ozone manager
* @return bucket layout
* @throws IOException
*/
public static BucketLayout getBucketLayout(String volName,
String buckName, OzoneManager ozoneManager) throws IOException {
return getBucketLayout(volName, buckName, ozoneManager, new HashSet<>());
}
```
```
private static BucketLayout getBucketLayout(String volName,
String buckName, OzoneManager ozoneManager,
Set<Pair<String, String>> visited) throws IOException {
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]