From ee37af3c2cabd5e5996000846e4b04a707be28f6 Mon Sep 17 00:00:00 2001 From: Nitesh Jain <89.nitesh@gmail.com> Date: Wed, 13 Sep 2017 06:04:56 +0000 Subject: [PATCH] hold back flush till stream close (#51) --- .../backup/azure/PageBlobOutputStream.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cassandra-executor/src/main/java/com/mesosphere/dcos/cassandra/executor/backup/azure/PageBlobOutputStream.java b/cassandra-executor/src/main/java/com/mesosphere/dcos/cassandra/executor/backup/azure/PageBlobOutputStream.java index 3679cdaa..5acb9db7 100644 --- a/cassandra-executor/src/main/java/com/mesosphere/dcos/cassandra/executor/backup/azure/PageBlobOutputStream.java +++ b/cassandra-executor/src/main/java/com/mesosphere/dcos/cassandra/executor/backup/azure/PageBlobOutputStream.java @@ -30,6 +30,7 @@ public class PageBlobOutputStream extends FilterOutputStream { private long currentPageSize = PAGE_BLOB_PAGE_SIZE; private volatile IOException lastError; + private boolean closed = false; /** * Creates an output stream filter built on top of the Azure @@ -63,10 +64,17 @@ public void write(int b) throws IOException { internalWrite(b); } + @Override + public void flush() throws IOException { + // cannot flush untill close + } + @Override public void close() throws IOException { this.checkStreamState(); + if(closed) + return; // top off page size // flush write does NOT occur unless full page is written @@ -74,11 +82,16 @@ public void close() throws IOException { byte[] pad = new byte[(int) (currentPageSize - count)]; writePad(pad); } - super.close(); - + try { + super.flush(); + super.close(); + } finally { + closed = true; + } uploadMetadata(); } + private void writePad(byte[] pad) throws IOException { out.write(pad); }