This is an automated email from the ASF dual-hosted git repository.
szetszwo 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 07a3351328 HDDS-8657. Remove Clone and make use of copyObject in
OmDirectoryInfo and OmKeyInfo. (#4745)
07a3351328 is described below
commit 07a3351328cbed6b3a40282f62db53b4b177181c
Author: ashishkumar50 <[email protected]>
AuthorDate: Sat May 20 05:58:38 2023 +0530
HDDS-8657. Remove Clone and make use of copyObject in OmDirectoryInfo and
OmKeyInfo. (#4745)
---
.../hadoop/ozone/om/helpers/ICopyObject.java | 22 ++++++++++++++
.../hadoop/ozone/om/helpers/OmDirectoryInfo.java | 27 ++---------------
.../apache/hadoop/ozone/om/helpers/OmKeyInfo.java | 34 ++--------------------
.../hadoop/ozone/om/OzoneListStatusHelper.java | 7 ++---
4 files changed, 31 insertions(+), 59 deletions(-)
diff --git
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/ICopyObject.java
b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/ICopyObject.java
new file mode 100644
index 0000000000..8f9fae9659
--- /dev/null
+++
b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/ICopyObject.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+package org.apache.hadoop.ozone.om.helpers;
+
+/**
+ * CopyObject Info interface.
+ */
+public interface ICopyObject {
+ <T> T copyObject();
+}
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 5cc5160273..9460e777c8 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
@@ -24,7 +24,6 @@ import
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
import java.util.BitSet;
import java.util.HashMap;
import java.util.LinkedList;
-import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -34,7 +33,8 @@ import java.util.Objects;
* in the user given path and a pointer to its parent directory element in the
* path. Also, it stores directory node related metdata details.
*/
-public class OmDirectoryInfo extends WithParentObjectId implements Cloneable {
+public class OmDirectoryInfo extends WithParentObjectId
+ implements ICopyObject {
private String name; // directory name
private long creationTime;
@@ -248,6 +248,7 @@ public class OmDirectoryInfo extends WithParentObjectId
implements Cloneable {
/**
* Return a new copy of the object.
*/
+ @Override
public OmDirectoryInfo copyObject() {
OmDirectoryInfo.Builder builder = new Builder()
.setName(name)
@@ -267,26 +268,4 @@ public class OmDirectoryInfo extends WithParentObjectId
implements Cloneable {
return builder.build();
}
-
- /**
- * Return a new copy of the object.
- */
- @Override
- public Object clone() throws CloneNotSupportedException {
- OmDirectoryInfo omDirectoryInfo = (OmDirectoryInfo) super.clone();
-
- omDirectoryInfo.metadata = new HashMap<>();
- omDirectoryInfo.acls = new ArrayList<>();
-
- acls.stream().filter(acl -> acl != null).forEach(acl ->
- omDirectoryInfo.acls.add(new OzoneAcl(acl.getType(),
- acl.getName(), (BitSet) acl.getAclBitSet().clone(),
- acl.getAclScope())));
-
- if (metadata != null) {
- metadata.forEach((k, v) -> omDirectoryInfo.metadata.put(k, v));
- }
-
- return omDirectoryInfo;
- }
}
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 077a081195..62a87c774d 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
@@ -48,7 +48,8 @@ import org.slf4j.LoggerFactory;
* This is returned from OM to client, and client use class to talk to
* datanode. Also, this is the metadata written to om.db on server side.
*/
-public final class OmKeyInfo extends WithParentObjectId implements Cloneable {
+public final class OmKeyInfo extends WithParentObjectId
+ implements ICopyObject {
private static final Logger LOG = LoggerFactory.getLogger(OmKeyInfo.class);
private final String volumeName;
private final String bucketName;
@@ -752,6 +753,7 @@ public final class OmKeyInfo extends WithParentObjectId
implements Cloneable {
/**
* Return a new copy of the object.
*/
+ @Override
public OmKeyInfo copyObject() {
OmKeyInfo.Builder builder = new OmKeyInfo.Builder()
.setVolumeName(volumeName)
@@ -789,36 +791,6 @@ public final class OmKeyInfo extends WithParentObjectId
implements Cloneable {
return builder.build();
}
- /**
- * Return a new copy of the object.
- */
- @Override
- public Object clone() throws CloneNotSupportedException {
- OmKeyInfo omKeyInfo = (OmKeyInfo) super.clone();
-
- omKeyInfo.metadata = new HashMap<>();
- omKeyInfo.keyLocationVersions = new ArrayList<>();
- omKeyInfo.acls = new ArrayList<>();
-
- keyLocationVersions.stream().filter(keyLocationVersion ->
- keyLocationVersion != null).forEach(keyLocationVersion ->
- omKeyInfo.keyLocationVersions.add(
- new OmKeyLocationInfoGroup(keyLocationVersion.getVersion(),
- keyLocationVersion.getLocationList(),
- keyLocationVersion.isMultipartKey())));
-
- acls.stream().filter(acl -> acl != null).forEach(acl ->
- omKeyInfo.acls.add(new OzoneAcl(acl.getType(),
- acl.getName(), (BitSet) acl.getAclBitSet().clone(),
- acl.getAclScope())));
-
- if (metadata != null) {
- metadata.forEach((k, v) -> omKeyInfo.metadata.put(k, v));
- }
-
- return omKeyInfo;
- }
-
/**
* Method to clear the fileEncryptionInfo.
* This method is called when a KeyDelete operation is performed.
diff --git
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneListStatusHelper.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneListStatusHelper.java
index 06cda4667b..f8eb2cd279 100644
---
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneListStatusHelper.java
+++
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneListStatusHelper.java
@@ -18,7 +18,6 @@ package org.apache.hadoop.ozone.om;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
-import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.hdds.utils.db.Table;
import org.apache.hadoop.hdds.utils.db.TableIterator;
@@ -32,6 +31,7 @@ import org.apache.hadoop.ozone.om.helpers.OmKeyArgs;
import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+import org.apache.hadoop.ozone.om.helpers.ICopyObject;
import org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo;
import org.apache.hadoop.ozone.om.helpers.WithParentObjectId;
import org.apache.hadoop.ozone.om.request.file.OMFileRequest;
@@ -442,9 +442,8 @@ public class OzoneListStatusHelper {
}
// Copy cache value to local copy and work on it
- Value copyOmInfo = ObjectUtils.clone(cacheOmInfo);
- if (copyOmInfo != null) {
- cacheOmInfo = copyOmInfo;
+ if (cacheOmInfo instanceof ICopyObject) {
+ cacheOmInfo = ((ICopyObject) cacheOmInfo).copyObject();
}
if (StringUtils.isBlank(startKey)) {
// startKey is null or empty, then the seekKeyInDB="1024/"
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]