diff options
author | ulfjack <ulfjack@google.com> | 2018-04-01 01:36:57 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-04-01 01:38:03 -0700 |
commit | f54d7e5293cc40ce3507a9adef530e46ab817585 (patch) | |
tree | 2cf3f0662bdf3523f1f01b4908ea0d47100eab5c | |
parent | df7731f13e58e719d0b0a703a0b53f2bc1e2d795 (diff) |
Enable bulk writes in the HttpBlobStore
Second attempt of https://github.com/bazelbuild/bazel/commit/0654620304728a5aecadd58138e96c41135d24e7, 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 https://github.com/bazelbuild/bazel/commit/deccc485603c004daad959fd747f1c0c9efc4f00.
Fixed #4944.
PiperOrigin-RevId: 191215696
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/remote/blobstore/http/HttpBlobStore.java | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/remote/blobstore/http/HttpBlobStore.java b/src/main/java/com/google/devtools/build/lib/remote/blobstore/http/HttpBlobStore.java index 012931bade..857dfe4f1d 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/blobstore/http/HttpBlobStore.java +++ b/src/main/java/com/google/devtools/build/lib/remote/blobstore/http/HttpBlobStore.java @@ -43,7 +43,6 @@ import io.netty.util.internal.PlatformDependent; 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; @@ -199,23 +198,31 @@ public final class HttpBlobStore implements SimpleBlobStore { } @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); |