31
31
import com .google .devtools .build .lib .actions .cache .ActionCache ;
32
32
import com .google .devtools .build .lib .actions .cache .ActionCache .Entry .SerializableTreeArtifactValue ;
33
33
import com .google .devtools .build .lib .actions .cache .MetadataDigestUtils ;
34
- import com .google .devtools .build .lib .actions .cache .MetadataHandler ;
34
+ import com .google .devtools .build .lib .actions .cache .OutputMetadataStore ;
35
35
import com .google .devtools .build .lib .actions .cache .Protos .ActionCacheStatistics .MissReason ;
36
36
import com .google .devtools .build .lib .collect .nestedset .NestedSet ;
37
37
import com .google .devtools .build .lib .collect .nestedset .NestedSetBuilder ;
@@ -180,7 +180,7 @@ private static FileArtifactValue getCachedMetadata(
180
180
* @param action action to be validated.
181
181
* @param actionInputs the inputs of the action. Normally just the result of action.getInputs(),
182
182
* but if this action doesn't yet know its inputs, we check the inputs from the cache.
183
- * @param metadataHandler provider of metadata for the artifacts this action interacts with.
183
+ * @param outputMetadataStore provider of metadata for the artifacts this action interacts with.
184
184
* @param checkOutput true to validate output artifacts, Otherwise, just validate inputs.
185
185
* @param cachedOutputMetadata a set of cached metadata that should be used instead of loading
186
186
* from {@code metadataHandler}.
@@ -190,8 +190,8 @@ private static boolean validateArtifacts(
190
190
ActionCache .Entry entry ,
191
191
Action action ,
192
192
NestedSet <Artifact > actionInputs ,
193
- MetadataProvider metadataProvider ,
194
- MetadataHandler metadataHandler ,
193
+ InputMetadataProvider inputMetadataProvider ,
194
+ OutputMetadataStore outputMetadataStore ,
195
195
boolean checkOutput ,
196
196
@ Nullable CachedOutputMetadata cachedOutputMetadata )
197
197
throws InterruptedException {
@@ -200,14 +200,15 @@ private static boolean validateArtifacts(
200
200
for (Artifact artifact : action .getOutputs ()) {
201
201
FileArtifactValue metadata = getCachedMetadata (cachedOutputMetadata , artifact );
202
202
if (metadata == null ) {
203
- metadata = getOutputMetadataMaybe (metadataHandler , artifact );
203
+ metadata = getOutputMetadataMaybe (outputMetadataStore , artifact );
204
204
}
205
205
206
206
mdMap .put (artifact .getExecPathString (), metadata );
207
207
}
208
208
}
209
209
for (Artifact artifact : actionInputs .toList ()) {
210
- mdMap .put (artifact .getExecPathString (), getInputMetadataMaybe (metadataProvider , artifact ));
210
+ mdMap .put (
211
+ artifact .getExecPathString (), getInputMetadataMaybe (inputMetadataProvider , artifact ));
211
212
}
212
213
return !Arrays .equals (MetadataDigestUtils .fromMetadata (mdMap ), entry .getFileDigest ());
213
214
}
@@ -319,7 +320,7 @@ private CachedOutputMetadata(
319
320
}
320
321
321
322
private static CachedOutputMetadata loadCachedOutputMetadata (
322
- Action action , ActionCache .Entry entry , MetadataHandler metadataHandler )
323
+ Action action , ActionCache .Entry entry , OutputMetadataStore outputMetadataStore )
323
324
throws InterruptedException {
324
325
Instant now = Instant .now ();
325
326
ImmutableMap .Builder <Artifact , RemoteFileArtifactValue > remoteFileMetadata =
@@ -348,7 +349,7 @@ private static CachedOutputMetadata loadCachedOutputMetadata(
348
349
349
350
TreeArtifactValue localTreeMetadata ;
350
351
try {
351
- localTreeMetadata = metadataHandler .getTreeArtifactValue (parent );
352
+ localTreeMetadata = outputMetadataStore .getTreeArtifactValue (parent );
352
353
} catch (IOException e ) {
353
354
// Ignore the cached metadata if we encountered an error when loading corresponding
354
355
// local one.
@@ -399,7 +400,7 @@ private static CachedOutputMetadata loadCachedOutputMetadata(
399
400
400
401
FileArtifactValue localMetadata ;
401
402
try {
402
- localMetadata = getOutputMetadataOrConstant (metadataHandler , artifact );
403
+ localMetadata = getOutputMetadataOrConstant (outputMetadataStore , artifact );
403
404
} catch (FileNotFoundException ignored ) {
404
405
localMetadata = null ;
405
406
} catch (IOException e ) {
@@ -439,8 +440,8 @@ public Token getTokenIfNeedToExecute(
439
440
Map <String , String > clientEnv ,
440
441
OutputPermissions outputPermissions ,
441
442
EventHandler handler ,
442
- MetadataProvider metadataProvider ,
443
- MetadataHandler metadataHandler ,
443
+ InputMetadataProvider inputMetadataProvider ,
444
+ OutputMetadataStore outputMetadataStore ,
444
445
ArtifactExpander artifactExpander ,
445
446
Map <String , String > remoteDefaultPlatformProperties ,
446
447
boolean loadCachedOutputMetadata )
@@ -456,7 +457,7 @@ public Token getTokenIfNeedToExecute(
456
457
// Some types of middlemen are not checked because they should not
457
458
// propagate invalidation of their inputs.
458
459
if (middlemanType != MiddlemanType .SCHEDULING_DEPENDENCY_MIDDLEMAN ) {
459
- checkMiddlemanAction (action , handler , metadataProvider , metadataHandler );
460
+ checkMiddlemanAction (action , handler , inputMetadataProvider , outputMetadataStore );
460
461
}
461
462
return null ;
462
463
}
@@ -490,15 +491,15 @@ public Token getTokenIfNeedToExecute(
490
491
&& cacheConfig .storeOutputMetadata ()
491
492
&& loadCachedOutputMetadata ) {
492
493
// load remote metadata from action cache
493
- cachedOutputMetadata = loadCachedOutputMetadata (action , entry , metadataHandler );
494
+ cachedOutputMetadata = loadCachedOutputMetadata (action , entry , outputMetadataStore );
494
495
}
495
496
496
497
if (mustExecute (
497
498
action ,
498
499
entry ,
499
500
handler ,
500
- metadataProvider ,
501
- metadataHandler ,
501
+ inputMetadataProvider ,
502
+ outputMetadataStore ,
502
503
artifactExpander ,
503
504
actionInputs ,
504
505
clientEnv ,
@@ -517,8 +518,8 @@ public Token getTokenIfNeedToExecute(
517
518
518
519
// Inject cached output metadata if we have an action cache hit
519
520
if (cachedOutputMetadata != null ) {
520
- cachedOutputMetadata .remoteFileMetadata .forEach (metadataHandler ::injectFile );
521
- cachedOutputMetadata .mergedTreeMetadata .forEach (metadataHandler ::injectTree );
521
+ cachedOutputMetadata .remoteFileMetadata .forEach (outputMetadataStore ::injectFile );
522
+ cachedOutputMetadata .mergedTreeMetadata .forEach (outputMetadataStore ::injectTree );
522
523
}
523
524
524
525
return null ;
@@ -528,8 +529,8 @@ private boolean mustExecute(
528
529
Action action ,
529
530
@ Nullable ActionCache .Entry entry ,
530
531
EventHandler handler ,
531
- MetadataProvider metadataProvider ,
532
- MetadataHandler metadataHandler ,
532
+ InputMetadataProvider inputMetadataProvider ,
533
+ OutputMetadataStore outputMetadataStore ,
533
534
ArtifactExpander artifactExpander ,
534
535
NestedSet <Artifact > actionInputs ,
535
536
Map <String , String > clientEnv ,
@@ -558,8 +559,8 @@ private boolean mustExecute(
558
559
entry ,
559
560
action ,
560
561
actionInputs ,
561
- metadataProvider ,
562
- metadataHandler ,
562
+ inputMetadataProvider ,
563
+ outputMetadataStore ,
563
564
true ,
564
565
cachedOutputMetadata )) {
565
566
reportChanged (handler , action );
@@ -584,16 +585,17 @@ private boolean mustExecute(
584
585
}
585
586
586
587
private static FileArtifactValue getInputMetadataOrConstant (
587
- MetadataProvider metadataProvider , Artifact artifact ) throws IOException {
588
- FileArtifactValue metadata = metadataProvider .getInputMetadata (artifact );
588
+ InputMetadataProvider inputMetadataProvider , Artifact artifact ) throws IOException {
589
+ FileArtifactValue metadata = inputMetadataProvider .getInputMetadata (artifact );
589
590
return (metadata != null && artifact .isConstantMetadata ())
590
591
? ConstantMetadataValue .INSTANCE
591
592
: metadata ;
592
593
}
593
594
594
595
private static FileArtifactValue getOutputMetadataOrConstant (
595
- MetadataHandler metadataHandler , Artifact artifact ) throws IOException , InterruptedException {
596
- FileArtifactValue metadata = metadataHandler .getOutputMetadata (artifact );
596
+ OutputMetadataStore outputMetadataStore , Artifact artifact )
597
+ throws IOException , InterruptedException {
598
+ FileArtifactValue metadata = outputMetadataStore .getOutputMetadata (artifact );
597
599
return (metadata != null && artifact .isConstantMetadata ())
598
600
? ConstantMetadataValue .INSTANCE
599
601
: metadata ;
@@ -604,9 +606,9 @@ private static FileArtifactValue getOutputMetadataOrConstant(
604
606
// should propagate the exception, because it is unexpected (e.g., bad file system state).
605
607
@ Nullable
606
608
private static FileArtifactValue getInputMetadataMaybe (
607
- MetadataProvider metadataProvider , Artifact artifact ) {
609
+ InputMetadataProvider inputMetadataProvider , Artifact artifact ) {
608
610
try {
609
- return getInputMetadataOrConstant (metadataProvider , artifact );
611
+ return getInputMetadataOrConstant (inputMetadataProvider , artifact );
610
612
} catch (IOException e ) {
611
613
return null ;
612
614
}
@@ -617,9 +619,9 @@ private static FileArtifactValue getInputMetadataMaybe(
617
619
// should propagate the exception, because it is unexpected (e.g., bad file system state).
618
620
@ Nullable
619
621
private static FileArtifactValue getOutputMetadataMaybe (
620
- MetadataHandler metadataHandler , Artifact artifact ) throws InterruptedException {
622
+ OutputMetadataStore outputMetadataStore , Artifact artifact ) throws InterruptedException {
621
623
try {
622
- return getOutputMetadataOrConstant (metadataHandler , artifact );
624
+ return getOutputMetadataOrConstant (outputMetadataStore , artifact );
623
625
} catch (IOException e ) {
624
626
return null ;
625
627
}
@@ -628,8 +630,8 @@ private static FileArtifactValue getOutputMetadataMaybe(
628
630
public void updateActionCache (
629
631
Action action ,
630
632
Token token ,
631
- MetadataProvider metadataProvider ,
632
- MetadataHandler metadataHandler ,
633
+ InputMetadataProvider inputMetadataProvider ,
634
+ OutputMetadataStore outputMetadataStore ,
633
635
ArtifactExpander artifactExpander ,
634
636
Map <String , String > clientEnv ,
635
637
OutputPermissions outputPermissions ,
@@ -656,17 +658,17 @@ public void updateActionCache(
656
658
if (!key .equals (execPath )) {
657
659
actionCache .remove (execPath );
658
660
}
659
- if (!metadataHandler .artifactOmitted (output )) {
661
+ if (!outputMetadataStore .artifactOmitted (output )) {
660
662
if (output .isTreeArtifact ()) {
661
663
SpecialArtifact parent = (SpecialArtifact ) output ;
662
- TreeArtifactValue metadata = metadataHandler .getTreeArtifactValue (parent );
664
+ TreeArtifactValue metadata = outputMetadataStore .getTreeArtifactValue (parent );
663
665
entry .addOutputTree (parent , metadata , cacheConfig .storeOutputMetadata ());
664
666
} else {
665
667
// Output files *must* exist and be accessible after successful action execution. We use
666
668
// the 'constant' metadata for the volatile workspace status output. The volatile output
667
669
// contains information such as timestamps, and even when --stamp is enabled, we don't
668
670
// want to rebuild everything if only that file changes.
669
- FileArtifactValue metadata = getOutputMetadataOrConstant (metadataHandler , output );
671
+ FileArtifactValue metadata = getOutputMetadataOrConstant (outputMetadataStore , output );
670
672
checkState (metadata != null );
671
673
entry .addOutputFile (output , metadata , cacheConfig .storeOutputMetadata ());
672
674
}
@@ -684,7 +686,7 @@ public void updateActionCache(
684
686
for (Artifact input : action .getInputs ().toList ()) {
685
687
entry .addInputFile (
686
688
input .getExecPath (),
687
- getInputMetadataMaybe (metadataProvider , input ),
689
+ getInputMetadataMaybe (inputMetadataProvider , input ),
688
690
/* saveExecPath= */ !excludePathsFromActionCache .contains (input ));
689
691
}
690
692
entry .getFileDigest ();
@@ -768,8 +770,8 @@ public List<Artifact> getCachedInputs(Action action, PackageRootResolver resolve
768
770
private void checkMiddlemanAction (
769
771
Action action ,
770
772
EventHandler handler ,
771
- MetadataProvider metadataProvider ,
772
- MetadataHandler metadataHandler )
773
+ InputMetadataProvider inputMetadataProvider ,
774
+ OutputMetadataStore outputMetadataStore )
773
775
throws InterruptedException {
774
776
if (!cacheConfig .enabled ()) {
775
777
// Action cache is disabled, don't generate digests.
@@ -788,8 +790,8 @@ private void checkMiddlemanAction(
788
790
entry ,
789
791
action ,
790
792
action .getInputs (),
791
- metadataProvider ,
792
- metadataHandler ,
793
+ inputMetadataProvider ,
794
+ outputMetadataStore ,
793
795
false ,
794
796
/* cachedOutputMetadata= */ null )) {
795
797
reportChanged (handler , action );
@@ -809,12 +811,12 @@ private void checkMiddlemanAction(
809
811
for (Artifact input : action .getInputs ().toList ()) {
810
812
entry .addInputFile (
811
813
input .getExecPath (),
812
- getInputMetadataMaybe (metadataProvider , input ),
814
+ getInputMetadataMaybe (inputMetadataProvider , input ),
813
815
/* saveExecPath= */ true );
814
816
}
815
817
}
816
818
817
- metadataHandler .setDigestForVirtualArtifact (middleman , entry .getFileDigest ());
819
+ outputMetadataStore .setDigestForVirtualArtifact (middleman , entry .getFileDigest ());
818
820
if (changed ) {
819
821
actionCache .put (cacheKey , entry );
820
822
} else {
@@ -831,8 +833,8 @@ public Token getTokenUnconditionallyAfterFailureToRecordActionCacheHit(
831
833
Map <String , String > clientEnv ,
832
834
OutputPermissions outputPermissions ,
833
835
EventHandler handler ,
834
- MetadataProvider metadataProvider ,
835
- MetadataHandler metadataHandler ,
836
+ InputMetadataProvider inputMetadataProvider ,
837
+ OutputMetadataStore outputMetadataStore ,
836
838
ArtifactExpander artifactExpander ,
837
839
Map <String , String > remoteDefaultPlatformProperties ,
838
840
boolean loadCachedOutputMetadata )
@@ -846,8 +848,8 @@ public Token getTokenUnconditionallyAfterFailureToRecordActionCacheHit(
846
848
clientEnv ,
847
849
outputPermissions ,
848
850
handler ,
849
- metadataProvider ,
850
- metadataHandler ,
851
+ inputMetadataProvider ,
852
+ outputMetadataStore ,
851
853
artifactExpander ,
852
854
remoteDefaultPlatformProperties ,
853
855
loadCachedOutputMetadata );
0 commit comments