1717import static com .google .common .base .Strings .isNullOrEmpty ;
1818import static java .lang .String .format ;
1919
20- import build .bazel .remote .execution .v2 .Action ;
2120import build .bazel .remote .execution .v2 .ActionCacheGrpc ;
2221import build .bazel .remote .execution .v2 .ActionCacheGrpc .ActionCacheBlockingStub ;
2322import build .bazel .remote .execution .v2 .ActionResult ;
24- import build .bazel .remote .execution .v2 .Command ;
2523import build .bazel .remote .execution .v2 .ContentAddressableStorageGrpc ;
2624import build .bazel .remote .execution .v2 .ContentAddressableStorageGrpc .ContentAddressableStorageFutureStub ;
2725import build .bazel .remote .execution .v2 .Digest ;
3836import com .google .common .base .Ascii ;
3937import com .google .common .base .Preconditions ;
4038import com .google .common .base .Throwables ;
41- import com .google .common .collect .ImmutableList ;
4239import com .google .common .collect .ImmutableSet ;
4340import com .google .common .collect .Iterables ;
4441import com .google .common .collect .Maps ;
5047import com .google .common .util .concurrent .MoreExecutors ;
5148import com .google .common .util .concurrent .SettableFuture ;
5249import com .google .devtools .build .lib .actions .ActionInput ;
53- import com .google .devtools .build .lib .actions .ExecException ;
5450import com .google .devtools .build .lib .concurrent .ThreadSafety .ThreadSafe ;
5551import com .google .devtools .build .lib .remote .RemoteRetrier .ProgressiveBackoff ;
5652import com .google .devtools .build .lib .remote .common .SimpleBlobStore .ActionKey ;
5753import com .google .devtools .build .lib .remote .merkletree .MerkleTree ;
5854import com .google .devtools .build .lib .remote .options .RemoteOptions ;
5955import com .google .devtools .build .lib .remote .util .DigestUtil ;
6056import com .google .devtools .build .lib .remote .util .TracingMetadataUtils ;
61- import com .google .devtools .build .lib .util .io .FileOutErr ;
6257import com .google .devtools .build .lib .vfs .Path ;
6358import com .google .protobuf .ByteString ;
6459import com .google .protobuf .Message ;
7065import java .io .IOException ;
7166import java .io .OutputStream ;
7267import java .util .ArrayList ;
73- import java .util .Collection ;
7468import java .util .List ;
7569import java .util .Map ;
7670import java .util .concurrent .ExecutionException ;
@@ -166,17 +160,8 @@ public static boolean isRemoteCacheOptions(RemoteOptions options) {
166160 || Ascii .toLowerCase (options .remoteCache ).startsWith ("https://" ));
167161 }
168162
169- private ListenableFuture <FindMissingBlobsResponse > getMissingDigests (
170- FindMissingBlobsRequest request ) throws IOException , InterruptedException {
171- Context ctx = Context .current ();
172- try {
173- return retrier .executeAsync (() -> ctx .call (() -> casFutureStub ().findMissingBlobs (request )));
174- } catch (StatusRuntimeException e ) {
175- throw new IOException (e );
176- }
177- }
178-
179- private ImmutableSet <Digest > getMissingDigests (Iterable <Digest > digests )
163+ @ Override
164+ protected ImmutableSet <Digest > getMissingDigests (Iterable <Digest > digests )
180165 throws IOException , InterruptedException {
181166 if (Iterables .isEmpty (digests )) {
182167 return ImmutableSet .of ();
@@ -208,6 +193,16 @@ private ImmutableSet<Digest> getMissingDigests(Iterable<Digest> digests)
208193 return result .build ();
209194 }
210195
196+ private ListenableFuture <FindMissingBlobsResponse > getMissingDigests (
197+ FindMissingBlobsRequest request ) throws IOException , InterruptedException {
198+ Context ctx = Context .current ();
199+ try {
200+ return retrier .executeAsync (() -> ctx .call (() -> casFutureStub ().findMissingBlobs (request )));
201+ } catch (StatusRuntimeException e ) {
202+ throw new IOException (e );
203+ }
204+ }
205+
211206 /**
212207 * Ensures that the tree structure of the inputs, the input files themselves, and the command are
213208 * available in the remote cache, such that the tree can be reassembled and executed on another
@@ -376,32 +371,6 @@ public void onCompleted() {
376371 return future ;
377372 }
378373
379- @ Override
380- public void upload (
381- ActionKey actionKey ,
382- Action action ,
383- Command command ,
384- Path execRoot ,
385- Collection <Path > files ,
386- FileOutErr outErr )
387- throws ExecException , IOException , InterruptedException {
388- ActionResult .Builder result = ActionResult .newBuilder ();
389- upload (execRoot , actionKey , action , command , files , outErr , result );
390- try {
391- retrier .execute (
392- () ->
393- acBlockingStub ()
394- .updateActionResult (
395- UpdateActionResultRequest .newBuilder ()
396- .setInstanceName (options .remoteInstanceName )
397- .setActionDigest (actionKey .getDigest ())
398- .setActionResult (result )
399- .build ()));
400- } catch (StatusRuntimeException e ) {
401- throw new IOException (e );
402- }
403- }
404-
405374 @ Override
406375 protected ListenableFuture <Void > uploadFile (Digest digest , Path path ) {
407376 return uploader .uploadBlobAsync (
@@ -418,77 +387,6 @@ protected ListenableFuture<Void> uploadBlob(Digest digest, ByteString data) {
418387 /* forceUpload= */ true );
419388 }
420389
421- void upload (
422- Path execRoot ,
423- ActionKey actionKey ,
424- Action action ,
425- Command command ,
426- Collection <Path > files ,
427- FileOutErr outErr ,
428- ActionResult .Builder result )
429- throws ExecException , IOException , InterruptedException {
430- UploadManifest manifest =
431- new UploadManifest (
432- digestUtil ,
433- result ,
434- execRoot ,
435- options .incompatibleRemoteSymlinks ,
436- options .allowSymlinkUpload );
437- manifest .addFiles (files );
438- manifest .setStdoutStderr (outErr );
439- manifest .addAction (actionKey , action , command );
440-
441- Map <Digest , Path > digestToFile = manifest .getDigestToFile ();
442- Map <Digest , ByteString > digestToBlobs = manifest .getDigestToBlobs ();
443- Collection <Digest > digests = new ArrayList <>();
444- digests .addAll (digestToFile .keySet ());
445- digests .addAll (digestToBlobs .keySet ());
446-
447- ImmutableSet <Digest > digestsToUpload = getMissingDigests (digests );
448- ImmutableList .Builder <ListenableFuture <Void >> uploads = ImmutableList .builder ();
449- for (Digest digest : digestsToUpload ) {
450- Path file = digestToFile .get (digest );
451- if (file != null ) {
452- uploads .add (uploadFile (digest , file ));
453- } else {
454- ByteString blob = digestToBlobs .get (digest );
455- if (blob == null ) {
456- String message = "FindMissingBlobs call returned an unknown digest: " + digest ;
457- throw new IOException (message );
458- }
459- uploads .add (uploadBlob (digest , blob ));
460- }
461- }
462-
463- waitForUploads (uploads .build ());
464-
465- if (manifest .getStderrDigest () != null ) {
466- result .setStderrDigest (manifest .getStderrDigest ());
467- }
468- if (manifest .getStdoutDigest () != null ) {
469- result .setStdoutDigest (manifest .getStdoutDigest ());
470- }
471- }
472-
473- private static void waitForUploads (List <ListenableFuture <Void >> uploads )
474- throws IOException , InterruptedException {
475- try {
476- for (ListenableFuture <Void > upload : uploads ) {
477- upload .get ();
478- }
479- } catch (ExecutionException e ) {
480- // TODO(buchgr): Add support for cancellation and factor this method out to be shared
481- // between ByteStreamUploader as well.
482- Throwable cause = e .getCause ();
483- Throwables .throwIfInstanceOf (cause , IOException .class );
484- Throwables .throwIfInstanceOf (cause , InterruptedException .class );
485- if (cause != null ) {
486- throw new IOException (cause );
487- }
488- throw new IOException (e );
489- }
490- }
491-
492390 // Execution Cache API
493391
494392 @ Override
@@ -511,4 +409,22 @@ public ActionResult getCachedActionResult(ActionKey actionKey)
511409 throw new IOException (e );
512410 }
513411 }
412+
413+ @ Override
414+ protected void setCachedActionResult (ActionKey actionKey , ActionResult result )
415+ throws IOException , InterruptedException {
416+ try {
417+ retrier .execute (
418+ () ->
419+ acBlockingStub ()
420+ .updateActionResult (
421+ UpdateActionResultRequest .newBuilder ()
422+ .setInstanceName (options .remoteInstanceName )
423+ .setActionDigest (actionKey .getDigest ())
424+ .setActionResult (result )
425+ .build ()));
426+ } catch (StatusRuntimeException e ) {
427+ throw new IOException (e );
428+ }
429+ }
514430}
0 commit comments