Search in sources :

Example 11 with AutoCloseableLock

use of com.facebook.buck.util.concurrent.AutoCloseableLock in project buck by facebook.

the class DaemonicParserState method invalidateAllCaches.

public boolean invalidateAllCaches() {
    LOG.debug("Starting to invalidate all caches..");
    try (AutoCloseableLock writeLock = cellStateLock.writeLock()) {
        boolean invalidated = !cellPathToDaemonicState.isEmpty();
        cellPathToDaemonicState.clear();
        if (invalidated) {
            LOG.debug("Cache data invalidated.");
        } else {
            LOG.debug("Caches were empty, no data invalidated.");
        }
        return invalidated;
    }
}
Also used : AutoCloseableLock(com.facebook.buck.util.concurrent.AutoCloseableLock)

Example 12 with AutoCloseableLock

use of com.facebook.buck.util.concurrent.AutoCloseableLock in project buck by facebook.

the class DaemonicParserState method invalidateContainingBuildFile.

/**
   * Finds the build file responsible for the given {@link Path} and invalidates
   * all of the cached rules dependent on it.
   * @param path A {@link Path}, relative to the project root and "contained"
   *             within the build file to find and invalidate.
   */
private synchronized void invalidateContainingBuildFile(Cell cell, BuildFileTree buildFiles, Path path) {
    LOG.debug("Invalidating rules dependent on change to %s in cell %s", path, cell);
    Set<Path> packageBuildFiles = new HashSet<>();
    // Find the closest ancestor package for the input path.  We'll definitely need to invalidate
    // that.
    Optional<Path> packageBuildFile = buildFiles.getBasePathOfAncestorTarget(path);
    packageBuildFiles.addAll(OptionalCompat.asSet(packageBuildFile.map(cell.getFilesystem()::resolve)));
    // packages to reference the same file
    if (!cell.isEnforcingBuckPackageBoundaries(path)) {
        while (packageBuildFile.isPresent() && packageBuildFile.get().getParent() != null) {
            packageBuildFile = buildFiles.getBasePathOfAncestorTarget(packageBuildFile.get().getParent());
            packageBuildFiles.addAll(OptionalCompat.asSet(packageBuildFile));
        }
    }
    if (packageBuildFiles.isEmpty()) {
        LOG.debug("%s is not owned by any build file.  Not invalidating anything.", cell.getFilesystem().resolve(path).toAbsolutePath().toString());
        return;
    }
    buildFilesInvalidatedByFileAddOrRemoveCounter.inc(packageBuildFiles.size());
    pathsAddedOrRemovedInvalidatingBuildFiles.add(path.toString());
    try (AutoCloseableLock readLock = cellStateLock.readLock()) {
        DaemonicCellState state = cellPathToDaemonicState.get(cell.getRoot());
        // Invalidate all the packages we found.
        for (Path buildFile : packageBuildFiles) {
            invalidatePath(state, buildFile.resolve(cell.getBuildFileName()));
        }
    }
}
Also used : Path(java.nio.file.Path) AutoCloseableLock(com.facebook.buck.util.concurrent.AutoCloseableLock) HashSet(java.util.HashSet)

Aggregations

AutoCloseableLock (com.facebook.buck.util.concurrent.AutoCloseableLock)12 Path (java.nio.file.Path)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ConcurrentMap (java.util.concurrent.ConcurrentMap)4 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)2 Cell (com.facebook.buck.rules.Cell)2 MapDifference (com.google.common.collect.MapDifference)2 HashSet (java.util.HashSet)2 Optional (java.util.Optional)2 BuildFileParseException (com.facebook.buck.json.BuildFileParseException)1 Logger (com.facebook.buck.log.Logger)1 BuildFileTree (com.facebook.buck.model.BuildFileTree)1 BuildTarget (com.facebook.buck.model.BuildTarget)1 BuildTargetException (com.facebook.buck.model.BuildTargetException)1 FilesystemBackedBuildFileTree (com.facebook.buck.model.FilesystemBackedBuildFileTree)1 AutoCloseableReadWriteUpdateLock (com.facebook.buck.util.concurrent.AutoCloseableReadWriteUpdateLock)1 Preconditions (com.google.common.base.Preconditions)1 HashMultimap (com.google.common.collect.HashMultimap)1