From d184e4883bb7fc21de2f7aeea4304994de27e9ea Mon Sep 17 00:00:00 2001 From: Mostyn Bramley-Moore Date: Tue, 22 Feb 2022 02:51:48 -0800 Subject: [PATCH] Remote: handle early return of compressed blobs uploads This is an implementation of this REAPI spec update: https://github.com/bazelbuild/remote-apis/pull/213 Here's a bazel-remote build that can be used to test this change: https://github.com/buchgr/bazel-remote/pull/527 Fixes #14654 Closes #14870. PiperOrigin-RevId: 430167812 --- CONTRIBUTORS | 1 + .../build/lib/remote/ByteStreamUploader.java | 23 +++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index a95cecd8def926..6936c814fe7bd0 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -20,6 +20,7 @@ Shreya Bhattarai Kevin Bierhoff Klaas Boesche Phil Bordelon +Mostyn Bramley-Moore Jon Brandvein Volker Braun Thomas Broyer diff --git a/src/main/java/com/google/devtools/build/lib/remote/ByteStreamUploader.java b/src/main/java/com/google/devtools/build/lib/remote/ByteStreamUploader.java index a6a7c782bf16bb..e5b817a6ba8603 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/ByteStreamUploader.java +++ b/src/main/java/com/google/devtools/build/lib/remote/ByteStreamUploader.java @@ -323,14 +323,33 @@ ListenableFuture start() { // level/algorithm, so we cannot know the expected committed offset long committedSize = committedOffset.get(); long expected = chunker.getOffset(); - if (!chunker.hasNext() && committedSize != expected) { + + if (committedSize == expected) { + // Both compressed and uncompressed uploads can succeed + // with this result. + return immediateVoidFuture(); + } + + if (chunker.isCompressed()) { + if (committedSize == -1) { + // Returned early, blob already available. + return immediateVoidFuture(); + } + String message = format( - "write incomplete: committed_size %d for %d total", + "compressed write incomplete: committed_size %d is neither -1 nor total %d", committedSize, expected); return Futures.immediateFailedFuture(new IOException(message)); } + + // Uncompressed upload failed. + String message = + format( + "write incomplete: committed_size %d for %d total", committedSize, expected); + return Futures.immediateFailedFuture(new IOException(message)); } + return immediateVoidFuture(); }, MoreExecutors.directExecutor());