use of com.facebook.buck.util.concurrent.AutoCloseableLock in project buck by facebook.
the class DaemonicParserState method invalidateIfProjectBuildFileParserStateChanged.
private void invalidateIfProjectBuildFileParserStateChanged(Cell cell) {
Iterable<String> defaultIncludes = cell.getBuckConfig().getView(ParserConfig.class).getDefaultIncludes();
boolean invalidatedByDefaultIncludesChange = false;
Iterable<String> expected;
try (AutoCloseableLock readLock = cachedStateLock.readLock()) {
expected = cachedIncludes.get(cell.getRoot());
if (expected == null || !Iterables.elementsEqual(defaultIncludes, expected)) {
// Someone's changed the default includes. That's almost definitely caused all our lovingly
// cached data to be enormously wonky.
invalidatedByDefaultIncludesChange = true;
}
if (!invalidatedByDefaultIncludesChange) {
return;
}
}
try (AutoCloseableLock writeLock = cachedStateLock.writeLock()) {
cachedIncludes.put(cell.getRoot(), defaultIncludes);
}
synchronized (this) {
if (invalidateCellCaches(cell) && invalidatedByDefaultIncludesChange) {
LOG.warn("Invalidating cache on default includes change (%s != %s)", expected, defaultIncludes);
cacheInvalidatedByDefaultIncludesChangeCounter.inc();
}
}
}
use of com.facebook.buck.util.concurrent.AutoCloseableLock in project buck by facebook.
the class DaemonicCellState method invalidatePath.
int invalidatePath(Path path) {
try (AutoCloseableLock writeLock = rawAndComputedNodesLock.writeLock()) {
int invalidatedRawNodes = 0;
ImmutableSet<Map<String, Object>> rawNodes = allRawNodes.getIfPresent(path);
if (rawNodes != null) {
// Increment the counter
invalidatedRawNodes = rawNodes.size();
for (Map<String, Object> rawNode : rawNodes) {
UnflavoredBuildTarget target = RawNodeParsePipeline.parseBuildTargetFromRawRule(cellRoot, rawNode, path);
LOG.debug("Invalidating target for path %s: %s", path, target);
for (CacheImpl<?> cache : typedNodeCaches.values()) {
cache.allComputedNodes.invalidateAll(targetsCornucopia.get(target));
}
targetsCornucopia.removeAll(target);
}
allRawNodes.invalidate(path);
}
// We may have been given a file that other build files depend on. Iteratively remove those.
Iterable<Path> dependents = buildFileDependents.get(path);
LOG.debug("Invalidating dependents for path %s: %s", path, dependents);
for (Path dependent : dependents) {
if (dependent.equals(path)) {
continue;
}
invalidatedRawNodes += invalidatePath(dependent);
}
buildFileDependents.removeAll(path);
buildFileConfigs.remove(path);
buildFileEnv.remove(path);
return invalidatedRawNodes;
}
}
use of com.facebook.buck.util.concurrent.AutoCloseableLock in project buck by facebook.
the class DaemonicCellState method putRawNodesIfNotPresentAndStripMetaEntries.
ImmutableSet<Map<String, Object>> putRawNodesIfNotPresentAndStripMetaEntries(final Path buildFile, final ImmutableSet<Map<String, Object>> withoutMetaIncludes, final ImmutableSet<Path> dependentsOfEveryNode, ImmutableMap<String, ImmutableMap<String, Optional<String>>> configs, ImmutableMap<String, Optional<String>> env) {
try (AutoCloseableLock writeLock = rawAndComputedNodesLock.writeLock()) {
ImmutableSet<Map<String, Object>> updated = allRawNodes.putIfAbsentAndGet(buildFile, withoutMetaIncludes);
buildFileConfigs.put(buildFile, configs);
buildFileEnv.put(buildFile, env);
if (updated == withoutMetaIncludes) {
// the "dependentsOfEveryNode" set.
for (Path dependent : dependentsOfEveryNode) {
buildFileDependents.put(dependent, buildFile);
}
}
return updated;
}
}
use of com.facebook.buck.util.concurrent.AutoCloseableLock in project buck by facebook.
the class DaemonicCellState method getOrCreateCache.
@SuppressWarnings("unchecked")
public <T> CacheImpl<T> getOrCreateCache(Class<T> type) {
try (AutoCloseableLock updateLock = rawAndComputedNodesLock.updateLock()) {
CacheImpl<?> cache = typedNodeCaches.get(type);
if (cache == null) {
try (AutoCloseableLock writeLock = rawAndComputedNodesLock.writeLock()) {
cache = new CacheImpl<>();
typedNodeCaches.put(type, cache);
}
}
return (CacheImpl<T>) cache;
}
}
use of com.facebook.buck.util.concurrent.AutoCloseableLock in project buck by facebook.
the class DaemonicParserState method invalidateIfBuckConfigOrEnvHasChanged.
private synchronized void invalidateIfBuckConfigOrEnvHasChanged(Cell cell, Path buildFile) {
try (AutoCloseableLock readLock = cellStateLock.readLock()) {
DaemonicCellState state = cellPathToDaemonicState.get(cell.getRoot());
if (state == null) {
return;
}
// Invalidates and also keeps the state cell up-to-date
state.invalidateIfBuckConfigHasChanged(cell, buildFile);
Optional<MapDifference<String, String>> envDiff = state.invalidateIfEnvHasChanged(cell, buildFile);
if (envDiff.isPresent()) {
MapDifference<String, String> diff = envDiff.get();
LOG.warn("Invalidating cache on environment change (%s)", diff);
Set<String> environmentChanges = new HashSet<>();
environmentChanges.addAll(diff.entriesOnlyOnLeft().keySet());
environmentChanges.addAll(diff.entriesOnlyOnRight().keySet());
environmentChanges.addAll(diff.entriesDiffering().keySet());
cacheInvalidatedByEnvironmentVariableChangeCounter.addAll(environmentChanges);
broadcastEventListener.broadcast(ParsingEvent.environmentalChange(environmentChanges.toString()));
}
}
}
Aggregations