@@ -609,62 +609,63 @@ Token checkActionCache(
609609 artifactExpander ,
610610 remoteDefaultProperties ,
611611 loadCachedOutputMetadata );
612- } catch (UserExecException e ) {
613- throw ActionExecutionException .fromExecException (e , action );
614- }
615- if (token == null ) {
616- boolean eventPosted = false ;
617- // Notify BlazeRuntimeStatistics about the action middleman 'execution'.
618- if (action .getActionType ().isMiddleman ()) {
619- eventHandler .post (new ActionMiddlemanEvent (action , actionStartTime ));
620- eventPosted = true ;
621- }
622612
623- if (action instanceof NotifyOnActionCacheHit ) {
624- NotifyOnActionCacheHit notify = (NotifyOnActionCacheHit ) action ;
625- ExtendedEventHandler contextEventHandler = selectEventHandler (action );
626- ActionCachedContext context =
627- new ActionCachedContext () {
628- @ Override
629- public ExtendedEventHandler getEventHandler () {
630- return contextEventHandler ;
631- }
632-
633- @ Override
634- public Path getExecRoot () {
635- return executorEngine .getExecRoot ();
636- }
637-
638- @ Override
639- public <T extends ActionContext > T getContext (Class <? extends T > type ) {
640- return executorEngine .getContext (type );
641- }
642- };
643- boolean recordActionCacheHit = notify .actionCacheHit (context );
644- if (!recordActionCacheHit ) {
645- token =
646- actionCacheChecker .getTokenUnconditionallyAfterFailureToRecordActionCacheHit (
647- action ,
648- resolvedCacheArtifacts ,
649- clientEnv ,
650- handler ,
651- metadataHandler ,
652- artifactExpander ,
653- remoteDefaultProperties ,
654- loadCachedOutputMetadata );
613+ if (token == null ) {
614+ boolean eventPosted = false ;
615+ // Notify BlazeRuntimeStatistics about the action middleman 'execution'.
616+ if (action .getActionType ().isMiddleman ()) {
617+ eventHandler .post (new ActionMiddlemanEvent (action , actionStartTime ));
618+ eventPosted = true ;
655619 }
656- }
657620
658- // We still need to check the outputs so that output file data is available to the value.
659- // Filesets cannot be cached in the action cache, so it is fine to pass null here.
660- checkOutputs (
661- action ,
662- metadataHandler ,
663- /*filesetOutputSymlinksForMetrics=*/ null ,
664- /*isActionCacheHitForMetrics=*/ true );
665- if (!eventPosted ) {
666- eventHandler .post (new CachedActionEvent (action , actionStartTime ));
621+ if (action instanceof NotifyOnActionCacheHit ) {
622+ NotifyOnActionCacheHit notify = (NotifyOnActionCacheHit ) action ;
623+ ExtendedEventHandler contextEventHandler = selectEventHandler (action );
624+ ActionCachedContext context =
625+ new ActionCachedContext () {
626+ @ Override
627+ public ExtendedEventHandler getEventHandler () {
628+ return contextEventHandler ;
629+ }
630+
631+ @ Override
632+ public Path getExecRoot () {
633+ return executorEngine .getExecRoot ();
634+ }
635+
636+ @ Override
637+ public <T extends ActionContext > T getContext (Class <? extends T > type ) {
638+ return executorEngine .getContext (type );
639+ }
640+ };
641+ boolean recordActionCacheHit = notify .actionCacheHit (context );
642+ if (!recordActionCacheHit ) {
643+ token =
644+ actionCacheChecker .getTokenUnconditionallyAfterFailureToRecordActionCacheHit (
645+ action ,
646+ resolvedCacheArtifacts ,
647+ clientEnv ,
648+ handler ,
649+ metadataHandler ,
650+ artifactExpander ,
651+ remoteDefaultProperties ,
652+ loadCachedOutputMetadata );
653+ }
654+ }
655+
656+ // We still need to check the outputs so that output file data is available to the value.
657+ // Filesets cannot be cached in the action cache, so it is fine to pass null here.
658+ checkOutputs (
659+ action ,
660+ metadataHandler ,
661+ /* filesetOutputSymlinksForMetrics= */ null ,
662+ /* isActionCacheHitForMetrics= */ true );
663+ if (!eventPosted ) {
664+ eventHandler .post (new CachedActionEvent (action , actionStartTime ));
665+ }
667666 }
667+ } catch (UserExecException e ) {
668+ throw ActionExecutionException .fromExecException (e , action );
668669 }
669670 return token ;
670671 }
@@ -1437,33 +1438,37 @@ private boolean checkOutputs(
14371438 @ Nullable ImmutableList <FilesetOutputSymlink > filesetOutputSymlinksForMetrics ,
14381439 boolean isActionCacheHitForMetrics ) {
14391440 boolean success = true ;
1440- for (Artifact output : action .getOutputs ()) {
1441- // getMetadata has the side effect of adding the artifact to the cache if it's not there
1442- // already (e.g., due to a previous call to MetadataHandler.injectDigest), therefore we only
1443- // call it if we know the artifact is not omitted.
1444- if (!metadataHandler .artifactOmitted (output )) {
1445- try {
1446- FileArtifactValue metadata = metadataHandler .getMetadata (output );
1447-
1448- addOutputToMetrics (
1449- output ,
1450- metadata ,
1451- metadataHandler ,
1452- filesetOutputSymlinksForMetrics ,
1453- isActionCacheHitForMetrics ,
1454- action );
1455- } catch (IOException e ) {
1456- success = false ;
1457- if (output .isTreeArtifact ()) {
1458- reportOutputTreeArtifactErrors (action , output , reporter , e );
1459- } else if (output .isSymlink () && e instanceof NotASymlinkException ) {
1460- reporter .handle (
1461- Event .error (
1462- action .getOwner ().getLocation (),
1463- String .format ("declared output '%s' is not a symlink" , output .prettyPrint ())));
1464- } else {
1465- // Are all other exceptions caught due to missing files?
1466- reportMissingOutputFile (action , output , reporter , output .getPath ().isSymbolicLink (), e );
1441+ try (SilentCloseable c = profiler .profile (ProfilerTask .INFO , "checkOutputs" )) {
1442+ for (Artifact output : action .getOutputs ()) {
1443+ // getMetadata has the side effect of adding the artifact to the cache if it's not there
1444+ // already (e.g., due to a previous call to MetadataHandler.injectDigest), therefore we only
1445+ // call it if we know the artifact is not omitted.
1446+ if (!metadataHandler .artifactOmitted (output )) {
1447+ try {
1448+ FileArtifactValue metadata = metadataHandler .getMetadata (output );
1449+
1450+ addOutputToMetrics (
1451+ output ,
1452+ metadata ,
1453+ metadataHandler ,
1454+ filesetOutputSymlinksForMetrics ,
1455+ isActionCacheHitForMetrics ,
1456+ action );
1457+ } catch (IOException e ) {
1458+ success = false ;
1459+ if (output .isTreeArtifact ()) {
1460+ reportOutputTreeArtifactErrors (action , output , reporter , e );
1461+ } else if (output .isSymlink () && e instanceof NotASymlinkException ) {
1462+ reporter .handle (
1463+ Event .error (
1464+ action .getOwner ().getLocation (),
1465+ String .format (
1466+ "declared output '%s' is not a symlink" , output .prettyPrint ())));
1467+ } else {
1468+ // Are all other exceptions caught due to missing files?
1469+ reportMissingOutputFile (
1470+ action , output , reporter , output .getPath ().isSymbolicLink (), e );
1471+ }
14671472 }
14681473 }
14691474 }
0 commit comments