Skip to content

Commit

Permalink
Enable bulk writes in the HttpBlobStore
Browse files Browse the repository at this point in the history
Second attempt of bazelbuild@0654620, which I am rolling back. The problem is that FilterOutputStream.write is just plain wrong and we shouldn't inherit FilterOutputStream at all, but instead do it manually (which actually requires less code).

This was a performance regression in bazelbuild@deccc48.

Fixed bazelbuild#4944.

PiperOrigin-RevId: 191215696
  • Loading branch information
ulfjack authored and Copybara-Service committed Apr 1, 2018
1 parent df7731f commit f54d7e5
Showing 1 changed file with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.FilterInputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand Down Expand Up @@ -199,23 +198,31 @@ public boolean get(String key, OutputStream out) throws IOException, Interrupted
}

@SuppressWarnings("FutureReturnValueIgnored")
private boolean get(String key, OutputStream out, boolean casDownload)
private boolean get(String key, final OutputStream out, boolean casDownload)
throws IOException, InterruptedException {
final AtomicBoolean dataWritten = new AtomicBoolean();

OutputStream wrappedOut =
new FilterOutputStream(out) {
new OutputStream() {
// OutputStream.close() does nothing, which is what we want to ensure that the
// OutputStream can't be closed somewhere in the Netty pipeline, so that we can support
// retries. The OutputStream is closed in the finally block below.

@Override
public void write(byte[] b, int offset, int length) throws IOException {
dataWritten.set(true);
out.write(b, offset, length);
}

@Override
public void write(int b) throws IOException {
dataWritten.set(true);
super.write(b);
out.write(b);
}

@Override
public void close() {
// Ensure that the OutputStream can't be closed somewhere in the Netty
// pipeline, so that we can support retries. The OutputStream is closed in
// the finally block below.
public void flush() throws IOException {
out.flush();
}
};
DownloadCommand download = new DownloadCommand(uri, casDownload, key, wrappedOut);
Expand Down

0 comments on commit f54d7e5

Please sign in to comment.