Skip to content

Commit

Permalink
byte count
Browse files Browse the repository at this point in the history
  • Loading branch information
aherrmann committed Oct 15, 2021
1 parent c88fc2c commit 8d976d3
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions nix/bazel-retry-cache.patch
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ index 9ce71c7c52..5c7f2d0728 100644
"//src/main/java/com/google/devtools/build/lib/vfs",
"//third_party:auth",
diff --git a/src/main/java/com/google/devtools/build/lib/remote/http/HttpCacheClient.java b/src/main/java/com/google/devtools/build/lib/remote/http/HttpCacheClient.java
index 1efecd3bb1..98a2866200 100644
index 1efecd3bb1..dcfa1c1582 100644
--- a/src/main/java/com/google/devtools/build/lib/remote/http/HttpCacheClient.java
+++ b/src/main/java/com/google/devtools/build/lib/remote/http/HttpCacheClient.java
@@ -19,12 +19,14 @@ import com.google.auth.Credentials;
Expand Down Expand Up @@ -218,34 +218,30 @@ index 1efecd3bb1..98a2866200 100644
Promise<Channel> channelReady = eventLoop.next().newPromise();
channelPool
.acquire()
@@ -388,8 +400,17 @@ public final class HttpCacheClient implements RemoteCacheClient {
@@ -388,8 +400,13 @@ public final class HttpCacheClient implements RemoteCacheClient {
new IdleTimeoutHandler(timeoutSeconds, ReadTimeoutException.INSTANCE));
pipeline.addLast(new HttpClientCodec());
pipeline.addLast("inflater", new HttpContentDecompressor());
+ ImmutableList.Builder<Entry<String, String>> headersBuilder = ImmutableList.<Entry<String, String>>builder();
+ headersBuilder.addAll(extraHttpHeaders);
+ if (offset > 0) {
+ logger.atInfo().log("Resuming download at offset %d at %s", offset, uri);
+ System.err.println(String.format("RETRY Resuming download at offset %d at %s", offset, uri));
+ headersBuilder.add(Maps.immutableEntry("Range", String.format("bytes=%d-", offset)));
+ } else {
+ System.err.println(String.format("START Download from beginning %s", uri));
+ }
synchronized (credentialsLock) {
- pipeline.addLast(new HttpDownloadHandler(creds, extraHttpHeaders));
+ pipeline.addLast(new HttpDownloadHandler(creds, headersBuilder.build()));
}

if (!channel.eventLoop().inEventLoop()) {
@@ -460,6 +481,7 @@ public final class HttpCacheClient implements RemoteCacheClient {

@@ -461,6 +478,7 @@ public final class HttpCacheClient implements RemoteCacheClient {
@SuppressWarnings("FutureReturnValueIgnored")
private ListenableFuture<Void> get(Digest digest, final OutputStream out, boolean casDownload) {
+ final AtomicLong bytesDownloaded = new AtomicLong();
final AtomicBoolean dataWritten = new AtomicBoolean();
+ AtomicLong bytesDownloaded = new AtomicLong();
OutputStream wrappedOut =
new OutputStream() {
@@ -470,12 +492,14 @@ public final class HttpCacheClient implements RemoteCacheClient {
// OutputStream.close() does nothing, which is what we want to ensure that the
@@ -470,12 +488,14 @@ public final class HttpCacheClient implements RemoteCacheClient {
@Override
public void write(byte[] b, int offset, int length) throws IOException {
dataWritten.set(true);
Expand All @@ -260,7 +256,7 @@ index 1efecd3bb1..98a2866200 100644
out.write(b);
}

@@ -485,61 +509,63 @@ public final class HttpCacheClient implements RemoteCacheClient {
@@ -485,61 +505,69 @@ public final class HttpCacheClient implements RemoteCacheClient {
}
};
DownloadCommand downloadCmd = new DownloadCommand(uri, casDownload, digest, wrappedOut);
Expand Down Expand Up @@ -311,6 +307,12 @@ index 1efecd3bb1..98a2866200 100644
- } finally {
- releaseDownloadChannel(ch);
+ return retrier.executeAsync(() -> {
+ System.err.println(String.format(
+ "REMOTE CACHE DOWNLOAD %s/%s/%s at offset %d",
+ uri,
+ casDownload ? "cas" : "ac",
+ digest.toString(),
+ bytesDownloaded.get()));
+ SettableFuture<Void> outerF = SettableFuture.create();
+ acquireDownloadChannel(bytesDownloaded.get())
+ .addListener(
Expand Down Expand Up @@ -373,7 +375,7 @@ index 1efecd3bb1..98a2866200 100644
.addListener(
(Future<Channel> channelPromise) -> {
if (!channelPromise.isSuccess()) {
@@ -673,20 +699,24 @@ public final class HttpCacheClient implements RemoteCacheClient {
@@ -673,20 +701,24 @@ public final class HttpCacheClient implements RemoteCacheClient {
@Override
public ListenableFuture<Void> uploadFile(
RemoteActionExecutionContext context, Digest digest, Path file) {
Expand Down

0 comments on commit 8d976d3

Please sign in to comment.