szetszwo commented on code in PR #8503:
URL: https://github.com/apache/ozone/pull/8503#discussion_r2119677907


##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/SnapshotDiffJob.java:
##########
@@ -316,12 +316,17 @@ public Class<SnapshotDiffJob> getTypeClass() {
 
     @Override
     public byte[] toPersistedFormatImpl(SnapshotDiffJob object) throws 
IOException {

Review Comment:
   The implementation no longer throws any exception.  Change the method to
   ```java
       public byte[] toPersistedFormat(SnapshotDiffJob object) {
   ```



##########
hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/helpers/TestOmSnapshotDiffJobCodec.java:
##########
@@ -0,0 +1,57 @@
+package org.apache.hadoop.ozone.om.helpers;
+
+import org.apache.hadoop.hdds.utils.db.Codec;
+import org.apache.hadoop.ozone.snapshot.SnapshotDiffResponse.JobStatus;
+import org.apache.hadoop.ozone.snapshot.SnapshotDiffResponse.SubStatus;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+
+/**
+ * Testing serialization of SnapshotDiffJobCodec objects to/from RocksDB.
+ */
+public class TestOmSnapshotDiffJobCodec {
+  private final OldSnapshotDiffJobCodecForTesting oldCodec
+      = new OldSnapshotDiffJobCodecForTesting();
+  private final Codec<SnapshotDiffJob> newCodec = SnapshotDiffJob.getCodec();
+
+  @Test
+  public void testOldJsonSerializedDataCanBeReadByNewCodec() throws Exception {
+    // Step 1: Construct a SnapshotDiffJob instance
+    SnapshotDiffJob original = new SnapshotDiffJob(
+        123456789L,
+        "job-001",
+        JobStatus.IN_PROGRESS,
+        "volA",
+        "buckB",
+        "snap1",
+        "snap2",
+        true,
+        false,
+        100L,
+        SubStatus.SST_FILE_DELTA_DAG_WALK,
+        0.0
+    );
+
+    // Step 2: Serialize using the old Jackson-based codec
+    byte[] oldFormatData = oldCodec.toPersistedFormatImpl(original);
+
+    // Step 3: Deserialize using the new default codec (with Protobuf + JSON 
fallback)
+    SnapshotDiffJob parsed = newCodec.fromPersistedFormatImpl(oldFormatData);

Review Comment:
   You are right.  The format is changed.  The byte content won't be the same.



##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/SnapshotDiffJob.java:
##########
@@ -316,12 +316,17 @@ public Class<SnapshotDiffJob> getTypeClass() {
 
     @Override
     public byte[] toPersistedFormatImpl(SnapshotDiffJob object) throws 
IOException {
-      return MAPPER.writeValueAsBytes(object);
+      return object.toProtoBuf().toByteArray();
     }
 
     @Override
     public SnapshotDiffJob fromPersistedFormatImpl(byte[] rawData) throws 
IOException {
-      return MAPPER.readValue(rawData, SnapshotDiffJob.class);
+      try {
+        SnapshotDiffJobProto proto = SnapshotDiffJobProto.parseFrom(rawData);
+        return SnapshotDiffJob.getFromProtoBuf(proto);
+      } catch (IOException e) {

Review Comment:
   Let's catch `InvalidProtocolBufferException` and add a comment:
   ```java
         } catch (InvalidProtocolBufferException e) {
           // the rawData was in old format, fallback to the old implementation
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to