From 3db92b0dc749a758321d3be727fdee016376b758 Mon Sep 17 00:00:00 2001 From: Mostyn Bramley-Moore Date: Mon, 21 Feb 2022 22:13:28 +0100 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 --- CONTRIBUTORS | 1 + .../build/lib/remote/ByteStreamUploader.java | 24 +++++++++++++++++-- 2 files changed, 23 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..eef486732f6cb5 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,34 @@ 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());