Skip to content

Commit 5290112

Browse files
authored
HDDS-14172. Reduce copying in OMFileRequest.getDirectoryInfo (#9541)
1 parent ef980cd commit 5290112

4 files changed

Lines changed: 31 additions & 11 deletions

File tree

hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/AclListBuilder.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ public static AclListBuilder of(ImmutableList<OzoneAcl> list) {
4343
return new AclListBuilder(list);
4444
}
4545

46+
/**
47+
* Overload accepting List instead of ImmutableList for binary compatibility
48+
* across different Guava versions (especially for Hadoop 2.x compatibility).
49+
* This method can be removed when Hadoop 2.x support is dropped and all
50+
* callers are guaranteed to use the same Guava version.
51+
*/
52+
public static AclListBuilder of(List<OzoneAcl> list) {
53+
if (list instanceof ImmutableList) {
54+
return new AclListBuilder((ImmutableList<OzoneAcl>) list);
55+
}
56+
return copyOf(list);
57+
}
58+
4659
public static AclListBuilder copyOf(List<OzoneAcl> list) {
4760
return new AclListBuilder(list == null ? ImmutableList.of() : ImmutableList.copyOf(list));
4861
}

hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmDirectoryInfo.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ public Builder toBuilder() {
7575
return new Builder(this);
7676
}
7777

78+
public static Builder builderFromOmKeyInfo(OmKeyInfo keyInfo) {
79+
return new Builder(keyInfo);
80+
}
81+
7882
/**
7983
* Builder for Directory Info.
8084
*/
@@ -100,6 +104,14 @@ private Builder(OmDirectoryInfo obj) {
100104
this.acls = AclListBuilder.of(obj.acls);
101105
}
102106

107+
private Builder(OmKeyInfo keyInfo) {
108+
super(keyInfo);
109+
this.name = keyInfo.getFileName();
110+
this.creationTime = keyInfo.getCreationTime();
111+
this.modificationTime = keyInfo.getModificationTime();
112+
this.acls = AclListBuilder.of(keyInfo.getAcls());
113+
}
114+
103115
@Override
104116
public Builder setParentObjectID(long parentObjectId) {
105117
super.setParentObjectID(parentObjectId);
@@ -180,7 +192,7 @@ public long getModificationTime() {
180192
return modificationTime;
181193
}
182194

183-
public List<OzoneAcl> getAcls() {
195+
public ImmutableList<OzoneAcl> getAcls() {
184196
return acls;
185197
}
186198

hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmKeyInfo.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,10 @@ public Builder toBuilder() {
930930
return new Builder(this);
931931
}
932932

933+
public OmDirectoryInfo.Builder toDirectoryInfoBuilder() {
934+
return OmDirectoryInfo.builderFromOmKeyInfo(this);
935+
}
936+
933937
/**
934938
* Return a new copy of the object.
935939
*/

hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/file/OMFileRequest.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -786,16 +786,7 @@ public static String getAbsolutePath(String prefixName, String fileName) {
786786
* @return omDirectoryInfo object
787787
*/
788788
public static OmDirectoryInfo getDirectoryInfo(OmKeyInfo keyInfo) {
789-
return OmDirectoryInfo.newBuilder()
790-
.setParentObjectID(keyInfo.getParentObjectID())
791-
.setAcls(keyInfo.getAcls())
792-
.addAllMetadata(keyInfo.getMetadata())
793-
.setCreationTime(keyInfo.getCreationTime())
794-
.setModificationTime(keyInfo.getModificationTime())
795-
.setObjectID(keyInfo.getObjectID())
796-
.setUpdateID(keyInfo.getUpdateID())
797-
.setName(OzoneFSUtils.getFileName(keyInfo.getKeyName()))
798-
.build();
789+
return keyInfo.toDirectoryInfoBuilder().build();
799790
}
800791

801792
/**

0 commit comments

Comments
 (0)