From 8a53b0e51506d825d276ea7c9480190bd2287009 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 7 Dec 2022 12:11:01 -0800 Subject: [PATCH] Make references to syscall caches less confusing. `PerBuildSyscallCache` is renamed `DefaultSyscallCache`. It is server-scoped, not per-build scoped, although `clear()` is called between builds (this is now documented on `SyscallCache`). Variables named `perBuild` or `perCommand` are adjusted accordingly. PiperOrigin-RevId: 493672664 Change-Id: Ifa70d8c636fec4b9bc9e194691f865569de3ff2a --- .../java/com/google/devtools/build/lib/BUILD | 2 +- .../build/lib/runtime/BlazeWorkspace.java | 8 ++--- .../build/lib/runtime/WorkspaceBuilder.java | 28 +++++++---------- .../google/devtools/build/lib/skyframe/BUILD | 4 +-- ...allCache.java => DefaultSyscallCache.java} | 16 +++++----- .../DirectoryListingStateFunction.java | 2 +- .../skyframe/SequencedSkyframeExecutor.java | 24 +++++++-------- .../SequencedSkyframeExecutorFactory.java | 5 ++-- .../build/lib/skyframe/SkyframeExecutor.java | 30 +++++++++---------- .../lib/skyframe/SkyframeExecutorFactory.java | 2 +- .../packages/AbstractPackageLoader.java | 6 ++-- .../build/lib/skyframe/packages/BUILD | 2 +- .../devtools/build/lib/vfs/SyscallCache.java | 8 +++-- .../lib/analysis/util/AnalysisTestCase.java | 2 +- .../lib/analysis/util/BuildViewTestCase.java | 2 +- .../analysis/util/ConfigurationTestCase.java | 2 +- .../google/devtools/build/lib/buildtool/BUILD | 2 +- .../lib/buildtool/QueryIntegrationTest.java | 10 +++---- .../packages/util/PackageLoadingTestCase.java | 2 +- .../pkgcache/BuildFileModificationTest.java | 2 +- .../lib/pkgcache/IncrementalLoadingTest.java | 2 +- .../lib/pkgcache/LoadingPhaseRunnerTest.java | 2 +- .../lib/pkgcache/PackageLoadingTest.java | 2 +- .../query2/testutil/SkyframeQueryHelper.java | 2 +- .../google/devtools/build/lib/skyframe/BUILD | 2 +- ...temValueCheckerInferringAncestorsTest.java | 2 +- ...psOfPatternsFunctionSmartNegationTest.java | 2 +- 27 files changed, 86 insertions(+), 87 deletions(-) rename src/main/java/com/google/devtools/build/lib/skyframe/{PerBuildSyscallCache.java => DefaultSyscallCache.java} (94%) diff --git a/src/main/java/com/google/devtools/build/lib/BUILD b/src/main/java/com/google/devtools/build/lib/BUILD index 9b52063095ae47..e12af87157ab48 100644 --- a/src/main/java/com/google/devtools/build/lib/BUILD +++ b/src/main/java/com/google/devtools/build/lib/BUILD @@ -362,6 +362,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/skyframe:configuration_phase_started_event", "//src/main/java/com/google/devtools/build/lib/skyframe:configured_target_key", "//src/main/java/com/google/devtools/build/lib/skyframe:configured_target_progress_receiver", + "//src/main/java/com/google/devtools/build/lib/skyframe:default_syscall_cache", "//src/main/java/com/google/devtools/build/lib/skyframe:diff_awareness", "//src/main/java/com/google/devtools/build/lib/skyframe:execution_finished_event", "//src/main/java/com/google/devtools/build/lib/skyframe:incremental_package_roots", @@ -369,7 +370,6 @@ java_library( "//src/main/java/com/google/devtools/build/lib/skyframe:package_progress_receiver", "//src/main/java/com/google/devtools/build/lib/skyframe:package_roots_no_symlink_creation", "//src/main/java/com/google/devtools/build/lib/skyframe:package_value", - "//src/main/java/com/google/devtools/build/lib/skyframe:per_build_syscall_cache", "//src/main/java/com/google/devtools/build/lib/skyframe:precomputed_value", "//src/main/java/com/google/devtools/build/lib/skyframe:repository_mapping_value", "//src/main/java/com/google/devtools/build/lib/skyframe:sky_functions", diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeWorkspace.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeWorkspace.java index 6a37f041fc10fe..fcafa401fe4a24 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeWorkspace.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeWorkspace.java @@ -63,7 +63,7 @@ public final class BlazeWorkspace { private final BlazeDirectories directories; private final SkyframeExecutor skyframeExecutor; - private final SyscallCache perCommandSyscallCache; + private final SyscallCache syscallCache; /** * Loaded lazily on the first build command that enables the action cache. Cleared on a build @@ -84,7 +84,7 @@ public BlazeWorkspace( WorkspaceStatusAction.Factory workspaceStatusActionFactory, BinTools binTools, @Nullable AllocationTracker allocationTracker, - SyscallCache perCommandSyscallCache) { + SyscallCache syscallCache) { this.runtime = runtime; this.eventBusExceptionHandler = Preconditions.checkNotNull(eventBusExceptionHandler); this.workspaceStatusActionFactory = workspaceStatusActionFactory; @@ -93,7 +93,7 @@ public BlazeWorkspace( this.directories = directories; this.skyframeExecutor = skyframeExecutor; - this.perCommandSyscallCache = perCommandSyscallCache; + this.syscallCache = syscallCache; if (directories.inWorkspace()) { writeOutputBaseReadmeFile(); @@ -211,7 +211,7 @@ public CommandEnvironment initCommand( Thread.currentThread(), command, options, - perCommandSyscallCache, + syscallCache, warnings, waitTimeInMs, commandStartTime, diff --git a/src/main/java/com/google/devtools/build/lib/runtime/WorkspaceBuilder.java b/src/main/java/com/google/devtools/build/lib/runtime/WorkspaceBuilder.java index f4fcabc377d8aa..22d9523e36e511 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/WorkspaceBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/WorkspaceBuilder.java @@ -23,8 +23,8 @@ import com.google.devtools.build.lib.exec.BinTools; import com.google.devtools.build.lib.packages.PackageFactory; import com.google.devtools.build.lib.profiler.memory.AllocationTracker; +import com.google.devtools.build.lib.skyframe.DefaultSyscallCache; import com.google.devtools.build.lib.skyframe.DiffAwareness; -import com.google.devtools.build.lib.skyframe.PerBuildSyscallCache; import com.google.devtools.build.lib.skyframe.SequencedSkyframeExecutorFactory; import com.google.devtools.build.lib.skyframe.SkyframeExecutor; import com.google.devtools.build.lib.skyframe.SkyframeExecutorFactory; @@ -60,7 +60,7 @@ public final class WorkspaceBuilder { private SkyframeExecutorRepositoryHelpersHolder skyframeExecutorRepositoryHelpersHolder = null; @Nullable private SkyframeExecutor.SkyKeyStateReceiver skyKeyStateReceiver = null; - private SyscallCache perCommandSyscallCache; + private SyscallCache syscallCache; WorkspaceBuilder(BlazeDirectories directories, BinTools binTools) { this.directories = directories; @@ -88,12 +88,6 @@ public static int getSyscallCacheInitialCapacity() { return (int) scaledMemory; } - public static PerBuildSyscallCache createPerBuildSyscallCache() { - return PerBuildSyscallCache.newBuilder() - .setInitialCapacity(getSyscallCacheInitialCapacity()) - .build(); - } - BlazeWorkspace build( BlazeRuntime runtime, PackageFactory packageFactory, @@ -103,12 +97,15 @@ BlazeWorkspace build( if (skyframeExecutorFactory == null) { skyframeExecutorFactory = new SequencedSkyframeExecutorFactory(); } - if (perCommandSyscallCache == null) { - perCommandSyscallCache = createPerBuildSyscallCache(); + if (syscallCache == null) { + syscallCache = + DefaultSyscallCache.newBuilder() + .setInitialCapacity(getSyscallCacheInitialCapacity()) + .build(); } SingleFileSystemSyscallCache singleFsSyscallCache = - new SingleFileSystemSyscallCache(perCommandSyscallCache, runtime.getFileSystem()); + new SingleFileSystemSyscallCache(syscallCache, runtime.getFileSystem()); SkyframeExecutor skyframeExecutor = skyframeExecutorFactory.create( @@ -173,13 +170,10 @@ public WorkspaceBuilder setAllocationTracker(AllocationTracker allocationTracker } @CanIgnoreReturnValue - public WorkspaceBuilder setPerCommandSyscallCache(SyscallCache perCommandSyscallCache) { + public WorkspaceBuilder setSyscallCache(SyscallCache syscallCache) { Preconditions.checkState( - this.perCommandSyscallCache == null, - "Set twice: %s %s", - this.perCommandSyscallCache, - perCommandSyscallCache); - this.perCommandSyscallCache = Preconditions.checkNotNull(perCommandSyscallCache); + this.syscallCache == null, "Set twice: %s %s", this.syscallCache, syscallCache); + this.syscallCache = Preconditions.checkNotNull(syscallCache); return this; } diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/BUILD b/src/main/java/com/google/devtools/build/lib/skyframe/BUILD index d06db05116ce8d..d3c4ec2a506a10 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/BUILD +++ b/src/main/java/com/google/devtools/build/lib/skyframe/BUILD @@ -1814,8 +1814,8 @@ java_library( ) java_library( - name = "per_build_syscall_cache", - srcs = ["PerBuildSyscallCache.java"], + name = "default_syscall_cache", + srcs = ["DefaultSyscallCache.java"], deps = [ "//src/main/java/com/google/devtools/build/lib/util", "//src/main/java/com/google/devtools/build/lib/vfs", diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PerBuildSyscallCache.java b/src/main/java/com/google/devtools/build/lib/skyframe/DefaultSyscallCache.java similarity index 94% rename from src/main/java/com/google/devtools/build/lib/skyframe/PerBuildSyscallCache.java rename to src/main/java/com/google/devtools/build/lib/skyframe/DefaultSyscallCache.java index 52d71cf44eccb1..6072f62ff79b4e 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/PerBuildSyscallCache.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/DefaultSyscallCache.java @@ -30,13 +30,15 @@ import javax.annotation.Nullable; /** - * A per-build cache of filesystem operations. + * A basic implementation of {@link SyscallCache} that caches stat and readdir operations, used if + * no custom cache is set in {@link + * com.google.devtools.build.lib.runtime.WorkspaceBuilder#setSyscallCache}. * *

Allows non-Skyframe operations (like non-Skyframe globbing) to share a filesystem cache with * Skyframe operations, and may be able to answer questions (like the type of a file) based on * existing data (like the directory listing of a parent) without filesystem access. */ -public final class PerBuildSyscallCache implements SyscallCache { +public final class DefaultSyscallCache implements SyscallCache { private final Supplier, Object>> statCacheSupplier; private final Supplier> readdirCacheSupplier; @@ -47,7 +49,7 @@ public final class PerBuildSyscallCache implements SyscallCache { private static final FileStatus NO_STATUS = new FakeFileStatus(); - private PerBuildSyscallCache( + private DefaultSyscallCache( Supplier, Object>> statCacheSupplier, Supplier> readdirCacheSupplier) { this.statCacheSupplier = statCacheSupplier; @@ -89,7 +91,7 @@ public Builder setInitialCapacity(int initialCapacity) { return this; } - public PerBuildSyscallCache build() { + public DefaultSyscallCache build() { Caffeine statCacheBuilder = Caffeine.newBuilder(); if (maxStats != UNSET) { statCacheBuilder.maximumSize(maxStats); @@ -102,9 +104,9 @@ public PerBuildSyscallCache build() { statCacheBuilder.initialCapacity(initialCapacity); readdirCacheBuilder.initialCapacity(initialCapacity); } - return new PerBuildSyscallCache( - () -> statCacheBuilder.build(PerBuildSyscallCache::statImpl), - () -> readdirCacheBuilder.build(PerBuildSyscallCache::readdirImpl)); + return new DefaultSyscallCache( + () -> statCacheBuilder.build(DefaultSyscallCache::statImpl), + () -> readdirCacheBuilder.build(DefaultSyscallCache::readdirImpl)); } } diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/DirectoryListingStateFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/DirectoryListingStateFunction.java index ecd1a8cfab320e..180ff5ba3b16fd 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/DirectoryListingStateFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/DirectoryListingStateFunction.java @@ -34,7 +34,7 @@ public class DirectoryListingStateFunction implements SkyFunction { private final ExternalFilesHelper externalFilesHelper; /** - * A file-system abstraction to use. This can e.g. be a {@link PerBuildSyscallCache} which helps + * A file-system abstraction to use. This can e.g. be a {@link DefaultSyscallCache} which helps * re-use the results of expensive readdir() operations, that are likely already executed for * evaluating globs. */ diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java index 6382b71467868b..53bc9228d018bb 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java @@ -172,7 +172,7 @@ private SequencedSkyframeExecutor( Iterable diffAwarenessFactories, WorkspaceInfoFromDiffReceiver workspaceInfoFromDiffReceiver, ImmutableMap extraSkyFunctions, - SyscallCache perCommandSyscallCache, + SyscallCache syscallCache, SkyFunction ignoredPackagePrefixesFunction, CrossRepositoryLabelViolationStrategy crossRepositoryLabelViolationStrategy, ImmutableList buildFilesByPriority, @@ -189,14 +189,14 @@ private SequencedSkyframeExecutor( actionKeyContext, workspaceStatusActionFactory, extraSkyFunctions, - perCommandSyscallCache, + syscallCache, ExternalFileAction.DEPEND_ON_EXTERNAL_PKG_FOR_EXTERNAL_REPO_PATHS, ignoredPackagePrefixesFunction, crossRepositoryLabelViolationStrategy, buildFilesByPriority, externalPackageHelper, actionOnIOExceptionReadingBuildFile, - /*shouldUnblockCpuWorkWhenFetchingDeps=*/ false, + /* shouldUnblockCpuWorkWhenFetchingDeps= */ false, new PackageProgressReceiver(), new ConfiguredTargetProgressReceiver(), skyKeyStateReceiver, @@ -487,8 +487,7 @@ private void handleDiffsWithMissingDiffInformation( .build(); memoizingEvaluator.evaluate(ImmutableList.of(), evaluationContext); - FilesystemValueChecker fsvc = - new FilesystemValueChecker(tsgm, perCommandSyscallCache, fsvcThreads); + FilesystemValueChecker fsvc = new FilesystemValueChecker(tsgm, syscallCache, fsvcThreads); // We need to manually check for changes to known files. This entails finding all dirty file // system values under package roots for which we don't have diff information. If at least // one path entry doesn't have diff information, then we're going to have to iterate over @@ -558,8 +557,7 @@ private void handleDiffsWithMissingDiffInformation( logger.atInfo().log( "About to scan %d external files", externalFilesKnowledge.nonOutputExternalFilesSeen.size()); - FilesystemValueChecker fsvc = - new FilesystemValueChecker(tsgm, perCommandSyscallCache, fsvcThreads); + FilesystemValueChecker fsvc = new FilesystemValueChecker(tsgm, syscallCache, fsvcThreads); ImmutableBatchDirtyResult batchDirtyResult; try (SilentCloseable c = Profiler.instance().profile("fsvc.getDirtyExternalKeys")) { Map externalDirtyNodes = new ConcurrentHashMap<>(); @@ -730,7 +728,7 @@ protected void invalidateFilesUnderPathForTestingImpl( Differencer.Diff diff; if (modifiedFileSet.treatEverythingAsModified()) { diff = - new FilesystemValueChecker(tsgm, perCommandSyscallCache, /*numThreads=*/ 200) + new FilesystemValueChecker(tsgm, syscallCache, /* numThreads= */ 200) .getDirtyKeys(memoizingEvaluator.getValues(), new BasicFilesystemDirtinessChecker()); } else { diff = getDiff(tsgm, modifiedFileSet, pathEntry, /* fsvcThreads= */ 200); @@ -757,7 +755,7 @@ public void detectModifiedOutputFiles( long startTime = System.nanoTime(); FilesystemValueChecker fsvc = new FilesystemValueChecker( - Preconditions.checkNotNull(tsgm.get()), perCommandSyscallCache, fsvcThreads); + Preconditions.checkNotNull(tsgm.get()), syscallCache, fsvcThreads); BatchStat batchStatter = outputService == null ? null : outputService.getBatchStatter(); recordingDiffer.invalidate( fsvc.getDirtyActionValues( @@ -977,7 +975,7 @@ public static final class Builder { private SkyFunction ignoredPackagePrefixesFunction; private BugReporter bugReporter = BugReporter.defaultInstance(); private SkyKeyStateReceiver skyKeyStateReceiver = SkyKeyStateReceiver.NULL_INSTANCE; - private SyscallCache perCommandSyscallCache = null; + private SyscallCache syscallCache = null; private Builder() {} @@ -1004,7 +1002,7 @@ public SequencedSkyframeExecutor build() { diffAwarenessFactories, workspaceInfoFromDiffReceiver, extraSkyFunctions, - Preconditions.checkNotNull(perCommandSyscallCache), + Preconditions.checkNotNull(syscallCache), ignoredPackagePrefixesFunction, crossRepositoryLabelViolationStrategy, buildFilesByPriority, @@ -1127,8 +1125,8 @@ public Builder setSkyKeyStateReceiver(SkyKeyStateReceiver skyKeyStateReceiver) { } @CanIgnoreReturnValue - public Builder setPerCommandSyscallCache(SyscallCache perCommandSyscallCache) { - this.perCommandSyscallCache = perCommandSyscallCache; + public Builder setSyscallCache(SyscallCache syscallCache) { + this.syscallCache = syscallCache; return this; } } diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutorFactory.java b/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutorFactory.java index 099db51a92a8cd..65fda322698437 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutorFactory.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutorFactory.java @@ -27,6 +27,7 @@ /** A factory of SkyframeExecutors that returns SequencedSkyframeExecutor. */ public final class SequencedSkyframeExecutorFactory implements SkyframeExecutorFactory { + @Override public SkyframeExecutor create( PackageFactory pkgFactory, @@ -36,7 +37,7 @@ public SkyframeExecutor create( Factory workspaceStatusActionFactory, Iterable diffAwarenessFactories, ImmutableMap extraSkyFunctions, - SyscallCache perCommandSyscallCache, + SyscallCache syscallCache, @Nullable SkyframeExecutorRepositoryHelpersHolder repositoryHelpersHolder, SkyframeExecutor.SkyKeyStateReceiver skyKeyStateReceiver, BugReporter bugReporter) { @@ -48,7 +49,7 @@ public SkyframeExecutor create( .setWorkspaceStatusActionFactory(workspaceStatusActionFactory) .setDiffAwarenessFactories(diffAwarenessFactories) .setExtraSkyFunctions(extraSkyFunctions) - .setPerCommandSyscallCache(perCommandSyscallCache) + .setSyscallCache(syscallCache) .setRepositoryHelpersHolder(repositoryHelpersHolder) .setSkyKeyStateReceiver(skyKeyStateReceiver) .setBugReporter(bugReporter) diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java index d161e2d0c3a594..a584b9efc27234 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java @@ -308,7 +308,7 @@ public abstract class SkyframeExecutor implements WalkableGraphFactory, Configur private final AtomicInteger numPackagesSuccessfullyLoaded = new AtomicInteger(0); @Nullable private final PackageProgressReceiver packageProgress; @Nullable private final ConfiguredTargetProgressReceiver configuredTargetProgress; - final SyscallCache perCommandSyscallCache; + final SyscallCache syscallCache; private final SkyframeBuildView skyframeBuildView; private ActionLogBufferPathGenerator actionLogBufferPathGenerator; @@ -433,7 +433,7 @@ protected SkyframeExecutor( ActionKeyContext actionKeyContext, Factory workspaceStatusActionFactory, ImmutableMap extraSkyFunctions, - SyscallCache perCommandSyscallCache, + SyscallCache syscallCache, ExternalFileAction externalFileAction, SkyFunction ignoredPackagePrefixesFunction, CrossRepositoryLabelViolationStrategy crossRepositoryLabelViolationStrategy, @@ -452,8 +452,8 @@ protected SkyframeExecutor( this.shouldUnblockCpuWorkWhenFetchingDeps = shouldUnblockCpuWorkWhenFetchingDeps; this.skyKeyStateReceiver = skyKeyStateReceiver; this.bugReporter = bugReporter; - this.perCommandSyscallCache = perCommandSyscallCache; - this.pkgFactory.setSyscallCache(this.perCommandSyscallCache); + this.syscallCache = syscallCache; + this.pkgFactory.setSyscallCache(this.syscallCache); this.workspaceStatusActionFactory = workspaceStatusActionFactory; this.queryTransitivePackagePreloader = new QueryTransitivePackagePreloader( @@ -461,7 +461,7 @@ protected SkyframeExecutor( this.packageManager = new SkyframePackageManager( new SkyframePackageLoader(), - this.perCommandSyscallCache, + this.syscallCache, pkgLocator::get, numPackagesSuccessfullyLoaded); this.fileSystem = fileSystem; @@ -478,7 +478,7 @@ protected SkyframeExecutor( outputArtifactsFromActionCache, statusReporterRef, this::getPathEntries, - this.perCommandSyscallCache, + this.syscallCache, skyKeyStateReceiver::makeThreadStateReceiver); this.artifactFactory = new ArtifactFactory( @@ -625,7 +625,7 @@ private ImmutableMap skyFunctions() { new ArtifactFunction( () -> !skyframeActionExecutor.actionFileSystemType().inMemoryFileSystem(), sourceArtifactsSeen, - perCommandSyscallCache)); + syscallCache)); map.put( SkyFunctions.BUILD_INFO_COLLECTION, new BuildInfoCollectionFunction(actionKeyContext, artifactFactory)); @@ -637,7 +637,7 @@ private ImmutableMap skyFunctions() { this.actionExecutionFunction = actionExecutionFunction; map.put( SkyFunctions.RECURSIVE_FILESYSTEM_TRAVERSAL, - new RecursiveFilesystemTraversalFunction(perCommandSyscallCache)); + new RecursiveFilesystemTraversalFunction(syscallCache)); map.put(SkyFunctions.FILESET_ENTRY, new FilesetEntryFunction(directories::getExecRoot)); map.put( SkyFunctions.ACTION_TEMPLATE_EXPANSION, @@ -689,11 +689,11 @@ protected boolean traverseTestSuites() { } protected SkyFunction newFileStateFunction() { - return new FileStateFunction(tsgm::get, perCommandSyscallCache, externalFilesHelper); + return new FileStateFunction(tsgm::get, syscallCache, externalFilesHelper); } protected SkyFunction newDirectoryListingStateFunction() { - return new DirectoryListingStateFunction(externalFilesHelper, perCommandSyscallCache); + return new DirectoryListingStateFunction(externalFilesHelper, syscallCache); } protected GlobFunction newGlobFunction() { @@ -1298,7 +1298,7 @@ protected Differencer.Diff getDiff( memoizingEvaluator.getDoneValues(), dirtyFileStateSkyKeys, fsvcThreads, - perCommandSyscallCache); + syscallCache); } /** @@ -1351,7 +1351,7 @@ public void preparePackageLoading( starlarkSemantics.getBool(BuildLanguageOptions.EXPERIMENTAL_SIBLING_REPOSITORY_LAYOUT)); setPackageLocator(pkgLocator); - perCommandSyscallCache.clear(); + syscallCache.clear(); this.pkgFactory.setGlobbingThreads(packageOptions.globbingThreads); this.pkgFactory.setMaxDirectoriesToEagerlyVisitInGlobbing( packageOptions.maxDirectoriesToEagerlyVisitInGlobbing); @@ -2182,7 +2182,7 @@ public final void invalidateFilesUnderPathForTesting( dropConfiguredTargetsNow(eventHandler); lastAnalysisDiscarded = false; } - perCommandSyscallCache.clear(); + syscallCache.clear(); invalidateFilesUnderPathForTestingImpl(eventHandler, modifiedFileSet, pathEntry); } @@ -2218,7 +2218,7 @@ protected ConfigureTargetsResult configureTargets( EvaluationResult result = memoizingEvaluator.evaluate( Iterables.concat(configuredTargetKeys, topLevelAspectKeys), evaluationContext); - perCommandSyscallCache.noteAnalysisPhaseEnded(); + syscallCache.noteAnalysisPhaseEnded(); ImmutableSet.Builder configuredTargets = ImmutableSet.builder(); ImmutableMap.Builder aspects = ImmutableMap.builder(); @@ -2313,7 +2313,7 @@ EvaluationResult evaluateBuildDriverKeys( Iterables.concat(buildDriverCTKeys, buildDriverAspectKeys), evaluationContext); } finally { // No more analysis expected after this. - perCommandSyscallCache.noteAnalysisPhaseEnded(); + syscallCache.noteAnalysisPhaseEnded(); } } diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutorFactory.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutorFactory.java index 3cc6521914c036..ce922b4676b56f 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutorFactory.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutorFactory.java @@ -50,7 +50,7 @@ SkyframeExecutor create( Factory workspaceStatusActionFactory, Iterable diffAwarenessFactories, ImmutableMap extraSkyFunctions, - SyscallCache perCommandSyscallCache, + SyscallCache syscallCache, SkyframeExecutorRepositoryHelpersHolder repositoryHelpersHolder, SkyframeExecutor.SkyKeyStateReceiver skyKeyStateReceiver, BugReporter bugReporter) diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/packages/AbstractPackageLoader.java b/src/main/java/com/google/devtools/build/lib/skyframe/packages/AbstractPackageLoader.java index 682d26c420cdf5..c4d9baae02dff9 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/packages/AbstractPackageLoader.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/packages/AbstractPackageLoader.java @@ -60,6 +60,7 @@ import com.google.devtools.build.lib.skyframe.BzlLoadFunction; import com.google.devtools.build.lib.skyframe.BzlmodRepoRuleFunction; import com.google.devtools.build.lib.skyframe.ContainingPackageLookupFunction; +import com.google.devtools.build.lib.skyframe.DefaultSyscallCache; import com.google.devtools.build.lib.skyframe.ExternalFilesHelper; import com.google.devtools.build.lib.skyframe.ExternalFilesHelper.ExternalFileAction; import com.google.devtools.build.lib.skyframe.ExternalPackageFunction; @@ -72,7 +73,6 @@ import com.google.devtools.build.lib.skyframe.PackageLookupFunction; import com.google.devtools.build.lib.skyframe.PackageLookupFunction.CrossRepositoryLabelViolationStrategy; import com.google.devtools.build.lib.skyframe.PackageValue; -import com.google.devtools.build.lib.skyframe.PerBuildSyscallCache; import com.google.devtools.build.lib.skyframe.PrecomputedFunction; import com.google.devtools.build.lib.skyframe.PrecomputedValue; import com.google.devtools.build.lib.skyframe.RepositoryMappingFunction; @@ -442,8 +442,8 @@ private MemoizingEvaluator makeFreshEvaluator() { private ImmutableMap makeFreshSkyFunctions() { TimestampGranularityMonitor tsgm = new TimestampGranularityMonitor(BlazeClock.instance()); - PerBuildSyscallCache syscallCache = - PerBuildSyscallCache.newBuilder().setInitialCapacity(nonSkyframeGlobbingThreads).build(); + DefaultSyscallCache syscallCache = + DefaultSyscallCache.newBuilder().setInitialCapacity(nonSkyframeGlobbingThreads).build(); pkgFactory.setSyscallCache(syscallCache); pkgFactory.setMaxDirectoriesToEagerlyVisitInGlobbing( MAX_DIRECTORIES_TO_EAGERLY_VISIT_IN_GLOBBING); diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/packages/BUILD b/src/main/java/com/google/devtools/build/lib/skyframe/packages/BUILD index fb19a8cc9aa4b5..3404947a9a549b 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/packages/BUILD +++ b/src/main/java/com/google/devtools/build/lib/skyframe/packages/BUILD @@ -46,11 +46,11 @@ java_library( "//src/main/java/com/google/devtools/build/lib/repository:external_package_helper", "//src/main/java/com/google/devtools/build/lib/skyframe:bzl_compile", "//src/main/java/com/google/devtools/build/lib/skyframe:containing_package_lookup_function", + "//src/main/java/com/google/devtools/build/lib/skyframe:default_syscall_cache", "//src/main/java/com/google/devtools/build/lib/skyframe:file_function", "//src/main/java/com/google/devtools/build/lib/skyframe:ignored_package_prefixes_function", "//src/main/java/com/google/devtools/build/lib/skyframe:package_lookup_function", "//src/main/java/com/google/devtools/build/lib/skyframe:package_value", - "//src/main/java/com/google/devtools/build/lib/skyframe:per_build_syscall_cache", "//src/main/java/com/google/devtools/build/lib/skyframe:precomputed_function", "//src/main/java/com/google/devtools/build/lib/skyframe:precomputed_value", "//src/main/java/com/google/devtools/build/lib/skyframe:repository_mapping_function", 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 abc8163e6e82e5..37aa730fe55d96 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 @@ -25,9 +25,13 @@ * operations would be cached in Skyframe, but even then, implementations of this interface may do * batch operations and prefetching to improve performance. * + *

There is typically one {@link SyscallCache} instance in effect for the lifetime of the Bazel + * server, set in {@link com.google.devtools.build.lib.runtime.WorkspaceBuilder}. Between commands, + * {@link #clear} is called to drop cached data from the previous command. + * *

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. + * methods in this interface on files that may change during a build, like outputs or + * external repository files. Calling these methods on source files is allowed. */ public interface SyscallCache extends XattrProvider { SyscallCache NO_CACHE = diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java index f28ef3a1596e10..14973701a6f017 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java @@ -216,7 +216,7 @@ protected SkyframeExecutor createSkyframeExecutor(PackageFactory pkgFactory) { .setActionKeyContext(actionKeyContext) .setWorkspaceStatusActionFactory(workspaceStatusActionFactory) .setExtraSkyFunctions(analysisMock.getSkyFunctions(directories)) - .setPerCommandSyscallCache(delegatingSyscallCache) + .setSyscallCache(delegatingSyscallCache) .build(); } diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java index 50815a1c0e4ad9..8b880f948546f7 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java @@ -320,7 +320,7 @@ public void initializeSkyframeExecutor( .setActionKeyContext(actionKeyContext) .setWorkspaceStatusActionFactory(workspaceStatusActionFactory) .setExtraSkyFunctions(analysisMock.getSkyFunctions(directories)) - .setPerCommandSyscallCache(SyscallCache.NO_CACHE) + .setSyscallCache(SyscallCache.NO_CACHE) .setDiffAwarenessFactories(diffAwarenessFactories); skyframeExecutor = builder.build(); if (usesInliningBzlLoadFunction()) { diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/ConfigurationTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/ConfigurationTestCase.java index a8dd539e53faeb..fa77717a1a8e17 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/util/ConfigurationTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/util/ConfigurationTestCase.java @@ -125,7 +125,7 @@ public final void initializeSkyframeExecutor() throws Exception { .setActionKeyContext(actionKeyContext) .setWorkspaceStatusActionFactory(workspaceStatusActionFactory) .setExtraSkyFunctions(analysisMock.getSkyFunctions(directories)) - .setPerCommandSyscallCache(SyscallCache.NO_CACHE) + .setSyscallCache(SyscallCache.NO_CACHE) .build(); SkyframeExecutorTestHelper.process(skyframeExecutor); skyframeExecutor.injectExtraPrecomputedValues( diff --git a/src/test/java/com/google/devtools/build/lib/buildtool/BUILD b/src/test/java/com/google/devtools/build/lib/buildtool/BUILD index c604a800700a67..1afbaad748ec16 100644 --- a/src/test/java/com/google/devtools/build/lib/buildtool/BUILD +++ b/src/test/java/com/google/devtools/build/lib/buildtool/BUILD @@ -459,7 +459,7 @@ java_test( "//src/main/java/com/google/devtools/build/lib/events", "//src/main/java/com/google/devtools/build/lib/query2/query/output", "//src/main/java/com/google/devtools/build/lib/runtime/commands", - "//src/main/java/com/google/devtools/build/lib/skyframe:per_build_syscall_cache", + "//src/main/java/com/google/devtools/build/lib/skyframe:default_syscall_cache", "//src/main/java/com/google/devtools/build/lib/skyframe:sky_functions", "//src/main/java/com/google/devtools/build/lib/unix", "//src/main/java/com/google/devtools/build/lib/util:exit_code", diff --git a/src/test/java/com/google/devtools/build/lib/buildtool/QueryIntegrationTest.java b/src/test/java/com/google/devtools/build/lib/buildtool/QueryIntegrationTest.java index 58bee2ea682731..28b6443d874370 100644 --- a/src/test/java/com/google/devtools/build/lib/buildtool/QueryIntegrationTest.java +++ b/src/test/java/com/google/devtools/build/lib/buildtool/QueryIntegrationTest.java @@ -39,7 +39,7 @@ import com.google.devtools.build.lib.runtime.commands.QueryCommand; import com.google.devtools.build.lib.runtime.proto.InvocationPolicyOuterClass.InvocationPolicy; import com.google.devtools.build.lib.server.FailureDetails; -import com.google.devtools.build.lib.skyframe.PerBuildSyscallCache; +import com.google.devtools.build.lib.skyframe.DefaultSyscallCache; import com.google.devtools.build.lib.skyframe.SkyFunctions; import com.google.devtools.build.lib.testutil.TestConstants; import com.google.devtools.build.lib.testutil.TestUtils; @@ -88,7 +88,7 @@ @RunWith(TestParameterInjector.class) public class QueryIntegrationTest extends BuildIntegrationTestCase { private final CustomFileSystem fs = new CustomFileSystem(); - private final SyscallCache perCommandSyscallCache = PerBuildSyscallCache.newBuilder().build(); + private final SyscallCache syscallCache = DefaultSyscallCache.newBuilder().build(); private final List options = new ArrayList<>(); @@ -100,7 +100,7 @@ protected BlazeRuntime.Builder getRuntimeBuilder() throws Exception { @Override public void workspaceInit( BlazeRuntime runtime, BlazeDirectories directories, WorkspaceBuilder builder) { - builder.setPerCommandSyscallCache(perCommandSyscallCache); + builder.setSyscallCache(syscallCache); } }); } @@ -863,7 +863,7 @@ public void skyQueryExtensionPackageBuildFileDeletedAfterStat() throws Exception fs.watchedPaths.put( barBzl.asFragment(), () -> { - perCommandSyscallCache.clear(); + syscallCache.clear(); try { barBuild.delete(); } catch (IOException e) { @@ -886,7 +886,7 @@ public void skyQueryExtensionPackageBuildFileNotInUniverseHasError() throws Exce fs.watchedPaths.put( barBzl.asFragment(), () -> { - perCommandSyscallCache.clear(); + syscallCache.clear(); try { barBuild.delete(); } catch (IOException e) { diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/PackageLoadingTestCase.java b/src/test/java/com/google/devtools/build/lib/packages/util/PackageLoadingTestCase.java index 976b9e784c1959..fcca8b1904b656 100644 --- a/src/test/java/com/google/devtools/build/lib/packages/util/PackageLoadingTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/packages/util/PackageLoadingTestCase.java @@ -129,7 +129,7 @@ private SkyframeExecutor createSkyframeExecutor() { .setFileSystem(fileSystem) .setDirectories(directories) .setActionKeyContext(actionKeyContext) - .setPerCommandSyscallCache(delegatingSyscallCache) + .setSyscallCache(delegatingSyscallCache) .build(); skyframeExecutor.injectExtraPrecomputedValues( ImmutableList.of( diff --git a/src/test/java/com/google/devtools/build/lib/pkgcache/BuildFileModificationTest.java b/src/test/java/com/google/devtools/build/lib/pkgcache/BuildFileModificationTest.java index decf9d4975d778..312e2e61cd9207 100644 --- a/src/test/java/com/google/devtools/build/lib/pkgcache/BuildFileModificationTest.java +++ b/src/test/java/com/google/devtools/build/lib/pkgcache/BuildFileModificationTest.java @@ -92,7 +92,7 @@ public final void initializeSkyframeExecutor() { .setDirectories(directories) .setActionKeyContext(actionKeyContext) .setExtraSkyFunctions(analysisMock.getSkyFunctions(directories)) - .setPerCommandSyscallCache(SyscallCache.NO_CACHE) + .setSyscallCache(SyscallCache.NO_CACHE) .build(); skyframeExecutor.injectExtraPrecomputedValues( ImmutableList.of( diff --git a/src/test/java/com/google/devtools/build/lib/pkgcache/IncrementalLoadingTest.java b/src/test/java/com/google/devtools/build/lib/pkgcache/IncrementalLoadingTest.java index 8c4e5dad273bc4..46e3157bc0a4ca 100644 --- a/src/test/java/com/google/devtools/build/lib/pkgcache/IncrementalLoadingTest.java +++ b/src/test/java/com/google/devtools/build/lib/pkgcache/IncrementalLoadingTest.java @@ -451,7 +451,7 @@ public DiffAwareness maybeCreate(Root pathEntry) { .setDirectories(directories) .setActionKeyContext(new ActionKeyContext()) .setDiffAwarenessFactories(ImmutableList.of(new ManualDiffAwarenessFactory())) - .setPerCommandSyscallCache(SyscallCache.NO_CACHE) + .setSyscallCache(SyscallCache.NO_CACHE) .build(); SkyframeExecutorTestHelper.process(skyframeExecutor); PackageOptions packageOptions = Options.getDefaults(PackageOptions.class); diff --git a/src/test/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunnerTest.java b/src/test/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunnerTest.java index db27286523474f..4744559a5f8c8d 100644 --- a/src/test/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunnerTest.java +++ b/src/test/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunnerTest.java @@ -1369,7 +1369,7 @@ private static final class LoadingPhaseTester { .setDirectories(directories) .setActionKeyContext(new ActionKeyContext()) .setExtraSkyFunctions(analysisMock.getSkyFunctions(directories)) - .setPerCommandSyscallCache(SyscallCache.NO_CACHE) + .setSyscallCache(SyscallCache.NO_CACHE) .build(); SkyframeExecutorTestHelper.process(skyframeExecutor); PathPackageLocator pkgLocator = diff --git a/src/test/java/com/google/devtools/build/lib/pkgcache/PackageLoadingTest.java b/src/test/java/com/google/devtools/build/lib/pkgcache/PackageLoadingTest.java index 4d3d5e997679bd..9825715dfa7c26 100644 --- a/src/test/java/com/google/devtools/build/lib/pkgcache/PackageLoadingTest.java +++ b/src/test/java/com/google/devtools/build/lib/pkgcache/PackageLoadingTest.java @@ -97,7 +97,7 @@ private void initializeSkyframeExecutor(boolean doPackageLoadingChecks) throws E .setDirectories(directories) .setActionKeyContext(actionKeyContext) .setExtraSkyFunctions(analysisMock.getSkyFunctions(directories)) - .setPerCommandSyscallCache(SyscallCache.NO_CACHE) + .setSyscallCache(SyscallCache.NO_CACHE) .build(); SkyframeExecutorTestHelper.process(skyframeExecutor); setUpSkyframe(parsePackageOptions(), parseBuildLanguageOptions()); diff --git a/src/test/java/com/google/devtools/build/lib/query2/testutil/SkyframeQueryHelper.java b/src/test/java/com/google/devtools/build/lib/query2/testutil/SkyframeQueryHelper.java index c791adae7d933c..84ee6c690ccf35 100644 --- a/src/test/java/com/google/devtools/build/lib/query2/testutil/SkyframeQueryHelper.java +++ b/src/test/java/com/google/devtools/build/lib/query2/testutil/SkyframeQueryHelper.java @@ -381,7 +381,7 @@ protected SkyframeExecutor createSkyframeExecutor(ConfiguredRuleClassProvider ru .setIgnoredPackagePrefixesFunction( new IgnoredPackagePrefixesFunction(ignoredPackagePrefixesFile)) .setExtraSkyFunctions(analysisMock.getSkyFunctions(directories)) - .setPerCommandSyscallCache(delegatingSyscallCache) + .setSyscallCache(delegatingSyscallCache) .build(); skyframeExecutor.injectExtraPrecomputedValues( ImmutableList.builder() diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/BUILD b/src/test/java/com/google/devtools/build/lib/skyframe/BUILD index 4cfec3796ead1a..44fce13c6e6970 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/BUILD +++ b/src/test/java/com/google/devtools/build/lib/skyframe/BUILD @@ -207,7 +207,7 @@ java_test( "//src/main/java/com/google/devtools/build/lib/skyframe:directory_listing_function", "//src/main/java/com/google/devtools/build/lib/skyframe:directory_listing_state_value", "//src/main/java/com/google/devtools/build/lib/skyframe:file_function", - "//src/main/java/com/google/devtools/build/lib/skyframe:per_build_syscall_cache", + "//src/main/java/com/google/devtools/build/lib/skyframe:default_syscall_cache", "//src/main/java/com/google/devtools/build/lib/skyframe:top_level_status_events", "//src/main/java/com/google/devtools/build/lib/io:file_symlink_cycle_exception", "//src/main/java/com/google/devtools/build/lib/io:file_symlink_cycle_uniqueness_function", diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/FileSystemValueCheckerInferringAncestorsTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/FileSystemValueCheckerInferringAncestorsTest.java index 30fafbd9a9851b..d57007e9eed3bc 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/FileSystemValueCheckerInferringAncestorsTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/FileSystemValueCheckerInferringAncestorsTest.java @@ -63,7 +63,7 @@ public final class FileSystemValueCheckerInferringAncestorsTest { private final Scratch scratch = new Scratch(); private final List statedPaths = new ArrayList<>(); - private final PerBuildSyscallCache syscallCache = PerBuildSyscallCache.newBuilder().build(); + private final DefaultSyscallCache syscallCache = DefaultSyscallCache.newBuilder().build(); private Root root; private Root untrackedRoot; private Exception throwOnStat; diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternsFunctionSmartNegationTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternsFunctionSmartNegationTest.java index 9c5bbd7ab2e0ea..1b8be9d9668f87 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternsFunctionSmartNegationTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternsFunctionSmartNegationTest.java @@ -91,7 +91,7 @@ public void setUp() throws Exception { .setDirectories(directories) .setActionKeyContext(new ActionKeyContext()) .setExtraSkyFunctions(AnalysisMock.get().getSkyFunctions(directories)) - .setPerCommandSyscallCache(SyscallCache.NO_CACHE) + .setSyscallCache(SyscallCache.NO_CACHE) .setIgnoredPackagePrefixesFunction( new IgnoredPackagePrefixesFunction( PathFragment.create(ADDITIONAL_IGNORED_PACKAGE_PREFIXES_FILE_PATH_STRING)))