You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "Tsz-wo Sze (Jira)" <ji...@apache.org> on 2023/05/21 09:28:00 UTC

[jira] [Updated] (HDDS-8665) OmDBSnapshotInfoCodec.copyObject(..) does not follow the general contract of copy.

     [ https://issues.apache.org/jira/browse/HDDS-8665?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tsz-wo Sze updated HDDS-8665:
-----------------------------
    Description: 
OmDBSnapshotInfoCodec.copyObject(..) is a shallow copy -- it simply returns the same object.  However, if it is changed to return a deep copy as below, TestOMSnapshotDeleteRequest and TestOMSnapshotPurgeRequestAndResponse will fail.  These two tests depend on the behavior that, after copying, changing one of the object will also change the other object.
{code}
+++ b/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/codec/OmDBSnapshotInfoCodec.java
@@ -52,7 +52,13 @@ public SnapshotInfo fromPersistedFormat(byte[] rawData)
 
   @Override
   public SnapshotInfo copyObject(SnapshotInfo object) {
-    // Note: Not really a "copy". from OMDBSnapshotInfoCodec
-    return object;
+    // FIXME: Deep copy will cause failures
+    //        - TestOMSnapshotDeleteRequest NullPointerException
+    //        - TestOMSnapshotPurgeRequestAndResponse AssertionFailedError
+    try {
+      return fromPersistedFormat(toPersistedFormat(object));
+    } catch (IOException e) {
+      throw new IllegalStateException(e);
+    }
   }
 }{code}


  was:
In OmDBSnapshotInfoCodec.copyObject(..), it currently simply returns the same object.  However, if it is changed to return a real copy as below, TestOMSnapshotDeleteRequest and TestOMSnapshotPurgeRequestAndResponse will fail.
{code}
+++ b/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/codec/OmDBSnapshotInfoCodec.java
@@ -53,6 +53,14 @@ public SnapshotInfo fromPersistedFormat(byte[] rawData)
   @Override
   public SnapshotInfo copyObject(SnapshotInfo object) {
     // Note: Not really a "copy". from OMDBSnapshotInfoCodec
-    return object;
+
+    // TODO: Copy will cause failures
+    //       - TestOMSnapshotDeleteRequest NullPointerException
+    //       - TestOMSnapshotPurgeRequestAndResponse AssertionFailedError
+    try {
+      return fromPersistedFormat(toPersistedFormat(object));
+    } catch (IOException e) {
+      throw new IllegalStateException(e);
+    }
   }
 }
{code}



> OmDBSnapshotInfoCodec.copyObject(..) does not follow the general contract of copy.
> ----------------------------------------------------------------------------------
>
>                 Key: HDDS-8665
>                 URL: https://issues.apache.org/jira/browse/HDDS-8665
>             Project: Apache Ozone
>          Issue Type: Bug
>          Components: OM, Snapshot
>            Reporter: Tsz-wo Sze
>            Priority: Major
>
> OmDBSnapshotInfoCodec.copyObject(..) is a shallow copy -- it simply returns the same object.  However, if it is changed to return a deep copy as below, TestOMSnapshotDeleteRequest and TestOMSnapshotPurgeRequestAndResponse will fail.  These two tests depend on the behavior that, after copying, changing one of the object will also change the other object.
> {code}
> +++ b/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/codec/OmDBSnapshotInfoCodec.java
> @@ -52,7 +52,13 @@ public SnapshotInfo fromPersistedFormat(byte[] rawData)
>  
>    @Override
>    public SnapshotInfo copyObject(SnapshotInfo object) {
> -    // Note: Not really a "copy". from OMDBSnapshotInfoCodec
> -    return object;
> +    // FIXME: Deep copy will cause failures
> +    //        - TestOMSnapshotDeleteRequest NullPointerException
> +    //        - TestOMSnapshotPurgeRequestAndResponse AssertionFailedError
> +    try {
> +      return fromPersistedFormat(toPersistedFormat(object));
> +    } catch (IOException e) {
> +      throw new IllegalStateException(e);
> +    }
>    }
>  }{code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org