56
56
import com .google .devtools .build .lib .remote .zstd .ZstdDecompressingOutputStream ;
57
57
import com .google .devtools .build .lib .vfs .Path ;
58
58
import com .google .protobuf .ByteString ;
59
+ import io .grpc .Channel ;
59
60
import io .grpc .Status ;
60
61
import io .grpc .Status .Code ;
61
62
import io .grpc .StatusRuntimeException ;
@@ -122,7 +123,8 @@ private int computeMaxMissingBlobsDigestsPerMessage() {
122
123
return (options .maxOutboundMessageSize - overhead ) / digestSize ;
123
124
}
124
125
125
- private ContentAddressableStorageFutureStub casFutureStub (RemoteActionExecutionContext context ) {
126
+ private ContentAddressableStorageFutureStub casFutureStub (
127
+ RemoteActionExecutionContext context , Channel channel ) {
126
128
return ContentAddressableStorageGrpc .newFutureStub (channel )
127
129
.withInterceptors (
128
130
TracingMetadataUtils .attachMetadataInterceptor (context .getRequestMetadata ()),
@@ -131,7 +133,7 @@ private ContentAddressableStorageFutureStub casFutureStub(RemoteActionExecutionC
131
133
.withDeadlineAfter (options .remoteTimeout .getSeconds (), TimeUnit .SECONDS );
132
134
}
133
135
134
- private ByteStreamStub bsAsyncStub (RemoteActionExecutionContext context ) {
136
+ private ByteStreamStub bsAsyncStub (RemoteActionExecutionContext context , Channel channel ) {
135
137
return ByteStreamGrpc .newStub (channel )
136
138
.withInterceptors (
137
139
TracingMetadataUtils .attachMetadataInterceptor (context .getRequestMetadata ()),
@@ -140,7 +142,8 @@ private ByteStreamStub bsAsyncStub(RemoteActionExecutionContext context) {
140
142
.withDeadlineAfter (options .remoteTimeout .getSeconds (), TimeUnit .SECONDS );
141
143
}
142
144
143
- private ActionCacheFutureStub acFutureStub (RemoteActionExecutionContext context ) {
145
+ private ActionCacheFutureStub acFutureStub (
146
+ RemoteActionExecutionContext context , Channel channel ) {
144
147
return ActionCacheGrpc .newFutureStub (channel )
145
148
.withInterceptors (
146
149
TracingMetadataUtils .attachMetadataInterceptor (context .getRequestMetadata ()),
@@ -222,7 +225,11 @@ public ListenableFuture<ImmutableSet<Digest>> findMissingDigests(
222
225
private ListenableFuture <FindMissingBlobsResponse > getMissingDigests (
223
226
RemoteActionExecutionContext context , FindMissingBlobsRequest request ) {
224
227
return Utils .refreshIfUnauthenticatedAsync (
225
- () -> retrier .executeAsync (() -> casFutureStub (context ).findMissingBlobs (request )),
228
+ () ->
229
+ retrier .executeAsync (
230
+ () ->
231
+ channel .withChannelFuture (
232
+ channel -> casFutureStub (context , channel ).findMissingBlobs (request ))),
226
233
callCredentialsProvider );
227
234
}
228
235
@@ -254,7 +261,10 @@ public ListenableFuture<CachedActionResult> downloadActionResult(
254
261
return Utils .refreshIfUnauthenticatedAsync (
255
262
() ->
256
263
retrier .executeAsync (
257
- () -> handleStatus (acFutureStub (context ).getActionResult (request ))),
264
+ () ->
265
+ handleStatus (
266
+ channel .withChannelFuture (
267
+ channel -> acFutureStub (context , channel ).getActionResult (request )))),
258
268
callCredentialsProvider );
259
269
}
260
270
@@ -267,13 +277,15 @@ public ListenableFuture<Void> uploadActionResult(
267
277
retrier .executeAsync (
268
278
() ->
269
279
Futures .catchingAsync (
270
- acFutureStub (context )
271
- .updateActionResult (
272
- UpdateActionResultRequest .newBuilder ()
273
- .setInstanceName (options .remoteInstanceName )
274
- .setActionDigest (actionKey .getDigest ())
275
- .setActionResult (actionResult )
276
- .build ()),
280
+ channel .withChannelFuture (
281
+ channel ->
282
+ acFutureStub (context , channel )
283
+ .updateActionResult (
284
+ UpdateActionResultRequest .newBuilder ()
285
+ .setInstanceName (options .remoteInstanceName )
286
+ .setActionDigest (actionKey .getDigest ())
287
+ .setActionResult (actionResult )
288
+ .build ())),
277
289
StatusRuntimeException .class ,
278
290
(sre ) -> Futures .immediateFailedFuture (new IOException (sre )),
279
291
MoreExecutors .directExecutor ())),
@@ -317,18 +329,26 @@ private ListenableFuture<Void> downloadBlob(
317
329
@ Nullable Supplier <Digest > digestSupplier ) {
318
330
AtomicLong offset = new AtomicLong (0 );
319
331
ProgressiveBackoff progressiveBackoff = new ProgressiveBackoff (retrier ::newBackoff );
320
- ListenableFuture <Void > downloadFuture =
332
+ ListenableFuture <Long > downloadFuture =
321
333
Utils .refreshIfUnauthenticatedAsync (
322
334
() ->
323
335
retrier .executeAsync (
324
336
() ->
325
- requestRead (
326
- context , offset , progressiveBackoff , digest , out , digestSupplier ),
337
+ channel .withChannelFuture (
338
+ channel ->
339
+ requestRead (
340
+ context ,
341
+ offset ,
342
+ progressiveBackoff ,
343
+ digest ,
344
+ out ,
345
+ digestSupplier ,
346
+ channel )),
327
347
progressiveBackoff ),
328
348
callCredentialsProvider );
329
349
330
350
return Futures .catchingAsync (
331
- downloadFuture ,
351
+ Futures . transform ( downloadFuture , bytesWritten -> null , MoreExecutors . directExecutor ()) ,
332
352
StatusRuntimeException .class ,
333
353
(e ) -> Futures .immediateFailedFuture (new IOException (e )),
334
354
MoreExecutors .directExecutor ());
@@ -343,17 +363,18 @@ public static String getResourceName(String instanceName, Digest digest, boolean
343
363
return resourceName + DigestUtil .toString (digest );
344
364
}
345
365
346
- private ListenableFuture <Void > requestRead (
366
+ private ListenableFuture <Long > requestRead (
347
367
RemoteActionExecutionContext context ,
348
368
AtomicLong offset ,
349
369
ProgressiveBackoff progressiveBackoff ,
350
370
Digest digest ,
351
371
CountingOutputStream out ,
352
- @ Nullable Supplier <Digest > digestSupplier ) {
372
+ @ Nullable Supplier <Digest > digestSupplier ,
373
+ Channel channel ) {
353
374
String resourceName =
354
375
getResourceName (options .remoteInstanceName , digest , options .cacheCompression );
355
- SettableFuture <Void > future = SettableFuture .create ();
356
- bsAsyncStub (context )
376
+ SettableFuture <Long > future = SettableFuture .create ();
377
+ bsAsyncStub (context , channel )
357
378
.read (
358
379
ReadRequest .newBuilder ()
359
380
.setResourceName (resourceName )
@@ -400,7 +421,7 @@ public void onCompleted() {
400
421
Utils .verifyBlobContents (digest , digestSupplier .get ());
401
422
}
402
423
out .flush ();
403
- future .set (null );
424
+ future .set (offset . get () );
404
425
} catch (IOException e ) {
405
426
future .setException (e );
406
427
} catch (RuntimeException e ) {
0 commit comments