Replace most usages of SyscallCache with the weaker XattrProvider. SyscallCache is unsafe to use with files that may change over the course of the build, like outputs and files in external repositories. The weaker XattrProvider type helps to ensure that a stale cached value is not used.
Also thread SyscallCache through to IncludeParser.
FilesystemValueChecker is still using SyscallCache on outputs/external repository files. It will be fixed in a follow-up.
PiperOrigin-RevId: 433254855
diff --git a/src/main/java/com/google/devtools/build/lib/actions/FileArtifactValue.java b/src/main/java/com/google/devtools/build/lib/actions/FileArtifactValue.java
index 4166cc0..b8dd83f 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/FileArtifactValue.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/FileArtifactValue.java
@@ -30,6 +30,7 @@
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.Symlinks;
import com.google.devtools.build.lib.vfs.SyscallCache;
+import com.google.devtools.build.lib.vfs.XattrProvider;
import com.google.devtools.build.skyframe.SkyValue;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -191,7 +192,7 @@
public static final FileArtifactValue OMITTED_FILE_MARKER = new OmittedFileValue();
public static FileArtifactValue createForSourceArtifact(
- Artifact artifact, FileValue fileValue, SyscallCache syscallCache) throws IOException {
+ Artifact artifact, FileValue fileValue, XattrProvider xattrProvider) throws IOException {
// Artifacts with known generating actions should obtain the derived artifact's SkyValue
// from the generating action, instead.
Preconditions.checkState(!artifact.hasKnownGeneratingAction());
@@ -203,7 +204,7 @@
isFile ? fileValue.getSize() : 0,
isFile ? fileValue.realFileStateValue().getContentsProxy() : null,
isFile ? fileValue.getDigest() : null,
- syscallCache);
+ xattrProvider);
}
public static FileArtifactValue createFromInjectedDigest(
@@ -225,14 +226,14 @@
}
public static FileArtifactValue createFromStat(
- Path path, FileStatus stat, SyscallCache syscallCache) throws IOException {
+ Path path, FileStatus stat, XattrProvider xattrProvider) throws IOException {
return create(
path,
stat.isFile(),
stat.getSize(),
FileContentsProxy.create(stat),
/*digest=*/ null,
- syscallCache);
+ xattrProvider);
}
private static FileArtifactValue create(
@@ -241,7 +242,7 @@
long size,
FileContentsProxy proxy,
@Nullable byte[] digest,
- SyscallCache syscallCache)
+ XattrProvider xattrProvider)
throws IOException {
if (!isFile) {
// In this case, we need to store the mtime because the action cache uses mtime for
@@ -250,7 +251,7 @@
return new DirectoryArtifactValue(path.getLastModifiedTime());
}
if (digest == null) {
- digest = DigestUtils.getDigestWithManualFallback(path, size, syscallCache);
+ digest = DigestUtils.getDigestWithManualFallback(path, size, xattrProvider);
}
Preconditions.checkState(digest != null, path);
return createForNormalFile(digest, proxy, size);
@@ -289,8 +290,8 @@
* handle getting the digest using the Path and size values.
*/
public static FileArtifactValue createForNormalFileUsingPath(
- Path path, long size, SyscallCache syscallCache) throws IOException {
- return create(path, /*isFile=*/ true, size, /*proxy=*/ null, /*digest=*/ null, syscallCache);
+ Path path, long size, XattrProvider xattrProvider) throws IOException {
+ return create(path, /*isFile=*/ true, size, /*proxy=*/ null, /*digest=*/ null, xattrProvider);
}
public static FileArtifactValue createForDirectoryWithHash(byte[] digest) {
diff --git a/src/main/java/com/google/devtools/build/lib/actions/FileStateValue.java b/src/main/java/com/google/devtools/build/lib/actions/FileStateValue.java
index fd7dbca..7b19509 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/FileStateValue.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/FileStateValue.java
@@ -32,6 +32,7 @@
import com.google.devtools.build.lib.vfs.RootedPath;
import com.google.devtools.build.lib.vfs.Symlinks;
import com.google.devtools.build.lib.vfs.SyscallCache;
+import com.google.devtools.build.lib.vfs.XattrProvider;
import com.google.devtools.build.skyframe.SkyValue;
import java.io.IOException;
import java.util.Arrays;
@@ -112,7 +113,7 @@
RootedPath rootedPath,
FileStatusWithDigest statNoFollow,
boolean digestWillBeInjected,
- SyscallCache syscallCache,
+ XattrProvider xattrProvider,
@Nullable TimestampGranularityMonitor tsgm)
throws IOException {
Path path = rootedPath.asPath();
@@ -120,7 +121,7 @@
return statNoFollow.isSpecialFile()
? SpecialFileStateValue.fromStat(path.asFragment(), statNoFollow, tsgm)
: RegularFileStateValue.fromPath(
- path, statNoFollow, digestWillBeInjected, syscallCache, tsgm);
+ path, statNoFollow, digestWillBeInjected, xattrProvider, tsgm);
} else if (statNoFollow.isDirectory()) {
return DIRECTORY_FILE_STATE_NODE;
} else if (statNoFollow.isSymbolicLink()) {
@@ -223,7 +224,7 @@
Path path,
FileStatusWithDigest stat,
boolean digestWillBeInjected,
- SyscallCache syscallCache,
+ XattrProvider xattrProvider,
@Nullable TimestampGranularityMonitor tsgm)
throws InconsistentFilesystemException {
Preconditions.checkState(stat.isFile(), path);
@@ -232,7 +233,7 @@
// If the digest will be injected, we can skip calling getFastDigest, but we need to store a
// contents proxy because if the digest is injected but is not available from the
// filesystem, we will need the proxy to determine whether the file was modified.
- byte[] digest = digestWillBeInjected ? null : tryGetDigest(path, stat, syscallCache);
+ byte[] digest = digestWillBeInjected ? null : tryGetDigest(path, stat, xattrProvider);
if (digest == null) {
// Note that TimestampGranularityMonitor#notifyDependenceOnFileTime is a thread-safe
// method.
@@ -257,10 +258,10 @@
@Nullable
private static byte[] tryGetDigest(
- Path path, FileStatusWithDigest stat, SyscallCache syscallCache) throws IOException {
+ Path path, FileStatusWithDigest stat, XattrProvider xattrProvider) throws IOException {
try {
byte[] digest = stat.getDigest();
- return digest != null ? digest : syscallCache.getFastDigest(path);
+ return digest != null ? digest : xattrProvider.getFastDigest(path);
} catch (IOException ioe) {
if (!path.isReadable()) {
return null;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/ResolvedEvent.java b/src/main/java/com/google/devtools/build/lib/bazel/ResolvedEvent.java
index af12b47..087f8e5 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/ResolvedEvent.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/ResolvedEvent.java
@@ -15,7 +15,7 @@
package com.google.devtools.build.lib.bazel;
import com.google.devtools.build.lib.events.ExtendedEventHandler;
-import com.google.devtools.build.lib.vfs.SyscallCache;
+import com.google.devtools.build.lib.vfs.XattrProvider;
/** Interface for events reporting information to be added to a resolved file. */
public interface ResolvedEvent extends ExtendedEventHandler.ProgressLike {
@@ -23,5 +23,5 @@
String getName();
/** The entry for the list of resolved Information. */
- Object getResolvedInformation(SyscallCache syscallCache);
+ Object getResolvedInformation(XattrProvider xattrProvider);
}
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/SpawnLogModule.java b/src/main/java/com/google/devtools/build/lib/bazel/SpawnLogModule.java
index 030ea2d..dc7d1f5 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/SpawnLogModule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/SpawnLogModule.java
@@ -120,7 +120,7 @@
env.getExecRoot(),
outStream,
env.getOptions().getOptions(RemoteOptions.class),
- env.getSyscallCache());
+ env.getXattrProvider());
}
@Override
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/commands/SyncCommand.java b/src/main/java/com/google/devtools/build/lib/bazel/commands/SyncCommand.java
index e20308f..2f4ed59 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/commands/SyncCommand.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/commands/SyncCommand.java
@@ -52,7 +52,7 @@
import com.google.devtools.build.lib.util.ExitCode;
import com.google.devtools.build.lib.util.InterruptedFailureDetails;
import com.google.devtools.build.lib.vfs.RootedPath;
-import com.google.devtools.build.lib.vfs.SyscallCache;
+import com.google.devtools.build.lib.vfs.XattrProvider;
import com.google.devtools.build.skyframe.EvaluationContext;
import com.google.devtools.build.skyframe.EvaluationResult;
import com.google.devtools.build.skyframe.SkyKey;
@@ -264,7 +264,7 @@
}
@Override
- public Object getResolvedInformation(SyscallCache syscallCache) {
+ public Object getResolvedInformation(XattrProvider xattrProvider) {
return ImmutableMap.<String, Object>builder()
.put(ResolvedHashesFunction.ORIGINAL_RULE_CLASS, "bind")
.put(
@@ -296,7 +296,7 @@
}
@Override
- public Object getResolvedInformation(SyscallCache syscallCache) {
+ public Object getResolvedInformation(XattrProvider xattrProvider) {
return ImmutableMap.<String, Object>builder()
.put(ResolvedHashesFunction.ORIGINAL_RULE_CLASS, ruleName)
.put(
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/LocalConfigPlatformFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/LocalConfigPlatformFunction.java
index fef65ec..f06530f 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/LocalConfigPlatformFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/LocalConfigPlatformFunction.java
@@ -26,7 +26,7 @@
import com.google.devtools.build.lib.util.CPU;
import com.google.devtools.build.lib.util.OS;
import com.google.devtools.build.lib.vfs.Path;
-import com.google.devtools.build.lib.vfs.SyscallCache;
+import com.google.devtools.build.lib.vfs.XattrProvider;
import com.google.devtools.build.skyframe.SkyFunction.Environment;
import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
import com.google.devtools.build.skyframe.SkyKey;
@@ -86,7 +86,7 @@
}
@Override
- public Object getResolvedInformation(SyscallCache syscallCache) {
+ public Object getResolvedInformation(XattrProvider xattrProvider) {
String repr = String.format("local_config_platform(name = '%s')", name);
return ImmutableMap.<String, Object>builder()
.put(ResolvedHashesFunction.ORIGINAL_RULE_CLASS, LocalConfigPlatformRule.NAME)
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryResolvedEvent.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryResolvedEvent.java
index 20005c3..5fe79e7 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryResolvedEvent.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryResolvedEvent.java
@@ -30,7 +30,7 @@
import com.google.devtools.build.lib.packages.StructImpl;
import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.build.lib.vfs.Path;
-import com.google.devtools.build.lib.vfs.SyscallCache;
+import com.google.devtools.build.lib.vfs.XattrProvider;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@@ -165,13 +165,13 @@
* Ensure that the {@code resolvedInformation} and the {@code directoryDigest} fields are
* initialized properly. Does nothing, if the values are computed already.
*/
- private synchronized void finalizeResolvedInformation(SyscallCache syscallCache) {
+ private synchronized void finalizeResolvedInformation(XattrProvider xattrProvider) {
if (resolvedInformation != null) {
return;
}
String digest = "[unavailable]";
try {
- digest = outputDirectory.getDirectoryDigest(syscallCache);
+ digest = outputDirectory.getDirectoryDigest(xattrProvider);
repositoryBuilder.put(OUTPUT_TREE_HASH, digest);
} catch (IOException e) {
// Digest not available, but we still have to report that a repository rule
@@ -191,8 +191,8 @@
* Returns the entry for the given rule invocation in a format suitable for WORKSPACE.resolved.
*/
@Override
- public Object getResolvedInformation(SyscallCache syscallCache) {
- finalizeResolvedInformation(syscallCache);
+ public Object getResolvedInformation(XattrProvider xattrProvider) {
+ finalizeResolvedInformation(xattrProvider);
return resolvedInformation;
}
@@ -202,8 +202,8 @@
return name;
}
- public String getDirectoryDigest(SyscallCache syscallCache) {
- finalizeResolvedInformation(syscallCache);
+ public String getDirectoryDigest(XattrProvider xattrProvider) {
+ finalizeResolvedInformation(xattrProvider);
return directoryDigest;
}
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryResolvedModule.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryResolvedModule.java
index 5f17822..33469c7 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryResolvedModule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryResolvedModule.java
@@ -24,7 +24,7 @@
import com.google.devtools.build.lib.runtime.BlazeModule;
import com.google.devtools.build.lib.runtime.Command;
import com.google.devtools.build.lib.runtime.CommandEnvironment;
-import com.google.devtools.build.lib.vfs.SyscallCache;
+import com.google.devtools.build.lib.vfs.XattrProvider;
import com.google.devtools.common.options.OptionsBase;
import java.io.File;
import java.io.IOException;
@@ -42,7 +42,7 @@
private Map<String, Object> resolvedValues;
private String resolvedFile;
private ImmutableList<String> orderedNames;
- private SyscallCache syscallCache;
+ private XattrProvider xattrProvider;
@Override
public Iterable<Class<? extends OptionsBase>> getCommandOptions(Command command) {
@@ -63,7 +63,7 @@
} else {
this.resolvedFile = null;
}
- this.syscallCache = env.getSyscallCache();
+ this.xattrProvider = env.getXattrProvider();
}
@Override
@@ -100,7 +100,7 @@
@Subscribe
public void resolved(ResolvedEvent event) {
if (resolvedValues != null) {
- resolvedValues.put(event.getName(), event.getResolvedInformation(syscallCache));
+ resolvedValues.put(event.getName(), event.getResolvedInformation(xattrProvider));
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkRepositoryFunction.java
index 3d151b6..22fa001 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkRepositoryFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkRepositoryFunction.java
@@ -14,7 +14,8 @@
package com.google.devtools.build.lib.bazel.repository.starlark;
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
@@ -82,7 +83,7 @@
}
public void setSyscallCache(SyscallCache syscallCache) {
- this.syscallCache = syscallCache;
+ this.syscallCache = checkNotNull(syscallCache);
}
static String describeSemantics(StarlarkSemantics semantics) {
@@ -138,8 +139,7 @@
if (env.valuesMissing()) {
return null;
}
- Map<String, String> resolvedHashes =
- Preconditions.checkNotNull(resolvedHashesValue).getHashes();
+ Map<String, String> resolvedHashes = checkNotNull(resolvedHashesValue).getHashes();
PathPackageLocator packageLocator = PrecomputedValue.PATH_PACKAGE_LOCATOR.get(env);
if (env.valuesMissing()) {
@@ -151,8 +151,7 @@
if (env.valuesMissing()) {
return null;
}
- ImmutableSet<PathFragment> ignoredPatterns =
- Preconditions.checkNotNull(ignoredPackagesValue).getPatterns();
+ ImmutableSet<PathFragment> ignoredPatterns = checkNotNull(ignoredPackagesValue).getPatterns();
try (Mutability mu = Mutability.create("Starlark repository")) {
StarlarkThread thread = new StarlarkThread(mu, starlarkSemantics);
diff --git a/src/main/java/com/google/devtools/build/lib/exec/RunfilesTreeUpdater.java b/src/main/java/com/google/devtools/build/lib/exec/RunfilesTreeUpdater.java
index 57bdd64..b1dd574 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/RunfilesTreeUpdater.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/RunfilesTreeUpdater.java
@@ -24,7 +24,7 @@
import com.google.devtools.build.lib.vfs.DigestUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
-import com.google.devtools.build.lib.vfs.SyscallCache;
+import com.google.devtools.build.lib.vfs.XattrProvider;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
@@ -68,7 +68,7 @@
ImmutableMap<String, String> env,
OutErr outErr,
boolean enableRunfiles,
- SyscallCache syscallCache)
+ XattrProvider xattrProvider)
throws IOException, ExecException, InterruptedException {
Path runfilesDirPath = execRoot.getRelative(runfilesDir);
Path inputManifest = RunfilesSupport.inputManifestPath(runfilesDirPath);
@@ -84,9 +84,9 @@
// an up-to-date check.
if (!outputManifest.isSymbolicLink()
&& Arrays.equals(
- DigestUtils.getDigestWithManualFallbackWhenSizeUnknown(outputManifest, syscallCache),
+ DigestUtils.getDigestWithManualFallbackWhenSizeUnknown(outputManifest, xattrProvider),
DigestUtils.getDigestWithManualFallbackWhenSizeUnknown(
- inputManifest, syscallCache))) {
+ inputManifest, xattrProvider))) {
return;
}
} catch (IOException e) {
@@ -135,7 +135,7 @@
BinTools binTools,
ImmutableMap<String, String> env,
OutErr outErr,
- SyscallCache syscallCache)
+ XattrProvider xattrProvider)
throws ExecException, IOException, InterruptedException {
for (Map.Entry<PathFragment, Map<PathFragment, Artifact>> runfiles :
runfilesSupplier.getMappings().entrySet()) {
@@ -159,7 +159,7 @@
env,
outErr,
runfilesSupplier.isRunfileLinksEnabled(runfilesDir),
- syscallCache);
+ xattrProvider);
}
} finally {
decrementRefcnt(runfilesDir);
diff --git a/src/main/java/com/google/devtools/build/lib/exec/SingleBuildFileCache.java b/src/main/java/com/google/devtools/build/lib/exec/SingleBuildFileCache.java
index cc4fda2..e7542a1 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/SingleBuildFileCache.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/SingleBuildFileCache.java
@@ -23,7 +23,7 @@
import com.google.devtools.build.lib.vfs.FileSystem;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.Symlinks;
-import com.google.devtools.build.lib.vfs.SyscallCache;
+import com.google.devtools.build.lib.vfs.XattrProvider;
import java.io.IOException;
import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;
@@ -47,10 +47,10 @@
// unlikely that this default will adversely affect memory in most cases.
.initialCapacity(10000)
.build();
- private final SyscallCache syscallCache;
+ private final XattrProvider xattrProvider;
- public SingleBuildFileCache(String cwd, FileSystem fs, SyscallCache syscallCache) {
- this.syscallCache = syscallCache;
+ public SingleBuildFileCache(String cwd, FileSystem fs, XattrProvider xattrProvider) {
+ this.xattrProvider = xattrProvider;
this.execRoot = fs.getPath(cwd);
}
@@ -68,7 +68,7 @@
path,
// TODO(b/199940216): should we use syscallCache here since caching anyway?
path.stat(Symlinks.FOLLOW),
- syscallCache);
+ xattrProvider);
} catch (IOException e) {
return new ActionInputMetadata(input, e);
}
diff --git a/src/main/java/com/google/devtools/build/lib/exec/SpawnLogContext.java b/src/main/java/com/google/devtools/build/lib/exec/SpawnLogContext.java
index 1ca1e83..b1e8c64 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/SpawnLogContext.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/SpawnLogContext.java
@@ -38,7 +38,7 @@
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.Symlinks;
-import com.google.devtools.build.lib.vfs.SyscallCache;
+import com.google.devtools.build.lib.vfs.XattrProvider;
import com.google.protobuf.util.Durations;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -63,17 +63,17 @@
private final Path execRoot;
private final MessageOutputStream executionLog;
@Nullable private final RemoteOptions remoteOptions;
- private final SyscallCache syscallCache;
+ private final XattrProvider xattrProvider;
public SpawnLogContext(
Path execRoot,
MessageOutputStream executionLog,
@Nullable RemoteOptions remoteOptions,
- SyscallCache syscallCache) {
+ XattrProvider xattrProvider) {
this.execRoot = execRoot;
this.executionLog = executionLog;
this.remoteOptions = remoteOptions;
- this.syscallCache = syscallCache;
+ this.xattrProvider = xattrProvider;
}
/** Log the executed spawn to the output stream. */
@@ -105,7 +105,7 @@
if (inputPath.isDirectory()) {
listDirectoryContents(inputPath, builder::addInputs, metadataProvider);
} else {
- Digest digest = computeDigest(input, null, metadataProvider, syscallCache);
+ Digest digest = computeDigest(input, null, metadataProvider, xattrProvider);
builder.addInputsBuilder().setPath(input.getExecPathString()).setDigest(digest);
}
}
@@ -127,7 +127,7 @@
outputBuilder.setPath(path.relativeTo(execRoot).toString());
try {
outputBuilder.setDigest(
- computeDigest(e.getValue(), path, metadataProvider, syscallCache));
+ computeDigest(e.getValue(), path, metadataProvider, xattrProvider));
} catch (IOException ex) {
logger.atWarning().withCause(ex).log("Error computing spawn event output properties");
}
@@ -198,7 +198,7 @@
addFile.accept(
File.newBuilder()
.setPath(child.relativeTo(execRoot).toString())
- .setDigest(computeDigest(null, child, metadataProvider, syscallCache))
+ .setDigest(computeDigest(null, child, metadataProvider, xattrProvider))
.build());
}
}
@@ -215,7 +215,7 @@
@Nullable ActionInput input,
@Nullable Path path,
MetadataProvider metadataProvider,
- SyscallCache syscallCache)
+ XattrProvider xattrProvider)
throws IOException {
Preconditions.checkArgument(input != null || path != null);
DigestHashFunction hashFunction = execRoot.getFileSystem().getDigestFunction();
@@ -254,7 +254,7 @@
return digest
.setHash(
HashCode.fromBytes(
- DigestUtils.getDigestWithManualFallback(path, fileSize, syscallCache))
+ DigestUtils.getDigestWithManualFallback(path, fileSize, xattrProvider))
.toString())
.setSizeBytes(fileSize)
.build();
diff --git a/src/main/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunner.java
index 7f6a168..cf13e80 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunner.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunner.java
@@ -59,7 +59,7 @@
import com.google.devtools.build.lib.util.OS;
import com.google.devtools.build.lib.util.io.FileOutErr;
import com.google.devtools.build.lib.vfs.Path;
-import com.google.devtools.build.lib.vfs.SyscallCache;
+import com.google.devtools.build.lib.vfs.XattrProvider;
import com.google.errorprone.annotations.FormatMethod;
import com.google.errorprone.annotations.FormatString;
import java.io.File;
@@ -92,7 +92,7 @@
private final String hostName;
private final LocalExecutionOptions localExecutionOptions;
- private final SyscallCache syscallCache;
+ private final XattrProvider xattrProvider;
@Nullable private final ProcessWrapper processWrapper;
@@ -108,12 +108,12 @@
LocalEnvProvider localEnvProvider,
BinTools binTools,
ProcessWrapper processWrapper,
- SyscallCache syscallCache,
+ XattrProvider xattrProvider,
RunfilesTreeUpdater runfilesTreeUpdater) {
this.execRoot = execRoot;
this.processWrapper = processWrapper;
this.localExecutionOptions = Preconditions.checkNotNull(localExecutionOptions);
- this.syscallCache = syscallCache;
+ this.xattrProvider = xattrProvider;
this.hostName = NetUtil.getCachedShortHostName();
this.resourceManager = resourceManager;
this.localEnvProvider = localEnvProvider;
@@ -139,7 +139,7 @@
binTools,
spawn.getEnvironment(),
context.getFileOutErr(),
- syscallCache);
+ xattrProvider);
spawnMetrics.addSetupTime(setupTimeStopwatch.elapsed());
try (SilentCloseable c =
diff --git a/src/main/java/com/google/devtools/build/lib/includescanning/IncludeParser.java b/src/main/java/com/google/devtools/build/lib/includescanning/IncludeParser.java
index 1ae0c40..6eaf4a7 100644
--- a/src/main/java/com/google/devtools/build/lib/includescanning/IncludeParser.java
+++ b/src/main/java/com/google/devtools/build/lib/includescanning/IncludeParser.java
@@ -48,7 +48,6 @@
import com.google.devtools.build.lib.skyframe.GlobDescriptor;
import com.google.devtools.build.lib.skyframe.GlobValue;
import com.google.devtools.build.lib.skyframe.GlobValue.InvalidGlobPatternException;
-import com.google.devtools.build.lib.skyframe.PerBuildSyscallCache;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -189,8 +188,7 @@
private final ImmutableList<Rule> rules;
private final ArtifactFactory artifactFactory;
- private final SyscallCache syscallCache =
- PerBuildSyscallCache.newBuilder().setInitialCapacity(HINTS_CACHE_CONCURRENCY).build();
+ private final SyscallCache syscallCache;
private final LoadingCache<Artifact, ImmutableList<Artifact>> fileLevelHintsCache =
Caffeine.newBuilder()
@@ -202,7 +200,8 @@
*
* @param hintsRules the {@link HintsRules} parsed from INCLUDE_HINTS
*/
- Hints(HintsRules hintsRules, ArtifactFactory artifactFactory) {
+ Hints(HintsRules hintsRules, SyscallCache syscallCache, ArtifactFactory artifactFactory) {
+ this.syscallCache = syscallCache;
this.artifactFactory = artifactFactory;
this.rules = hintsRules.rules;
}
diff --git a/src/main/java/com/google/devtools/build/lib/includescanning/IncludeScanningModule.java b/src/main/java/com/google/devtools/build/lib/includescanning/IncludeScanningModule.java
index 96db5f3..83d5264 100644
--- a/src/main/java/com/google/devtools/build/lib/includescanning/IncludeScanningModule.java
+++ b/src/main/java/com/google/devtools/build/lib/includescanning/IncludeScanningModule.java
@@ -299,7 +299,9 @@
includeScannerSupplier.init(
new IncludeParser(
new IncludeParser.Hints(
- hintsRules, env.getSkyframeBuildView().getArtifactFactory())));
+ hintsRules,
+ env.getSyscallCache(),
+ env.getSkyframeBuildView().getArtifactFactory())));
}
@Override
diff --git a/src/main/java/com/google/devtools/build/lib/includescanning/SpawnIncludeScanner.java b/src/main/java/com/google/devtools/build/lib/includescanning/SpawnIncludeScanner.java
index fcc2acd..67e8676 100644
--- a/src/main/java/com/google/devtools/build/lib/includescanning/SpawnIncludeScanner.java
+++ b/src/main/java/com/google/devtools/build/lib/includescanning/SpawnIncludeScanner.java
@@ -125,7 +125,13 @@
if (remoteExtractionThreshold == 0 || (outputService != null && !file.isSourceArtifact())) {
return true;
}
- FileStatus status = syscallCache.statIfFound(file.getPath(), Symlinks.FOLLOW);
+ Path path = file.getPath();
+ // Don't use syscallCache for a derived artifact: it might have been statted before it was
+ // regenerated.
+ FileStatus status =
+ file.isSourceArtifact()
+ ? syscallCache.statIfFound(path, Symlinks.FOLLOW)
+ : path.statIfFound(Symlinks.FOLLOW);
return status == null || status.getSize() > remoteExtractionThreshold;
}
diff --git a/src/main/java/com/google/devtools/build/lib/remote/ByteStreamBuildEventArtifactUploader.java b/src/main/java/com/google/devtools/build/lib/remote/ByteStreamBuildEventArtifactUploader.java
index c1cfc69..76e755b 100644
--- a/src/main/java/com/google/devtools/build/lib/remote/ByteStreamBuildEventArtifactUploader.java
+++ b/src/main/java/com/google/devtools/build/lib/remote/ByteStreamBuildEventArtifactUploader.java
@@ -33,7 +33,7 @@
import com.google.devtools.build.lib.remote.util.DigestUtil;
import com.google.devtools.build.lib.remote.util.TracingMetadataUtils;
import com.google.devtools.build.lib.vfs.Path;
-import com.google.devtools.build.lib.vfs.SyscallCache;
+import com.google.devtools.build.lib.vfs.XattrProvider;
import io.netty.util.AbstractReferenceCounted;
import io.netty.util.ReferenceCounted;
import io.reactivex.rxjava3.core.Flowable;
@@ -69,7 +69,7 @@
private final Set<Path> omittedFiles = Sets.newConcurrentHashSet();
private final Set<Path> omittedTreeRoots = Sets.newConcurrentHashSet();
- private final SyscallCache syscallCache;
+ private final XattrProvider xattrProvider;
ByteStreamBuildEventArtifactUploader(
Executor executor,
@@ -79,7 +79,7 @@
String remoteServerInstanceName,
String buildRequestId,
String commandId,
- SyscallCache syscallCache) {
+ XattrProvider xattrProvider) {
this.executor = executor;
this.reporter = reporter;
this.verboseFailures = verboseFailures;
@@ -88,7 +88,7 @@
this.commandId = commandId;
this.remoteServerInstanceName = remoteServerInstanceName;
this.scheduler = Schedulers.from(executor);
- this.syscallCache = syscallCache;
+ this.xattrProvider = xattrProvider;
}
public void omitFile(Path file) {
@@ -155,7 +155,7 @@
}
}
- DigestUtil digestUtil = new DigestUtil(syscallCache, file.getFileSystem().getDigestFunction());
+ DigestUtil digestUtil = new DigestUtil(xattrProvider, file.getFileSystem().getDigestFunction());
Digest digest = digestUtil.compute(file);
return new PathMetadata(file, digest, /* directory= */ false, isRemoteFile(file));
}
diff --git a/src/main/java/com/google/devtools/build/lib/remote/ByteStreamBuildEventArtifactUploaderFactory.java b/src/main/java/com/google/devtools/build/lib/remote/ByteStreamBuildEventArtifactUploaderFactory.java
index 5ff3cfa..3eec1ee 100644
--- a/src/main/java/com/google/devtools/build/lib/remote/ByteStreamBuildEventArtifactUploaderFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/remote/ByteStreamBuildEventArtifactUploaderFactory.java
@@ -64,7 +64,7 @@
remoteServerInstanceName,
buildRequestId,
commandId,
- env.getSyscallCache());
+ env.getXattrProvider());
return uploader;
}
diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java
index 3bf61b3..55c6ba1 100644
--- a/src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java
+++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java
@@ -260,7 +260,7 @@
AuthAndTLSOptions authAndTlsOptions = env.getOptions().getOptions(AuthAndTLSOptions.class);
DigestHashFunction hashFn = env.getRuntime().getFileSystem().getDigestFunction();
- DigestUtil digestUtil = new DigestUtil(env.getSyscallCache(), hashFn);
+ DigestUtil digestUtil = new DigestUtil(env.getXattrProvider(), hashFn);
boolean verboseFailures = false;
ExecutionOptions executionOptions = env.getOptions().getOptions(ExecutionOptions.class);
diff --git a/src/main/java/com/google/devtools/build/lib/remote/util/DigestUtil.java b/src/main/java/com/google/devtools/build/lib/remote/util/DigestUtil.java
index 59d5faf..16055f1 100644
--- a/src/main/java/com/google/devtools/build/lib/remote/util/DigestUtil.java
+++ b/src/main/java/com/google/devtools/build/lib/remote/util/DigestUtil.java
@@ -25,7 +25,7 @@
import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.DigestUtils;
import com.google.devtools.build.lib.vfs.Path;
-import com.google.devtools.build.lib.vfs.SyscallCache;
+import com.google.devtools.build.lib.vfs.XattrProvider;
import com.google.protobuf.Message;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -33,11 +33,11 @@
/** Utility methods to work with {@link Digest}. */
public class DigestUtil {
- private final SyscallCache syscallCache;
+ private final XattrProvider xattrProvider;
private final DigestHashFunction hashFn;
- public DigestUtil(SyscallCache syscallCache, DigestHashFunction hashFn) {
- this.syscallCache = syscallCache;
+ public DigestUtil(XattrProvider xattrProvider, DigestHashFunction hashFn) {
+ this.xattrProvider = xattrProvider;
this.hashFn = hashFn;
}
@@ -63,7 +63,7 @@
public Digest compute(Path file, long fileSize) throws IOException {
return buildDigest(
- DigestUtils.getDigestWithManualFallback(file, fileSize, syscallCache), fileSize);
+ DigestUtils.getDigestWithManualFallback(file, fileSize, xattrProvider), fileSize);
}
public Digest compute(VirtualActionInput input) throws IOException {
diff --git a/src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java
index 79e623f..4709d5c 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java
@@ -21,7 +21,7 @@
import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
-import com.google.devtools.build.lib.vfs.SyscallCache;
+import com.google.devtools.build.lib.vfs.XattrProvider;
import com.google.devtools.build.skyframe.SkyFunction.Environment;
import com.google.devtools.build.skyframe.SkyKey;
import java.util.Map;
@@ -91,7 +91,7 @@
}
@Override
- public Object getResolvedInformation(SyscallCache syscallCache) {
+ public Object getResolvedInformation(XattrProvider xattrProvider) {
return ImmutableMap.<String, Object>builder()
.put(ResolvedHashesFunction.ORIGINAL_RULE_CLASS, "local_repository")
.put(
diff --git a/src/main/java/com/google/devtools/build/lib/rules/repository/NewLocalRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/rules/repository/NewLocalRepositoryFunction.java
index c119225..4c4347b 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/repository/NewLocalRepositoryFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/repository/NewLocalRepositoryFunction.java
@@ -28,7 +28,7 @@
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.Root;
import com.google.devtools.build.lib.vfs.RootedPath;
-import com.google.devtools.build.lib.vfs.SyscallCache;
+import com.google.devtools.build.lib.vfs.XattrProvider;
import com.google.devtools.build.skyframe.SkyFunction.Environment;
import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
import com.google.devtools.build.skyframe.SkyKey;
@@ -205,7 +205,7 @@
}
@Override
- public Object getResolvedInformation(SyscallCache syscallCache) {
+ public Object getResolvedInformation(XattrProvider xattrProvider) {
return ImmutableMap.<String, Object>builder()
.put(ResolvedHashesFunction.ORIGINAL_RULE_CLASS, "new_local_repository")
.put(ResolvedHashesFunction.ORIGINAL_ATTRIBUTES, orig)
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java b/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java
index 1781a6f..08cd449 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java
@@ -52,6 +52,7 @@
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.SyscallCache;
+import com.google.devtools.build.lib.vfs.XattrProvider;
import com.google.devtools.common.options.OptionsParsingResult;
import com.google.devtools.common.options.OptionsProvider;
import com.google.protobuf.Any;
@@ -799,10 +800,15 @@
}
}
+ /** Use {@link #getXattrProvider} when possible: see documentation of {@link SyscallCache}. */
public SyscallCache getSyscallCache() {
return syscallCache;
}
+ public XattrProvider getXattrProvider() {
+ return getSyscallCache();
+ }
+
/**
* Returns the {@linkplain
* com.google.devtools.build.lib.server.CommandProtos.RunRequest#getCommandExtensions extensions}
diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/SandboxModule.java b/src/main/java/com/google/devtools/build/lib/sandbox/SandboxModule.java
index f5ecba2..16055fa 100644
--- a/src/main/java/com/google/devtools/build/lib/sandbox/SandboxModule.java
+++ b/src/main/java/com/google/devtools/build/lib/sandbox/SandboxModule.java
@@ -451,8 +451,8 @@
LocalEnvProvider.forCurrentOs(env.getClientEnv()),
env.getBlazeWorkspace().getBinTools(),
ProcessWrapper.fromCommandEnvironment(env),
+ env.getXattrProvider(),
// TODO(buchgr): Replace singleton by a command-scoped RunfilesTreeUpdater
- env.getSyscallCache(),
RunfilesTreeUpdater.INSTANCE);
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java
index 669cadf..0ed234d 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java
@@ -733,7 +733,7 @@
action.discoversInputs(),
skyframeActionExecutor.useArchivedTreeArtifacts(action),
action.getOutputs(),
- skyframeActionExecutor.getSyscallCache(),
+ skyframeActionExecutor.getXattrProvider(),
tsgm.get(),
pathResolver,
skyframeActionExecutor.getExecRoot().asFragment(),
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ActionMetadataHandler.java b/src/main/java/com/google/devtools/build/lib/skyframe/ActionMetadataHandler.java
index 9086798..018fea4 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ActionMetadataHandler.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ActionMetadataHandler.java
@@ -49,7 +49,7 @@
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.RootedPath;
import com.google.devtools.build.lib.vfs.Symlinks;
-import com.google.devtools.build.lib.vfs.SyscallCache;
+import com.google.devtools.build.lib.vfs.XattrProvider;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
@@ -92,7 +92,7 @@
boolean forInputDiscovery,
boolean archivedTreeArtifactsEnabled,
ImmutableSet<Artifact> outputs,
- SyscallCache syscallCache,
+ XattrProvider xattrProvider,
TimestampGranularityMonitor tsgm,
ArtifactPathResolver artifactPathResolver,
PathFragment execRoot,
@@ -103,7 +103,7 @@
forInputDiscovery,
archivedTreeArtifactsEnabled,
outputs,
- syscallCache,
+ xattrProvider,
tsgm,
artifactPathResolver,
execRoot,
@@ -120,7 +120,7 @@
private final Set<Artifact> omittedOutputs = Sets.newConcurrentHashSet();
private final ImmutableSet<Artifact> outputs;
- private final SyscallCache syscallCache;
+ private final XattrProvider xattrProvider;
private final TimestampGranularityMonitor tsgm;
private final ArtifactPathResolver artifactPathResolver;
private final PathFragment execRoot;
@@ -134,7 +134,7 @@
boolean forInputDiscovery,
boolean archivedTreeArtifactsEnabled,
ImmutableSet<Artifact> outputs,
- SyscallCache syscallCache,
+ XattrProvider xattrProvider,
TimestampGranularityMonitor tsgm,
ArtifactPathResolver artifactPathResolver,
PathFragment execRoot,
@@ -145,7 +145,7 @@
this.forInputDiscovery = forInputDiscovery;
this.archivedTreeArtifactsEnabled = archivedTreeArtifactsEnabled;
this.outputs = checkNotNull(outputs);
- this.syscallCache = syscallCache;
+ this.xattrProvider = xattrProvider;
this.tsgm = checkNotNull(tsgm);
this.artifactPathResolver = checkNotNull(artifactPathResolver);
this.execRoot = checkNotNull(execRoot);
@@ -171,7 +171,7 @@
/*forInputDiscovery=*/ false,
archivedTreeArtifactsEnabled,
outputs,
- syscallCache,
+ xattrProvider,
tsgm,
artifactPathResolver,
execRoot,
@@ -510,7 +510,7 @@
artifactPathResolver,
statNoFollow,
injectedDigest != null,
- syscallCache,
+ xattrProvider,
// Prevent constant metadata artifacts from notifying the timestamp granularity monitor
// and potentially delaying the build for no reason.
artifact.isConstantMetadata() ? null : tsgm);
@@ -577,7 +577,7 @@
static FileArtifactValue fileArtifactValueFromArtifact(
Artifact artifact,
@Nullable FileStatusWithDigest statNoFollow,
- SyscallCache syscallCache,
+ XattrProvider xattrProvider,
@Nullable TimestampGranularityMonitor tsgm)
throws IOException {
return fileArtifactValueFromArtifact(
@@ -585,7 +585,7 @@
ArtifactPathResolver.IDENTITY,
statNoFollow,
/*digestWillBeInjected=*/ false,
- syscallCache,
+ xattrProvider,
tsgm);
}
@@ -594,7 +594,7 @@
ArtifactPathResolver artifactPathResolver,
@Nullable FileStatusWithDigest statNoFollow,
boolean digestWillBeInjected,
- SyscallCache syscallCache,
+ XattrProvider xattrProvider,
@Nullable TimestampGranularityMonitor tsgm)
throws IOException {
checkState(!artifact.isTreeArtifact() && !artifact.isMiddlemanArtifact(), artifact);
@@ -615,7 +615,7 @@
if (statNoFollow == null || !statNoFollow.isSymbolicLink()) {
return fileArtifactValueFromStat(
- rootedPathNoFollow, statNoFollow, digestWillBeInjected, syscallCache, tsgm);
+ rootedPathNoFollow, statNoFollow, digestWillBeInjected, xattrProvider, tsgm);
}
if (artifact.isSymlink()) {
@@ -640,14 +640,14 @@
FileStatus realStat = realRootedPath.asPath().statIfFound(Symlinks.NOFOLLOW);
FileStatusWithDigest realStatWithDigest = FileStatusWithDigestAdapter.maybeAdapt(realStat);
return fileArtifactValueFromStat(
- realRootedPath, realStatWithDigest, digestWillBeInjected, syscallCache, tsgm);
+ realRootedPath, realStatWithDigest, digestWillBeInjected, xattrProvider, tsgm);
}
private static FileArtifactValue fileArtifactValueFromStat(
RootedPath rootedPath,
FileStatusWithDigest stat,
boolean digestWillBeInjected,
- SyscallCache syscallCache,
+ XattrProvider xattrProvider,
@Nullable TimestampGranularityMonitor tsgm)
throws IOException {
if (stat == null) {
@@ -656,7 +656,7 @@
FileStateValue fileStateValue =
FileStateValue.createWithStatNoFollow(
- rootedPath, stat, digestWillBeInjected, syscallCache, tsgm);
+ rootedPath, stat, digestWillBeInjected, xattrProvider, tsgm);
return stat.isDirectory()
? FileArtifactValue.createForDirectoryWithMtime(stat.getLastModifiedTime())
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java
index b8d262a..8bdf9a0 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java
@@ -47,7 +47,7 @@
import com.google.devtools.build.lib.util.Fingerprint;
import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.build.lib.vfs.RootedPath;
-import com.google.devtools.build.lib.vfs.SyscallCache;
+import com.google.devtools.build.lib.vfs.XattrProvider;
import com.google.devtools.build.skyframe.SkyFunction;
import com.google.devtools.build.skyframe.SkyFunctionException;
import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
@@ -69,7 +69,7 @@
class ArtifactFunction implements SkyFunction {
private final Supplier<Boolean> mkdirForTreeArtifacts;
private final MetadataConsumerForMetrics sourceArtifactsSeen;
- private final SyscallCache syscallCache;
+ private final XattrProvider xattrProvider;
static final class MissingArtifactValue implements SkyValue {
private final DetailedExitCode detailedExitCode;
@@ -96,10 +96,10 @@
public ArtifactFunction(
Supplier<Boolean> mkdirForTreeArtifacts,
MetadataConsumerForMetrics sourceArtifactsSeen,
- SyscallCache syscallCache) {
+ XattrProvider xattrProvider) {
this.mkdirForTreeArtifacts = mkdirForTreeArtifacts;
this.sourceArtifactsSeen = sourceArtifactsSeen;
- this.syscallCache = syscallCache;
+ this.xattrProvider = xattrProvider;
}
@Override
@@ -279,7 +279,7 @@
if (!fileValue.isDirectory() || !TrackSourceDirectoriesFlag.trackSourceDirectories()) {
FileArtifactValue metadata;
try {
- metadata = FileArtifactValue.createForSourceArtifact(artifact, fileValue, syscallCache);
+ metadata = FileArtifactValue.createForSourceArtifact(artifact, fileValue, xattrProvider);
} catch (IOException e) {
throw new ArtifactFunctionException(
SourceArtifactException.create(artifact, e), Transience.TRANSIENT);
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java
index 5b408c3..ed943ef 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java
@@ -54,6 +54,7 @@
import com.google.devtools.build.lib.vfs.RootedPath;
import com.google.devtools.build.lib.vfs.Symlinks;
import com.google.devtools.build.lib.vfs.SyscallCache;
+import com.google.devtools.build.lib.vfs.XattrProvider;
import com.google.devtools.build.skyframe.SkyFunction;
import com.google.devtools.build.skyframe.SkyFunctionException;
import com.google.devtools.build.skyframe.SkyKey;
@@ -438,7 +439,7 @@
* @return transformed HasDigest value based on the digest field and object type.
*/
@VisibleForTesting
- static HasDigest withDigest(HasDigest fsVal, Path path, SyscallCache syscallCache)
+ static HasDigest withDigest(HasDigest fsVal, Path path, XattrProvider syscallCache)
throws IOException {
if (fsVal instanceof FileStateValue) {
FileStateValue fsv = (FileStateValue) fsVal;
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeActionExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeActionExecutor.java
index 3fb914d..bad4084 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeActionExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeActionExecutor.java
@@ -102,6 +102,7 @@
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.Root;
import com.google.devtools.build.lib.vfs.SyscallCache;
+import com.google.devtools.build.lib.vfs.XattrProvider;
import com.google.devtools.build.skyframe.SkyFunction.Environment;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.common.options.OptionsProvider;
@@ -317,7 +318,7 @@
return options.getOptions(BuildEventProtocolOptions.class).publishTargetSummary;
}
- SyscallCache getSyscallCache() {
+ XattrProvider getXattrProvider() {
return syscallCache;
}
diff --git a/src/main/java/com/google/devtools/build/lib/standalone/StandaloneModule.java b/src/main/java/com/google/devtools/build/lib/standalone/StandaloneModule.java
index 1fde342..61e38f5 100644
--- a/src/main/java/com/google/devtools/build/lib/standalone/StandaloneModule.java
+++ b/src/main/java/com/google/devtools/build/lib/standalone/StandaloneModule.java
@@ -82,7 +82,7 @@
LocalEnvProvider.forCurrentOs(env.getClientEnv()),
env.getBlazeWorkspace().getBinTools(),
ProcessWrapper.fromCommandEnvironment(env),
- env.getSyscallCache(),
+ env.getXattrProvider(),
// TODO(buchgr): Replace singleton by a command-scoped RunfilesTreeUpdater
RunfilesTreeUpdater.INSTANCE);
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/DigestUtils.java b/src/main/java/com/google/devtools/build/lib/vfs/DigestUtils.java
index 4308fa3..97f5ecd9 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/DigestUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/DigestUtils.java
@@ -157,8 +157,8 @@
* order to avoid excessive disk seeks.
*/
public static byte[] getDigestWithManualFallback(
- Path path, long fileSize, SyscallCache syscallCache) throws IOException {
- byte[] digest = syscallCache.getFastDigest(path);
+ Path path, long fileSize, XattrProvider xattrProvider) throws IOException {
+ byte[] digest = xattrProvider.getFastDigest(path);
return digest != null ? digest : manuallyComputeDigest(path, fileSize);
}
@@ -173,8 +173,8 @@
* @param path Path of the file.
*/
public static byte[] getDigestWithManualFallbackWhenSizeUnknown(
- Path path, SyscallCache syscallCache) throws IOException {
- return getDigestWithManualFallback(path, -1, syscallCache);
+ Path path, XattrProvider xattrProvider) throws IOException {
+ return getDigestWithManualFallback(path, -1, xattrProvider);
}
/**
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/Path.java b/src/main/java/com/google/devtools/build/lib/vfs/Path.java
index e7b9213..ff2008d 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/Path.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/Path.java
@@ -703,7 +703,7 @@
* @return a string representation of the bash of the directory
* @throws IOException if the digest could not be computed for any reason
*/
- public String getDirectoryDigest(SyscallCache syscallCache) throws IOException {
+ public String getDirectoryDigest(XattrProvider xattrProvider) throws IOException {
ImmutableList<String> entries =
ImmutableList.sortedCopyOf(fileSystem.getDirectoryEntries(asFragment()));
Hasher hasher = fileSystem.getDigestFunction().getHashFunction().newHasher();
@@ -718,9 +718,9 @@
hasher.putChar('-');
}
hasher.putBytes(
- DigestUtils.getDigestWithManualFallback(path, stat.getSize(), syscallCache));
+ DigestUtils.getDigestWithManualFallback(path, stat.getSize(), xattrProvider));
} else if (stat.isDirectory()) {
- hasher.putChar('d').putUnencodedChars(path.getDirectoryDigest(syscallCache));
+ hasher.putChar('d').putUnencodedChars(path.getDirectoryDigest(xattrProvider));
} else if (stat.isSymbolicLink()) {
PathFragment link = path.readSymbolicLink();
if (link.isAbsolute()) {
@@ -733,7 +733,7 @@
hasher.putChar('-');
}
hasher.putBytes(
- DigestUtils.getDigestWithManualFallbackWhenSizeUnknown(resolved, syscallCache));
+ DigestUtils.getDigestWithManualFallbackWhenSizeUnknown(resolved, xattrProvider));
} else {
// link to a non-file: include the link itself in the hash
hasher.putChar('l').putUnencodedChars(link.toString());
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/SyscallCache.java b/src/main/java/com/google/devtools/build/lib/vfs/SyscallCache.java
index f08216a5..016ddf3 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/SyscallCache.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/SyscallCache.java
@@ -24,8 +24,12 @@
* Centralized point to perform filesystem calls, to promote caching. Ideally all filesystem
* operations would be cached in Skyframe, but even then, implementations of this interface may do
* batch operations and prefetching to improve performance.
+ *
+ * <p>See the note in {@link XattrProvider} about caching in implementations. Do not call the
+ * methods in this interface on files that may change during this build, like outputs or external
+ * repository files. Calling these methods on source files is allowed.
*/
-public interface SyscallCache {
+public interface SyscallCache extends XattrProvider {
SyscallCache NO_CACHE =
new SyscallCache() {
@Override
@@ -62,18 +66,6 @@
@Nullable
DirentTypeWithSkip getType(Path path, Symlinks symlinks) throws IOException;
- /**
- * This and {@link #getxattr} exist for caches that may retrieve bulk data for a path
- * (stat+digest+xattrs) at once.
- */
- default byte[] getFastDigest(Path path) throws IOException {
- return path.getFastDigest();
- }
-
- default byte[] getxattr(Path path, String xattrName) throws IOException {
- return path.getxattr(xattrName);
- }
-
/** Called before each build. Implementations should flush their caches at that point. */
void clear();
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/XattrProvider.java b/src/main/java/com/google/devtools/build/lib/vfs/XattrProvider.java
new file mode 100644
index 0000000..525c1e2
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/vfs/XattrProvider.java
@@ -0,0 +1,37 @@
+// Copyright 2022 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.vfs;
+
+import java.io.IOException;
+
+/**
+ * Can perform xattrs on {@link Path} objects, including the common {@link Path#getFastDigest}. Some
+ * extensions to Bazel may allow this data to be retrieved in a different way than just accessing
+ * the xattr on the filesystem: they may do bulk filesystem operations for a path/directory at once.
+ *
+ * <p>Warning! these methods are called both *before* and *after* an action executes on its output
+ * files. Thus, implementations must not cache the value for output files or other files like those
+ * in external repositories that are generated during the build. An implementation is free to cache
+ * it for immutable source files for the duration of the build.
+ */
+public interface XattrProvider {
+ default byte[] getFastDigest(Path path) throws IOException {
+ return path.getFastDigest();
+ }
+
+ default byte[] getxattr(Path path, String xattrName) throws IOException {
+ return path.getxattr(xattrName);
+ }
+}
diff --git a/src/main/java/com/google/devtools/build/lib/worker/WorkerModule.java b/src/main/java/com/google/devtools/build/lib/worker/WorkerModule.java
index 837589a..2eeae45 100644
--- a/src/main/java/com/google/devtools/build/lib/worker/WorkerModule.java
+++ b/src/main/java/com/google/devtools/build/lib/worker/WorkerModule.java
@@ -161,7 +161,7 @@
env.getOptions().getOptions(WorkerOptions.class),
env.getEventBus(),
Runtime.getRuntime(),
- env.getSyscallCache());
+ env.getXattrProvider());
ExecutionOptions executionOptions =
checkNotNull(env.getOptions().getOptions(ExecutionOptions.class));
registryBuilder.registerStrategy(
diff --git a/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnRunner.java
index f0d77f5..839ea3c 100644
--- a/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnRunner.java
+++ b/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnRunner.java
@@ -63,7 +63,7 @@
import com.google.devtools.build.lib.util.io.FileOutErr;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
-import com.google.devtools.build.lib.vfs.SyscallCache;
+import com.google.devtools.build.lib.vfs.XattrProvider;
import com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest;
import com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse;
import com.google.protobuf.ByteString;
@@ -110,7 +110,7 @@
private final WorkerParser workerParser;
private final AtomicInteger requestIdCounter = new AtomicInteger(1);
private final Runtime runtime;
- private final SyscallCache syscallCache;
+ private final XattrProvider xattrProvider;
/** Mapping of worker ids to their metrics. */
private Map<Integer, WorkerMetric> workerIdToWorkerMetric = new ConcurrentHashMap<>();
@@ -127,7 +127,7 @@
WorkerOptions workerOptions,
EventBus eventBus,
Runtime runtime,
- SyscallCache syscallCache) {
+ XattrProvider xattrProvider) {
this.helpers = helpers;
this.execRoot = execRoot;
this.workers = Preconditions.checkNotNull(workers);
@@ -135,7 +135,7 @@
this.binTools = binTools;
this.resourceManager = resourceManager;
this.runfilesTreeUpdater = runfilesTreeUpdater;
- this.syscallCache = syscallCache;
+ this.xattrProvider = xattrProvider;
this.workerParser = new WorkerParser(execRoot, workerOptions, localEnvProvider, binTools);
this.workerOptions = workerOptions;
this.runtime = runtime;
@@ -193,7 +193,7 @@
binTools,
spawn.getEnvironment(),
context.getFileOutErr(),
- syscallCache);
+ xattrProvider);
MetadataProvider inputFileCache = context.getMetadataProvider();