This is an automated email from the ASF dual-hosted git repository.

adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new 48ed1da2830 HDDS-14151. Use MapBuilder for tags in OmKeyInfo (#9506)
48ed1da2830 is described below

commit 48ed1da28308286cc2e9fc300aafa98ca9a83cbd
Author: Russole <[email protected]>
AuthorDate: Wed Dec 17 00:43:38 2025 +0800

    HDDS-14151. Use MapBuilder for tags in OmKeyInfo (#9506)
---
 .../apache/hadoop/ozone/om/helpers/OmKeyInfo.java  | 30 ++++++++--------------
 .../apache/hadoop/ozone/om/helpers/WithTags.java   |  2 --
 .../hadoop/ozone/om/helpers/TestOmKeyInfo.java     |  4 ++-
 .../s3/tagging/S3DeleteObjectTaggingRequest.java   |  3 ++-
 .../S3DeleteObjectTaggingRequestWithFSO.java       |  5 ++--
 .../s3/tagging/S3PutObjectTaggingRequest.java      |  5 +---
 .../tagging/S3PutObjectTaggingRequestWithFSO.java  |  5 +---
 .../tagging/TestS3DeleteObjectTaggingResponse.java |  5 +++-
 .../s3/tagging/TestS3PutObjectTaggingResponse.java |  4 ++-
 9 files changed, 26 insertions(+), 37 deletions(-)

diff --git 
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmKeyInfo.java
 
b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmKeyInfo.java
index acae1fd4fd6..7cfbf4172d4 100644
--- 
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmKeyInfo.java
+++ 
b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmKeyInfo.java
@@ -18,6 +18,7 @@
 package org.apache.hadoop.ozone.om.helpers;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
 import jakarta.annotation.Nullable;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -98,7 +99,7 @@ public final class OmKeyInfo extends WithParentObjectId
   /**
    * Used for S3 tags.
    */
-  private Map<String, String> tags;
+  private final ImmutableMap<String, String> tags;
 
   // expectedDataGeneration, when used in key creation indicates that a
   // key with the same keyName should exist with the given generation.
@@ -124,7 +125,7 @@ private OmKeyInfo(Builder b) {
     this.fileName = b.fileName;
     this.isFile = b.isFile;
     this.ownerName = b.ownerName;
-    this.tags = b.tags;
+    this.tags = b.tags.build();
     this.expectedDataGeneration = b.expectedDataGeneration;
   }
 
@@ -257,11 +258,6 @@ public Map<String, String> getTags() {
     return tags;
   }
 
-  @Override
-  public void setTags(Map<String, String> tags) {
-    this.tags = tags;
-  }
-
   /**
    * updates the length of the each block in the list given.
    * This will be called when the key is being committed to OzoneManager.
@@ -492,15 +488,12 @@ public static class Builder extends 
WithParentObjectId.Builder<OmKeyInfo> {
     private FileChecksum fileChecksum;
 
     private boolean isFile;
-    private final Map<String, String> tags = new HashMap<>();
+    private final MapBuilder<String, String> tags;
     private Long expectedDataGeneration = null;
 
     public Builder() {
-      this(AclListBuilder.empty());
-    }
-
-    private Builder(AclListBuilder acls) {
-      this.acls = acls;
+      this.acls = AclListBuilder.empty();
+      this.tags = MapBuilder.empty();
     }
 
     public Builder(OmKeyInfo obj) {
@@ -519,9 +512,7 @@ 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 = MapBuilder.of(obj.tags);
       obj.keyLocationVersions.forEach(keyLocationVersion ->
           this.omKeyLocationInfoGroups.add(
               new OmKeyLocationInfoGroup(keyLocationVersion.getVersion(),
@@ -658,18 +649,17 @@ public Builder setFile(boolean isAFile) {
     }
 
     public Builder setTags(Map<String, String> tags) {
-      this.tags.clear();
-      addAllTags(tags);
+      this.tags.set(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);
+      this.tags.putAll(keyTags);
       return this;
     }
 
diff --git 
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/WithTags.java
 
b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/WithTags.java
index 8445fe2af25..63b6a2cf390 100644
--- 
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/WithTags.java
+++ 
b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/WithTags.java
@@ -25,6 +25,4 @@
 public interface WithTags {
 
   Map<String, String> getTags();
-
-  void setTags(Map<String, String> tags);
 }
diff --git 
a/hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/helpers/TestOmKeyInfo.java
 
b/hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/helpers/TestOmKeyInfo.java
index 37670634bf9..285853a3a76 100644
--- 
a/hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/helpers/TestOmKeyInfo.java
+++ 
b/hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/helpers/TestOmKeyInfo.java
@@ -206,7 +206,9 @@ private void createdAndTest(boolean isMPU) {
     assertEquals(key.getAcls(), cloneKey.getAcls());
 
     // Change object tags and check
-    key.setTags(Collections.singletonMap("tagKey3", "tagValue3"));
+    key = key.toBuilder()
+        .setTags(Collections.singletonMap("tagKey3", "tagValue3"))
+        .build();
 
     assertNotEquals(key, cloneKey);
   }
diff --git 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/tagging/S3DeleteObjectTaggingRequest.java
 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/tagging/S3DeleteObjectTaggingRequest.java
index 78dae794450..f35b1e01959 100644
--- 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/tagging/S3DeleteObjectTaggingRequest.java
+++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/tagging/S3DeleteObjectTaggingRequest.java
@@ -21,6 +21,7 @@
 import static 
org.apache.hadoop.ozone.om.lock.OzoneManagerLock.LeveledResource.BUCKET_LOCK;
 
 import java.io.IOException;
+import java.util.Collections;
 import java.util.Map;
 import java.util.Objects;
 import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
@@ -127,9 +128,9 @@ public OMClientResponse validateAndUpdateCache(OzoneManager 
ozoneManager, Execut
       }
 
       // Clear / delete the tags
-      omKeyInfo.getTags().clear();
       // Set the UpdateID to the current transactionLogIndex
       omKeyInfo = omKeyInfo.toBuilder()
+          .setTags(Collections.emptyMap())
           .setUpdateID(trxnLogIndex)
           .build();
 
diff --git 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/tagging/S3DeleteObjectTaggingRequestWithFSO.java
 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/tagging/S3DeleteObjectTaggingRequestWithFSO.java
index b25edfe544e..5b62aaa596e 100644
--- 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/tagging/S3DeleteObjectTaggingRequestWithFSO.java
+++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/tagging/S3DeleteObjectTaggingRequestWithFSO.java
@@ -20,6 +20,7 @@
 import static 
org.apache.hadoop.ozone.om.lock.OzoneManagerLock.LeveledResource.BUCKET_LOCK;
 
 import java.io.IOException;
+import java.util.Collections;
 import java.util.Map;
 import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
 import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
@@ -115,10 +116,8 @@ public OMClientResponse 
validateAndUpdateCache(OzoneManager ozoneManager, Execut
       final String dbKey = omMetadataManager.getOzonePathKey(volumeId, 
bucketId,
           omKeyInfo.getParentObjectID(), omKeyInfo.getFileName());
 
-      // Clear / delete the tags
-      omKeyInfo.getTags().clear();
-      // Set the UpdateId to the current transactionLogIndex
       omKeyInfo = omKeyInfo.toBuilder()
+          .setTags(Collections.emptyMap())
           .setUpdateID(trxnLogIndex)
           .build();
 
diff --git 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/tagging/S3PutObjectTaggingRequest.java
 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/tagging/S3PutObjectTaggingRequest.java
index 2bed2a6c1af..cc8064eee01 100644
--- 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/tagging/S3PutObjectTaggingRequest.java
+++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/tagging/S3PutObjectTaggingRequest.java
@@ -127,11 +127,8 @@ public OMClientResponse 
validateAndUpdateCache(OzoneManager ozoneManager, Execut
         throw new OMException("Key not found", KEY_NOT_FOUND);
       }
 
-      // Set the tags
-      omKeyInfo.getTags().clear();
-      
omKeyInfo.getTags().putAll(KeyValueUtil.getFromProtobuf(keyArgs.getTagsList()));
-      // Set the UpdateID to the current transactionLogIndex
       omKeyInfo = omKeyInfo.toBuilder()
+          .setTags(KeyValueUtil.getFromProtobuf(keyArgs.getTagsList()))
           .setUpdateID(trxnLogIndex)
           .build();
 
diff --git 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/tagging/S3PutObjectTaggingRequestWithFSO.java
 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/tagging/S3PutObjectTaggingRequestWithFSO.java
index 442bfc8d7bb..a771bf2b24a 100644
--- 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/tagging/S3PutObjectTaggingRequestWithFSO.java
+++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/tagging/S3PutObjectTaggingRequestWithFSO.java
@@ -116,11 +116,8 @@ public OMClientResponse 
validateAndUpdateCache(OzoneManager ozoneManager, Execut
       final String dbKey = omMetadataManager.getOzonePathKey(volumeId, 
bucketId,
           omKeyInfo.getParentObjectID(), omKeyInfo.getFileName());
 
-      // Set the tags
-      omKeyInfo.getTags().clear();
-      
omKeyInfo.getTags().putAll(KeyValueUtil.getFromProtobuf(keyArgs.getTagsList()));
-      // Set the UpdateId to the current transactionLogIndex
       omKeyInfo = omKeyInfo.toBuilder()
+          .setTags(KeyValueUtil.getFromProtobuf(keyArgs.getTagsList()))
           .setUpdateID(trxnLogIndex)
           .build();
 
diff --git 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/response/s3/tagging/TestS3DeleteObjectTaggingResponse.java
 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/response/s3/tagging/TestS3DeleteObjectTaggingResponse.java
index 03d0c261de8..bfcde032e2d 100644
--- 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/response/s3/tagging/TestS3DeleteObjectTaggingResponse.java
+++ 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/response/s3/tagging/TestS3DeleteObjectTaggingResponse.java
@@ -22,6 +22,7 @@
 import static org.junit.jupiter.api.Assertions.assertNotSame;
 
 import java.io.IOException;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 import org.apache.hadoop.hdds.client.RatisReplicationConfig;
@@ -55,7 +56,9 @@ public void testAddToBatch() throws Exception {
     assertNotNull(omKeyInfo);
     assertEquals(2, omKeyInfo.getTags().size());
 
-    omKeyInfo.getTags().clear();
+    omKeyInfo = omKeyInfo.toBuilder()
+        .setTags(Collections.emptyMap())
+        .build();
 
     S3DeleteObjectTaggingResponse deleteObjectTaggingResponse = 
getDeleteObjectTaggingResponse(omKeyInfo, omResponse);
 
diff --git 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/response/s3/tagging/TestS3PutObjectTaggingResponse.java
 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/response/s3/tagging/TestS3PutObjectTaggingResponse.java
index d2fdbffb3cb..fb901bf25db 100644
--- 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/response/s3/tagging/TestS3PutObjectTaggingResponse.java
+++ 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/response/s3/tagging/TestS3PutObjectTaggingResponse.java
@@ -55,7 +55,9 @@ public void testAddToDBBatch() throws Exception {
     tags.put("tag-key1", "tag-value1");
     tags.put("tag-key2", "tag-value2");
 
-    omKeyInfo.setTags(tags);
+    omKeyInfo = omKeyInfo.toBuilder()
+        .setTags(tags)
+        .build();
 
     S3PutObjectTaggingResponse putObjectTaggingResponse = 
getPutObjectTaggingResponse(omKeyInfo, omResponse);
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to