asterixdb-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Murtadha Hubail (Code Review)" <do-not-re...@asterixdb.incubator.apache.org>
Subject Change in asterixdb[master]: Replace Java serialization in checkpoints by Json
Date Sun, 22 Jan 2017 16:44:03 GMT
Murtadha Hubail has submitted this change and it was merged.

Change subject: Replace Java serialization in checkpoints by Json
......................................................................


Replace Java serialization in checkpoints by Json

Change-Id: Id4353716267d45ce21580ac2856b6a552d05d1f7
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1457
Reviewed-by: Till Westmann <tillw@apache.org>
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
BAD: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: abdullah alamoudi <bamousaa@gmail.com>
---
M asterixdb/asterix-common/pom.xml
M asterixdb/asterix-common/src/main/java/org/apache/asterix/common/transactions/Checkpoint.java
M asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/recovery/AbstractCheckpointManager.java
M asterixdb/pom.xml
4 files changed, 50 insertions(+), 22 deletions(-)

Approvals:
  abdullah alamoudi: Looks good to me, approved
  Till Westmann: Looks good to me, but someone else must approve
  Jenkins: Verified; No violations found; No violations found; Verified



diff --git a/asterixdb/asterix-common/pom.xml b/asterixdb/asterix-common/pom.xml
index cb5075a..7df1da6 100644
--- a/asterixdb/asterix-common/pom.xml
+++ b/asterixdb/asterix-common/pom.xml
@@ -311,6 +311,10 @@
       <groupId>org.apache.hyracks</groupId>
       <artifactId>hyracks-data-std</artifactId>
     </dependency>
+    <dependency>
+      <groupId>com.fasterxml.jackson.core</groupId>
+      <artifactId>jackson-annotations</artifactId>
+    </dependency>
   </dependencies>
 
 </project>
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/transactions/Checkpoint.java
b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/transactions/Checkpoint.java
index 8bbdab7..a74898e 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/transactions/Checkpoint.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/transactions/Checkpoint.java
@@ -18,11 +18,16 @@
  */
 package org.apache.asterix.common.transactions;
 
-import java.io.Serializable;
+import java.io.IOException;
 
-public class Checkpoint implements Serializable, Comparable<Checkpoint> {
+import org.apache.hyracks.api.exceptions.HyracksDataException;
 
-    private static final long serialVersionUID = 1L;
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class Checkpoint implements Comparable<Checkpoint> {
 
     private final long checkpointLsn;
     private final long minMCTFirstLsn;
@@ -31,8 +36,11 @@
     private final boolean sharp;
     private final int storageVersion;
 
-    public Checkpoint(long checkpointLsn, long minMCTFirstLsn, int maxJobId, long timeStamp,
boolean sharp,
-            int storageVersion) {
+    @JsonCreator
+    public Checkpoint(@JsonProperty("checkpointLsn") long checkpointLsn,
+            @JsonProperty("minMCTFirstLsn") long minMCTFirstLsn, @JsonProperty("maxJobId")
int maxJobId,
+            @JsonProperty("timeStamp") long timeStamp, @JsonProperty("sharp") boolean sharp,
+            @JsonProperty("storageVersion") int storageVersion) {
         this.checkpointLsn = checkpointLsn;
         this.minMCTFirstLsn = minMCTFirstLsn;
         this.maxJobId = maxJobId;
@@ -107,4 +115,20 @@
         result = prime * result + (int) (timeStamp ^ (timeStamp >>> 32));
         return result;
     }
-}
+
+    public String asJson() throws HyracksDataException {
+        try {
+            return new ObjectMapper().writeValueAsString(this);
+        } catch (JsonProcessingException e) {
+            throw new HyracksDataException(e);
+        }
+    }
+
+    public static Checkpoint fromJson(String json) throws HyracksDataException {
+        try {
+            return new ObjectMapper().readValue(json, Checkpoint.class);
+        } catch (IOException e) {
+            throw new HyracksDataException(e);
+        }
+    }
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/recovery/AbstractCheckpointManager.java
b/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/recovery/AbstractCheckpointManager.java
index 0b86ea5..d2650e9 100644
--- a/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/recovery/AbstractCheckpointManager.java
+++ b/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/recovery/AbstractCheckpointManager.java
@@ -18,14 +18,14 @@
  */
 package org.apache.asterix.transaction.management.service.recovery;
 
+import java.io.BufferedWriter;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.FilenameFilter;
 import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
 import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -84,15 +84,12 @@
         if (checkpoints == null || checkpoints.length == 0) {
             return null;
         }
-
-        Checkpoint checkpointObject;
         List<Checkpoint> checkpointObjectList = new ArrayList<>();
         for (File file : checkpoints) {
-            try (FileInputStream fis = new FileInputStream(file);
-                    ObjectInputStream oisFromFis = new ObjectInputStream(fis)) {
-                checkpointObject = (Checkpoint) oisFromFis.readObject();
-                checkpointObjectList.add(checkpointObject);
-            } catch (IOException | ClassNotFoundException e) {
+            try {
+                String jsonString = new String(Files.readAllBytes(Paths.get(file.getAbsolutePath())));
+                checkpointObjectList.add(Checkpoint.fromJson(jsonString));
+            } catch (IOException e) {
                 throw new ACIDException("Failed to read a checkpoint file", e);
             }
         }
@@ -139,12 +136,10 @@
         // Construct checkpoint file name
         String fileName = checkpointDir.getAbsolutePath() + File.separator + CHECKPOINT_FILENAME_PREFIX
                 + Long.toString(checkpoint.getTimeStamp());
-        //TODO: replace java serialization
         // Write checkpoint file to disk
-        try (FileOutputStream fos = new FileOutputStream(fileName);
-                ObjectOutputStream oosToFos = new ObjectOutputStream(fos)) {
-            oosToFos.writeObject(checkpoint);
-            oosToFos.flush();
+        Path path = Paths.get(fileName);
+        try (BufferedWriter writer = Files.newBufferedWriter(path)) {
+            writer.write(checkpoint.asJson());
         } catch (IOException e) {
             throw new HyracksDataException("Failed to write checkpoint to disk", e);
         }
diff --git a/asterixdb/pom.xml b/asterixdb/pom.xml
index dfc4f7b..51f8789 100644
--- a/asterixdb/pom.xml
+++ b/asterixdb/pom.xml
@@ -1011,6 +1011,11 @@
         <version>2.8.4</version>
       </dependency>
       <dependency>
+        <groupId>com.fasterxml.jackson.core</groupId>
+        <artifactId>jackson-annotations</artifactId>
+        <version>2.8.4</version>
+      </dependency>
+      <dependency>
         <groupId>com.google.guava</groupId>
         <artifactId>guava</artifactId>
         <version>18.0</version>

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/1457
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Id4353716267d45ce21580ac2856b6a552d05d1f7
Gerrit-PatchSet: 4
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Murtadha Hubail <hubailmor@gmail.com>
Gerrit-Reviewer: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Gerrit-Reviewer: Murtadha Hubail <hubailmor@gmail.com>
Gerrit-Reviewer: Till Westmann <tillw@apache.org>
Gerrit-Reviewer: abdullah alamoudi <bamousaa@gmail.com>

Mime
View raw message