From 18e2d0c35956482ca8d9fadc64c220af743e5ffb Mon Sep 17 00:00:00 2001 From: George Gensure Date: Wed, 20 Nov 2019 19:33:09 -0500 Subject: [PATCH] Only request grpc write when not complete If a queryWriteStatus yields a committedSize which leaves no content remaining to be uploaded, immediately succeed a blob upload. This can easily occur if a competing blob write completes asynchronously between abnormal write termination and a query. --- .../devtools/build/lib/remote/ByteStreamUploader.java | 8 +++++++- .../com/google/devtools/build/lib/remote/Chunker.java | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) 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 91f9f509f600ed..e70d5c835a7185 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 @@ -353,7 +353,13 @@ ListenableFuture start() { AtomicLong committedOffset = new AtomicLong(0); return Futures.transformAsync( retrier.executeAsync( - () -> ctx.call(() -> callAndQueryOnFailure(committedOffset, progressiveBackoff)), + () -> { + if (committedOffset.get() < chunker.getSize()) { + return ctx.call(() -> callAndQueryOnFailure(committedOffset, progressiveBackoff)); + } else { + return Futures.immediateFuture(null); + } + } progressiveBackoff), (result) -> { long committedSize = committedOffset.get(); diff --git a/src/main/java/com/google/devtools/build/lib/remote/Chunker.java b/src/main/java/com/google/devtools/build/lib/remote/Chunker.java index cda7a3aa7819e6..8904e59e20bd37 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/Chunker.java +++ b/src/main/java/com/google/devtools/build/lib/remote/Chunker.java @@ -218,7 +218,7 @@ public Chunk next() throws IOException { return new Chunk(blob, offsetBefore); } - private long bytesLeft() { + public long bytesLeft() { return getSize() - getOffset(); }