You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aurora.apache.org by wf...@apache.org on 2017/10/10 22:21:29 UTC

aurora git commit: Stream backup file from disk

Repository: aurora
Updated Branches:
  refs/heads/master 4a1fba3c8 -> cb8e956f1


Stream backup file from disk

This reduces the memory burden of loading a backup for recovery.
Previously, the backup file would be fully loaded into a `byte[]`, which
may be very large and fail to allocate.

Reviewed at https://reviews.apache.org/r/62873/


Project: http://git-wip-us.apache.org/repos/asf/aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/aurora/commit/cb8e956f
Tree: http://git-wip-us.apache.org/repos/asf/aurora/tree/cb8e956f
Diff: http://git-wip-us.apache.org/repos/asf/aurora/diff/cb8e956f

Branch: refs/heads/master
Commit: cb8e956f18a8743e5b348683824272fbf9e55c11
Parents: 4a1fba3
Author: Bill Farner <wf...@apache.org>
Authored: Tue Oct 10 15:21:08 2017 -0700
Committer: Bill Farner <wf...@apache.org>
Committed: Tue Oct 10 15:21:08 2017 -0700

----------------------------------------------------------------------
 .../aurora/scheduler/storage/backup/Recovery.java   | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aurora/blob/cb8e956f/src/main/java/org/apache/aurora/scheduler/storage/backup/Recovery.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/backup/Recovery.java b/src/main/java/org/apache/aurora/scheduler/storage/backup/Recovery.java
index b74de9b..6cd5b2b 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/backup/Recovery.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/backup/Recovery.java
@@ -13,7 +13,9 @@
  */
 package org.apache.aurora.scheduler.storage.backup;
 
+import java.io.BufferedInputStream;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicReference;
@@ -23,10 +25,8 @@ import javax.inject.Inject;
 
 import com.google.common.base.Function;
 import com.google.common.collect.ImmutableSet;
-import com.google.common.io.Files;
 import com.google.common.util.concurrent.Atomics;
 
-import org.apache.aurora.codec.ThriftBinaryCodec;
 import org.apache.aurora.codec.ThriftBinaryCodec.CodingException;
 import org.apache.aurora.common.base.Command;
 import org.apache.aurora.gen.storage.Snapshot;
@@ -35,6 +35,9 @@ import org.apache.aurora.scheduler.storage.DistributedSnapshotStore;
 import org.apache.aurora.scheduler.storage.Storage;
 import org.apache.aurora.scheduler.storage.Storage.MutateWork.NoResult;
 import org.apache.aurora.scheduler.storage.entities.IScheduledTask;
+import org.apache.thrift.TException;
+import org.apache.thrift.protocol.TBinaryProtocol;
+import org.apache.thrift.transport.TIOStreamTransport;
 
 import static java.util.Objects.requireNonNull;
 
@@ -138,10 +141,13 @@ public interface Recovery {
         throw new RecoveryException("Backup " + backupName + " does not exist.");
       }
 
-      Snapshot snapshot;
+      Snapshot snapshot = new Snapshot();
       try {
-        snapshot = ThriftBinaryCodec.decode(Snapshot.class, Files.toByteArray(backupFile));
-      } catch (CodingException e) {
+        TBinaryProtocol prot = new TBinaryProtocol(
+            new TIOStreamTransport(new BufferedInputStream(new FileInputStream(backupFile))));
+
+        snapshot.read(prot);
+      } catch (TException e) {
         throw new RecoveryException("Failed to decode backup " + e, e);
       } catch (IOException e) {
         throw new RecoveryException("Failed to read backup " + e, e);