adoroszlai commented on code in PR #9506:
URL: https://github.com/apache/ozone/pull/9506#discussion_r2622148555


##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmKeyInfo.java:
##########
@@ -492,7 +488,7 @@ public static class Builder extends 
WithParentObjectId.Builder<OmKeyInfo> {
     private FileChecksum fileChecksum;
 
     private boolean isFile;
-    private final Map<String, String> tags = new HashMap<>();
+    private MapBuilder<String, String> tags = MapBuilder.empty();

Review Comment:
   Let's not eagerly create an empty one, set it in the no-arg constructor 
instread:
   
   ```java
       private final MapBuilder<String, String> tags;
   
       public Builder() {
         this.acls = AclListBuilder.empty();
         this.tags = MapBuilder.empty();
       }
   ```
   
   `private Builder(AclListBuilder acls)` becomes unused and can be removed.



##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmKeyInfo.java:
##########
@@ -519,9 +515,10 @@ public Builder(OmKeyInfo obj) {
       this.fileChecksum = obj.fileChecksum;
       this.isFile = obj.isFile;
       this.expectedDataGeneration = obj.expectedDataGeneration;
-      if (obj.getTags() != null) {
-        this.tags.putAll(obj.getTags());
-      }
+      this.tags = obj.tags.isEmpty()
+          ? MapBuilder.empty()
+          : MapBuilder.of(obj.tags);

Review Comment:
   No need to handle empty map here.
   
   ```suggestion
         this.tags = MapBuilder.of(obj.tags);
   ```



##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmKeyInfo.java:
##########
@@ -658,18 +655,25 @@ public Builder setFile(boolean isAFile) {
     }
 
     public Builder setTags(Map<String, String> tags) {
-      this.tags.clear();
-      addAllTags(tags);
+      if (tags == null || tags.isEmpty()) {
+        this.tags = MapBuilder.empty();
+      } else if (tags instanceof ImmutableMap) {
+        this.tags = MapBuilder.of((ImmutableMap<String, String>) tags);
+      } else {
+        this.tags = MapBuilder.copyOf(tags);
+      }
       return this;
     }
 
     public Builder addTag(String key, String value) {
-      tags.put(key, value);
+      this.tags.put(key, value);
       return this;
     }
 
     public Builder addAllTags(Map<String, String> keyTags) {
-      tags.putAll(keyTags);
+      if (keyTags != null && !keyTags.isEmpty()) {
+        this.tags.putAll(keyTags);
+      }

Review Comment:
   No need to handle special cases.
   
   ```suggestion
         tags.putAll(keyTags);
   ```



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/tagging/S3PutObjectTaggingRequestWithFSO.java:
##########
@@ -117,10 +117,8 @@ public OMClientResponse 
validateAndUpdateCache(OzoneManager ozoneManager, Execut
           omKeyInfo.getParentObjectID(), omKeyInfo.getFileName());
 
       // Set the tags

Review Comment:
   nit: let's remove both comments consistently
   
   ```suggestion
   ```



##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmKeyInfo.java:
##########
@@ -519,9 +515,10 @@ public Builder(OmKeyInfo obj) {
       this.fileChecksum = obj.fileChecksum;
       this.isFile = obj.isFile;
       this.expectedDataGeneration = obj.expectedDataGeneration;
-      if (obj.getTags() != null) {
-        this.tags.putAll(obj.getTags());
-      }
+      this.tags = obj.tags.isEmpty()
+          ? MapBuilder.empty()
+          : MapBuilder.of(obj.tags);
+      this.acls.addAll(obj.getAcls());

Review Comment:
   This is probably restored due to merge conflict, as it's taken care of by 
`this.acls = AclListBuilder.of(obj.acls);` above.
   
   ```suggestion
   ```



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/tagging/S3DeleteObjectTaggingRequestWithFSO.java:
##########
@@ -116,9 +117,9 @@ public OMClientResponse validateAndUpdateCache(OzoneManager 
ozoneManager, Execut
           omKeyInfo.getParentObjectID(), omKeyInfo.getFileName());
 
       // Clear / delete the tags
-      omKeyInfo.getTags().clear();
       // Set the UpdateId to the current transactionLogIndex

Review Comment:
   nit: let's remove both comments consistently
   
   ```suggestion
   ```



##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmKeyInfo.java:
##########
@@ -658,18 +655,25 @@ public Builder setFile(boolean isAFile) {
     }
 
     public Builder setTags(Map<String, String> tags) {
-      this.tags.clear();
-      addAllTags(tags);
+      if (tags == null || tags.isEmpty()) {
+        this.tags = MapBuilder.empty();
+      } else if (tags instanceof ImmutableMap) {
+        this.tags = MapBuilder.of((ImmutableMap<String, String>) tags);
+      } else {
+        this.tags = MapBuilder.copyOf(tags);
+      }

Review Comment:
   Please do not create new `MapBuilder`.
   
   ```suggestion
         this.tags.set(tags);
   ```



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/tagging/S3DeleteObjectTaggingRequestWithFSO.java:
##########
@@ -116,9 +117,9 @@ public OMClientResponse validateAndUpdateCache(OzoneManager 
ozoneManager, Execut
           omKeyInfo.getParentObjectID(), omKeyInfo.getFileName());
 
       // Clear / delete the tags

Review Comment:
   nit: let's remove both comments consistently
   
   ```suggestion
   ```



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/tagging/S3PutObjectTaggingRequest.java:
##########
@@ -128,10 +128,8 @@ public OMClientResponse 
validateAndUpdateCache(OzoneManager ozoneManager, Execut
       }
 
       // Set the tags

Review Comment:
   nit: let's remove both comments consistently
   
   ```suggestion
   ```



-- 
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]

Reply via email to