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 5290112d041 HDDS-14172. Reduce copying in 
OMFileRequest.getDirectoryInfo (#9541)
5290112d041 is described below

commit 5290112d041dcaa416b90f371109bf22e052697a
Author: Eric C. Ho <[email protected]>
AuthorDate: Tue Dec 23 15:58:10 2025 +0800

    HDDS-14172. Reduce copying in OMFileRequest.getDirectoryInfo (#9541)
---
 .../org/apache/hadoop/ozone/om/helpers/AclListBuilder.java | 13 +++++++++++++
 .../apache/hadoop/ozone/om/helpers/OmDirectoryInfo.java    | 14 +++++++++++++-
 .../java/org/apache/hadoop/ozone/om/helpers/OmKeyInfo.java |  4 ++++
 .../apache/hadoop/ozone/om/request/file/OMFileRequest.java | 11 +----------
 4 files changed, 31 insertions(+), 11 deletions(-)

diff --git 
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/AclListBuilder.java
 
b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/AclListBuilder.java
index ae2ff885762..5e097ff1663 100644
--- 
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/AclListBuilder.java
+++ 
b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/AclListBuilder.java
@@ -43,6 +43,19 @@ public static AclListBuilder of(ImmutableList<OzoneAcl> 
list) {
     return new AclListBuilder(list);
   }
 
+  /**
+   * Overload accepting List instead of ImmutableList for binary compatibility
+   * across different Guava versions (especially for Hadoop 2.x compatibility).
+   * This method can be removed when Hadoop 2.x support is dropped and all
+   * callers are guaranteed to use the same Guava version.
+   */
+  public static AclListBuilder of(List<OzoneAcl> list) {
+    if (list instanceof ImmutableList) {
+      return new AclListBuilder((ImmutableList<OzoneAcl>) list);
+    }
+    return copyOf(list);
+  }
+
   public static AclListBuilder copyOf(List<OzoneAcl> list) {
     return new AclListBuilder(list == null ? ImmutableList.of() : 
ImmutableList.copyOf(list));
   }
diff --git 
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmDirectoryInfo.java
 
b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmDirectoryInfo.java
index 816f34d7167..13a09fd0d94 100644
--- 
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmDirectoryInfo.java
+++ 
b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmDirectoryInfo.java
@@ -75,6 +75,10 @@ public Builder toBuilder() {
     return new Builder(this);
   }
 
+  public static Builder builderFromOmKeyInfo(OmKeyInfo keyInfo) {
+    return new Builder(keyInfo);
+  }
+
   /**
    * Builder for Directory Info.
    */
@@ -100,6 +104,14 @@ private Builder(OmDirectoryInfo obj) {
       this.acls = AclListBuilder.of(obj.acls);
     }
 
+    private Builder(OmKeyInfo keyInfo) {
+      super(keyInfo);
+      this.name = keyInfo.getFileName();
+      this.creationTime = keyInfo.getCreationTime();
+      this.modificationTime = keyInfo.getModificationTime();
+      this.acls = AclListBuilder.of(keyInfo.getAcls());
+    }
+
     @Override
     public Builder setParentObjectID(long parentObjectId) {
       super.setParentObjectID(parentObjectId);
@@ -180,7 +192,7 @@ public long getModificationTime() {
     return modificationTime;
   }
 
-  public List<OzoneAcl> getAcls() {
+  public ImmutableList<OzoneAcl> getAcls() {
     return acls;
   }
 
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 76e0cac3f46..e0e900ccf2d 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
@@ -930,6 +930,10 @@ public Builder toBuilder() {
     return new Builder(this);
   }
 
+  public OmDirectoryInfo.Builder toDirectoryInfoBuilder() {
+    return OmDirectoryInfo.builderFromOmKeyInfo(this);
+  }
+
   /**
    * Return a new copy of the object.
    */
diff --git 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/file/OMFileRequest.java
 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/file/OMFileRequest.java
index a02c16188ef..6a23ab21537 100644
--- 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/file/OMFileRequest.java
+++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/file/OMFileRequest.java
@@ -786,16 +786,7 @@ public static String getAbsolutePath(String prefixName, 
String fileName) {
    * @return omDirectoryInfo object
    */
   public static OmDirectoryInfo getDirectoryInfo(OmKeyInfo keyInfo) {
-    return OmDirectoryInfo.newBuilder()
-        .setParentObjectID(keyInfo.getParentObjectID())
-        .setAcls(keyInfo.getAcls())
-        .addAllMetadata(keyInfo.getMetadata())
-        .setCreationTime(keyInfo.getCreationTime())
-        .setModificationTime(keyInfo.getModificationTime())
-        .setObjectID(keyInfo.getObjectID())
-        .setUpdateID(keyInfo.getUpdateID())
-        .setName(OzoneFSUtils.getFileName(keyInfo.getKeyName()))
-        .build();
+    return keyInfo.toDirectoryInfoBuilder().build();
   }
 
   /**


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

Reply via email to