Skip to content

Commit 8ec4c50

Browse files
lberkicopybara-github
authored andcommitted
Rename MetadataProvider to InputMetadataProvider and MetadataHandler to OutputMetadataStore.
This is to better underline that one deals with action inputs, the other, with action outputs. This change was generated mostly mechanically using my IDE, with manual tweaks to fix up the annoying "/* parameterName= */" comments. RELNOTES: None. PiperOrigin-RevId: 523743519 Change-Id: Ia7a67ad4296e82c31d50f47045663f2a6f151299
1 parent b2d1ca9 commit 8ec4c50

File tree

57 files changed

+426
-392
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+426
-392
lines changed

src/main/java/com/google/devtools/build/lib/actions/AbstractAction.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import com.google.common.flogger.GoogleLogger;
2424
import com.google.devtools.build.lib.actions.Artifact.ArchivedTreeArtifact;
2525
import com.google.devtools.build.lib.actions.Artifact.SpecialArtifact;
26-
import com.google.devtools.build.lib.actions.cache.MetadataHandler;
26+
import com.google.devtools.build.lib.actions.cache.OutputMetadataStore;
2727
import com.google.devtools.build.lib.actions.extra.ExtraActionInfo;
2828
import com.google.devtools.build.lib.analysis.platform.PlatformInfo;
2929
import com.google.devtools.build.lib.cmdline.Label;
@@ -548,14 +548,14 @@ public static void deleteOutput(Path path, @Nullable Root root) throws IOExcepti
548548
* checking, this method must be called.
549549
*/
550550
protected void checkInputsForDirectories(
551-
EventHandler eventHandler, MetadataProvider metadataProvider) throws ExecException {
551+
EventHandler eventHandler, InputMetadataProvider inputMetadataProvider) throws ExecException {
552552
// Report "directory dependency checking" warning only for non-generated directories (generated
553553
// ones will be reported earlier).
554554
for (Artifact input : getMandatoryInputs().toList()) {
555555
// Assume that if the file did not exist, we would not have gotten here.
556556
try {
557557
if (input.isSourceArtifact()
558-
&& metadataProvider.getInputMetadata(input).getType().isDirectory()) {
558+
&& inputMetadataProvider.getInputMetadata(input).getType().isDirectory()) {
559559
// TODO(ulfjack): What about dependency checking of special files?
560560
eventHandler.handle(
561561
Event.warn(
@@ -581,12 +581,12 @@ protected void checkOutputsForDirectories(ActionExecutionContext actionExecution
581581
throws InterruptedException {
582582
FileArtifactValue metadata;
583583
for (Artifact output : getOutputs()) {
584-
MetadataHandler metadataHandler = actionExecutionContext.getMetadataHandler();
585-
if (metadataHandler.artifactOmitted(output)) {
584+
OutputMetadataStore outputMetadataStore = actionExecutionContext.getOutputMetadataStore();
585+
if (outputMetadataStore.artifactOmitted(output)) {
586586
continue;
587587
}
588588
try {
589-
metadata = metadataHandler.getOutputMetadata(output);
589+
metadata = outputMetadataStore.getOutputMetadata(output);
590590
} catch (IOException e) {
591591
logger.atWarning().withCause(e).log("Error getting metadata for %s", output);
592592
metadata = null;

src/main/java/com/google/devtools/build/lib/actions/ActionCacheChecker.java

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import com.google.devtools.build.lib.actions.cache.ActionCache;
3232
import com.google.devtools.build.lib.actions.cache.ActionCache.Entry.SerializableTreeArtifactValue;
3333
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;
3535
import com.google.devtools.build.lib.actions.cache.Protos.ActionCacheStatistics.MissReason;
3636
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
3737
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
@@ -180,7 +180,7 @@ private static FileArtifactValue getCachedMetadata(
180180
* @param action action to be validated.
181181
* @param actionInputs the inputs of the action. Normally just the result of action.getInputs(),
182182
* 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.
184184
* @param checkOutput true to validate output artifacts, Otherwise, just validate inputs.
185185
* @param cachedOutputMetadata a set of cached metadata that should be used instead of loading
186186
* from {@code metadataHandler}.
@@ -190,8 +190,8 @@ private static boolean validateArtifacts(
190190
ActionCache.Entry entry,
191191
Action action,
192192
NestedSet<Artifact> actionInputs,
193-
MetadataProvider metadataProvider,
194-
MetadataHandler metadataHandler,
193+
InputMetadataProvider inputMetadataProvider,
194+
OutputMetadataStore outputMetadataStore,
195195
boolean checkOutput,
196196
@Nullable CachedOutputMetadata cachedOutputMetadata)
197197
throws InterruptedException {
@@ -200,14 +200,15 @@ private static boolean validateArtifacts(
200200
for (Artifact artifact : action.getOutputs()) {
201201
FileArtifactValue metadata = getCachedMetadata(cachedOutputMetadata, artifact);
202202
if (metadata == null) {
203-
metadata = getOutputMetadataMaybe(metadataHandler, artifact);
203+
metadata = getOutputMetadataMaybe(outputMetadataStore, artifact);
204204
}
205205

206206
mdMap.put(artifact.getExecPathString(), metadata);
207207
}
208208
}
209209
for (Artifact artifact : actionInputs.toList()) {
210-
mdMap.put(artifact.getExecPathString(), getInputMetadataMaybe(metadataProvider, artifact));
210+
mdMap.put(
211+
artifact.getExecPathString(), getInputMetadataMaybe(inputMetadataProvider, artifact));
211212
}
212213
return !Arrays.equals(MetadataDigestUtils.fromMetadata(mdMap), entry.getFileDigest());
213214
}
@@ -319,7 +320,7 @@ private CachedOutputMetadata(
319320
}
320321

321322
private static CachedOutputMetadata loadCachedOutputMetadata(
322-
Action action, ActionCache.Entry entry, MetadataHandler metadataHandler)
323+
Action action, ActionCache.Entry entry, OutputMetadataStore outputMetadataStore)
323324
throws InterruptedException {
324325
Instant now = Instant.now();
325326
ImmutableMap.Builder<Artifact, RemoteFileArtifactValue> remoteFileMetadata =
@@ -348,7 +349,7 @@ private static CachedOutputMetadata loadCachedOutputMetadata(
348349

349350
TreeArtifactValue localTreeMetadata;
350351
try {
351-
localTreeMetadata = metadataHandler.getTreeArtifactValue(parent);
352+
localTreeMetadata = outputMetadataStore.getTreeArtifactValue(parent);
352353
} catch (IOException e) {
353354
// Ignore the cached metadata if we encountered an error when loading corresponding
354355
// local one.
@@ -399,7 +400,7 @@ private static CachedOutputMetadata loadCachedOutputMetadata(
399400

400401
FileArtifactValue localMetadata;
401402
try {
402-
localMetadata = getOutputMetadataOrConstant(metadataHandler, artifact);
403+
localMetadata = getOutputMetadataOrConstant(outputMetadataStore, artifact);
403404
} catch (FileNotFoundException ignored) {
404405
localMetadata = null;
405406
} catch (IOException e) {
@@ -439,8 +440,8 @@ public Token getTokenIfNeedToExecute(
439440
Map<String, String> clientEnv,
440441
OutputPermissions outputPermissions,
441442
EventHandler handler,
442-
MetadataProvider metadataProvider,
443-
MetadataHandler metadataHandler,
443+
InputMetadataProvider inputMetadataProvider,
444+
OutputMetadataStore outputMetadataStore,
444445
ArtifactExpander artifactExpander,
445446
Map<String, String> remoteDefaultPlatformProperties,
446447
boolean loadCachedOutputMetadata)
@@ -456,7 +457,7 @@ public Token getTokenIfNeedToExecute(
456457
// Some types of middlemen are not checked because they should not
457458
// propagate invalidation of their inputs.
458459
if (middlemanType != MiddlemanType.SCHEDULING_DEPENDENCY_MIDDLEMAN) {
459-
checkMiddlemanAction(action, handler, metadataProvider, metadataHandler);
460+
checkMiddlemanAction(action, handler, inputMetadataProvider, outputMetadataStore);
460461
}
461462
return null;
462463
}
@@ -490,15 +491,15 @@ public Token getTokenIfNeedToExecute(
490491
&& cacheConfig.storeOutputMetadata()
491492
&& loadCachedOutputMetadata) {
492493
// load remote metadata from action cache
493-
cachedOutputMetadata = loadCachedOutputMetadata(action, entry, metadataHandler);
494+
cachedOutputMetadata = loadCachedOutputMetadata(action, entry, outputMetadataStore);
494495
}
495496

496497
if (mustExecute(
497498
action,
498499
entry,
499500
handler,
500-
metadataProvider,
501-
metadataHandler,
501+
inputMetadataProvider,
502+
outputMetadataStore,
502503
artifactExpander,
503504
actionInputs,
504505
clientEnv,
@@ -517,8 +518,8 @@ public Token getTokenIfNeedToExecute(
517518

518519
// Inject cached output metadata if we have an action cache hit
519520
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);
522523
}
523524

524525
return null;
@@ -528,8 +529,8 @@ private boolean mustExecute(
528529
Action action,
529530
@Nullable ActionCache.Entry entry,
530531
EventHandler handler,
531-
MetadataProvider metadataProvider,
532-
MetadataHandler metadataHandler,
532+
InputMetadataProvider inputMetadataProvider,
533+
OutputMetadataStore outputMetadataStore,
533534
ArtifactExpander artifactExpander,
534535
NestedSet<Artifact> actionInputs,
535536
Map<String, String> clientEnv,
@@ -558,8 +559,8 @@ private boolean mustExecute(
558559
entry,
559560
action,
560561
actionInputs,
561-
metadataProvider,
562-
metadataHandler,
562+
inputMetadataProvider,
563+
outputMetadataStore,
563564
true,
564565
cachedOutputMetadata)) {
565566
reportChanged(handler, action);
@@ -584,16 +585,17 @@ private boolean mustExecute(
584585
}
585586

586587
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);
589590
return (metadata != null && artifact.isConstantMetadata())
590591
? ConstantMetadataValue.INSTANCE
591592
: metadata;
592593
}
593594

594595
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);
597599
return (metadata != null && artifact.isConstantMetadata())
598600
? ConstantMetadataValue.INSTANCE
599601
: metadata;
@@ -604,9 +606,9 @@ private static FileArtifactValue getOutputMetadataOrConstant(
604606
// should propagate the exception, because it is unexpected (e.g., bad file system state).
605607
@Nullable
606608
private static FileArtifactValue getInputMetadataMaybe(
607-
MetadataProvider metadataProvider, Artifact artifact) {
609+
InputMetadataProvider inputMetadataProvider, Artifact artifact) {
608610
try {
609-
return getInputMetadataOrConstant(metadataProvider, artifact);
611+
return getInputMetadataOrConstant(inputMetadataProvider, artifact);
610612
} catch (IOException e) {
611613
return null;
612614
}
@@ -617,9 +619,9 @@ private static FileArtifactValue getInputMetadataMaybe(
617619
// should propagate the exception, because it is unexpected (e.g., bad file system state).
618620
@Nullable
619621
private static FileArtifactValue getOutputMetadataMaybe(
620-
MetadataHandler metadataHandler, Artifact artifact) throws InterruptedException {
622+
OutputMetadataStore outputMetadataStore, Artifact artifact) throws InterruptedException {
621623
try {
622-
return getOutputMetadataOrConstant(metadataHandler, artifact);
624+
return getOutputMetadataOrConstant(outputMetadataStore, artifact);
623625
} catch (IOException e) {
624626
return null;
625627
}
@@ -628,8 +630,8 @@ private static FileArtifactValue getOutputMetadataMaybe(
628630
public void updateActionCache(
629631
Action action,
630632
Token token,
631-
MetadataProvider metadataProvider,
632-
MetadataHandler metadataHandler,
633+
InputMetadataProvider inputMetadataProvider,
634+
OutputMetadataStore outputMetadataStore,
633635
ArtifactExpander artifactExpander,
634636
Map<String, String> clientEnv,
635637
OutputPermissions outputPermissions,
@@ -656,17 +658,17 @@ public void updateActionCache(
656658
if (!key.equals(execPath)) {
657659
actionCache.remove(execPath);
658660
}
659-
if (!metadataHandler.artifactOmitted(output)) {
661+
if (!outputMetadataStore.artifactOmitted(output)) {
660662
if (output.isTreeArtifact()) {
661663
SpecialArtifact parent = (SpecialArtifact) output;
662-
TreeArtifactValue metadata = metadataHandler.getTreeArtifactValue(parent);
664+
TreeArtifactValue metadata = outputMetadataStore.getTreeArtifactValue(parent);
663665
entry.addOutputTree(parent, metadata, cacheConfig.storeOutputMetadata());
664666
} else {
665667
// Output files *must* exist and be accessible after successful action execution. We use
666668
// the 'constant' metadata for the volatile workspace status output. The volatile output
667669
// contains information such as timestamps, and even when --stamp is enabled, we don't
668670
// want to rebuild everything if only that file changes.
669-
FileArtifactValue metadata = getOutputMetadataOrConstant(metadataHandler, output);
671+
FileArtifactValue metadata = getOutputMetadataOrConstant(outputMetadataStore, output);
670672
checkState(metadata != null);
671673
entry.addOutputFile(output, metadata, cacheConfig.storeOutputMetadata());
672674
}
@@ -684,7 +686,7 @@ public void updateActionCache(
684686
for (Artifact input : action.getInputs().toList()) {
685687
entry.addInputFile(
686688
input.getExecPath(),
687-
getInputMetadataMaybe(metadataProvider, input),
689+
getInputMetadataMaybe(inputMetadataProvider, input),
688690
/* saveExecPath= */ !excludePathsFromActionCache.contains(input));
689691
}
690692
entry.getFileDigest();
@@ -768,8 +770,8 @@ public List<Artifact> getCachedInputs(Action action, PackageRootResolver resolve
768770
private void checkMiddlemanAction(
769771
Action action,
770772
EventHandler handler,
771-
MetadataProvider metadataProvider,
772-
MetadataHandler metadataHandler)
773+
InputMetadataProvider inputMetadataProvider,
774+
OutputMetadataStore outputMetadataStore)
773775
throws InterruptedException {
774776
if (!cacheConfig.enabled()) {
775777
// Action cache is disabled, don't generate digests.
@@ -788,8 +790,8 @@ private void checkMiddlemanAction(
788790
entry,
789791
action,
790792
action.getInputs(),
791-
metadataProvider,
792-
metadataHandler,
793+
inputMetadataProvider,
794+
outputMetadataStore,
793795
false,
794796
/* cachedOutputMetadata= */ null)) {
795797
reportChanged(handler, action);
@@ -809,12 +811,12 @@ private void checkMiddlemanAction(
809811
for (Artifact input : action.getInputs().toList()) {
810812
entry.addInputFile(
811813
input.getExecPath(),
812-
getInputMetadataMaybe(metadataProvider, input),
814+
getInputMetadataMaybe(inputMetadataProvider, input),
813815
/* saveExecPath= */ true);
814816
}
815817
}
816818

817-
metadataHandler.setDigestForVirtualArtifact(middleman, entry.getFileDigest());
819+
outputMetadataStore.setDigestForVirtualArtifact(middleman, entry.getFileDigest());
818820
if (changed) {
819821
actionCache.put(cacheKey, entry);
820822
} else {
@@ -831,8 +833,8 @@ public Token getTokenUnconditionallyAfterFailureToRecordActionCacheHit(
831833
Map<String, String> clientEnv,
832834
OutputPermissions outputPermissions,
833835
EventHandler handler,
834-
MetadataProvider metadataProvider,
835-
MetadataHandler metadataHandler,
836+
InputMetadataProvider inputMetadataProvider,
837+
OutputMetadataStore outputMetadataStore,
836838
ArtifactExpander artifactExpander,
837839
Map<String, String> remoteDefaultPlatformProperties,
838840
boolean loadCachedOutputMetadata)
@@ -846,8 +848,8 @@ public Token getTokenUnconditionallyAfterFailureToRecordActionCacheHit(
846848
clientEnv,
847849
outputPermissions,
848850
handler,
849-
metadataProvider,
850-
metadataHandler,
851+
inputMetadataProvider,
852+
outputMetadataStore,
851853
artifactExpander,
852854
remoteDefaultPlatformProperties,
853855
loadCachedOutputMetadata);

0 commit comments

Comments
 (0)