use of com.facebook.buck.util.concurrent.AutoCloseableLock in project buck by facebook.
the class DaemonicCellState method invalidateIfBuckConfigHasChanged.
void invalidateIfBuckConfigHasChanged(Cell cell, Path buildFile) {
// TODO(mzlee): Check whether usedConfigs includes the buildFileName
ImmutableMap<String, ImmutableMap<String, Optional<String>>> usedConfigs;
try (AutoCloseableLock readLock = rawAndComputedNodesLock.readLock()) {
usedConfigs = buildFileConfigs.get(buildFile);
}
if (usedConfigs == null) {
// TODO(mzlee): Figure out when/how we can safely update this
this.cell.set(cell);
return;
}
for (Map.Entry<String, ImmutableMap<String, Optional<String>>> keyEnt : usedConfigs.entrySet()) {
for (Map.Entry<String, Optional<String>> valueEnt : keyEnt.getValue().entrySet()) {
Optional<String> value = cell.getBuckConfig().getValue(keyEnt.getKey(), valueEnt.getKey());
if (!value.equals(valueEnt.getValue())) {
invalidatePath(buildFile);
this.cell.set(cell);
return;
}
}
}
}
use of com.facebook.buck.util.concurrent.AutoCloseableLock in project buck by facebook.
the class DaemonicCellState method invalidateIfEnvHasChanged.
Optional<MapDifference<String, String>> invalidateIfEnvHasChanged(Cell cell, Path buildFile) {
// Invalidate if env vars have changed.
ImmutableMap<String, Optional<String>> usedEnv;
try (AutoCloseableLock readLock = rawAndComputedNodesLock.readLock()) {
usedEnv = buildFileEnv.get(buildFile);
}
if (usedEnv == null) {
this.cell.set(cell);
return Optional.empty();
}
for (Map.Entry<String, Optional<String>> ent : usedEnv.entrySet()) {
Optional<String> value = Optional.ofNullable(cell.getBuckConfig().getEnvironment().get(ent.getKey()));
if (!value.equals(ent.getValue())) {
invalidatePath(buildFile);
this.cell.set(cell);
return Optional.of(Maps.difference(value.map(v -> ImmutableMap.of(ent.getKey(), v)).orElse(ImmutableMap.of()), ent.getValue().map(v -> ImmutableMap.of(ent.getKey(), v)).orElse(ImmutableMap.of())));
}
}
return Optional.empty();
}
use of com.facebook.buck.util.concurrent.AutoCloseableLock in project buck by facebook.
the class DaemonicParserState method getOrCreateCellState.
private DaemonicCellState getOrCreateCellState(Cell cell) {
try (AutoCloseableLock writeLock = cellStateLock.writeLock()) {
DaemonicCellState state = cellPathToDaemonicState.get(cell.getRoot());
if (state == null) {
state = new DaemonicCellState(cell, parsingThreads);
cellPathToDaemonicState.put(cell.getRoot(), state);
}
return state;
}
}
use of com.facebook.buck.util.concurrent.AutoCloseableLock in project buck by facebook.
the class DaemonicParserState method invalidateBasedOn.
public void invalidateBasedOn(WatchEvent<?> event) {
if (!WatchEvents.isPathChangeEvent(event)) {
// Non-path change event, likely an overflow due to many change events: invalidate everything.
LOG.debug("Received non-path change event %s, assuming overflow and checking caches.", event);
if (invalidateAllCaches()) {
LOG.warn("Invalidated cache on watch event %s.", event);
cacheInvalidatedByWatchOverflowCounter.inc();
}
return;
}
filesChangedCounter.inc();
Path path = (Path) event.context();
try (AutoCloseableLock readLock = cellStateLock.readLock()) {
for (DaemonicCellState state : cellPathToDaemonicState.values()) {
try {
// rule key change. For parsing, these are the only events we need to care about.
if (isPathCreateOrDeleteEvent(event)) {
Cell cell = state.getCell();
BuildFileTree buildFiles = buildFileTrees.get(cell);
if (path.endsWith(cell.getBuildFileName())) {
LOG.debug("Build file %s changed, invalidating build file tree for cell %s", path, cell);
// If a build file has been added or removed, reconstruct the build file tree.
buildFileTrees.invalidate(cell);
}
// "containing" {@code path} unless its filename matches a temp file pattern.
if (!isTempFile(cell, path)) {
invalidateContainingBuildFile(cell, buildFiles, path);
} else {
LOG.debug("Not invalidating the owning build file of %s because it is a temporary file.", state.getCellRoot().resolve(path).toAbsolutePath().toString());
}
}
} catch (ExecutionException | UncheckedExecutionException e) {
try {
Throwables.throwIfInstanceOf(e, BuildFileParseException.class);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
} catch (BuildFileParseException bfpe) {
LOG.warn("Unable to parse already parsed build file.", bfpe);
}
}
}
}
invalidatePath(path);
}
use of com.facebook.buck.util.concurrent.AutoCloseableLock in project buck by facebook.
the class DaemonicParserState method invalidateCellCaches.
public boolean invalidateCellCaches(Cell cell) {
LOG.debug("Starting to invalidate caches for %s..", cell.getRoot());
try (AutoCloseableLock writeLock = cellStateLock.writeLock()) {
boolean invalidated = cellPathToDaemonicState.containsKey(cell.getRoot());
cellPathToDaemonicState.remove(cell.getRoot());
if (invalidated) {
LOG.debug("Cell cache data invalidated.");
} else {
LOG.debug("Cell caches were empty, no data invalidated.");
}
return invalidated;
}
}
Aggregations