use of com.google.common.collect.MapDifference 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.google.common.collect.MapDifference in project cassandra by apache.
the class SchemaKeyspace method makeUpdateTableMutation.
static Mutation.SimpleBuilder makeUpdateTableMutation(KeyspaceMetadata keyspace, TableMetadata oldTable, TableMetadata newTable, long timestamp) {
Mutation.SimpleBuilder builder = makeCreateKeyspaceMutation(keyspace.name, keyspace.params, timestamp);
addTableToSchemaMutation(newTable, false, builder);
MapDifference<ByteBuffer, ColumnMetadata> columnDiff = Maps.difference(oldTable.columns, newTable.columns);
// columns that are no longer needed
for (ColumnMetadata column : columnDiff.entriesOnlyOnLeft().values()) dropColumnFromSchemaMutation(oldTable, column, builder);
// newly added columns
for (ColumnMetadata column : columnDiff.entriesOnlyOnRight().values()) addColumnToSchemaMutation(newTable, column, builder);
// old columns with updated attributes
for (ByteBuffer name : columnDiff.entriesDiffering().keySet()) addColumnToSchemaMutation(newTable, newTable.getColumn(name), builder);
// dropped columns
MapDifference<ByteBuffer, DroppedColumn> droppedColumnDiff = Maps.difference(oldTable.droppedColumns, newTable.droppedColumns);
// newly dropped columns
for (DroppedColumn column : droppedColumnDiff.entriesOnlyOnRight().values()) addDroppedColumnToSchemaMutation(newTable, column, builder);
// columns added then dropped again
for (ByteBuffer name : droppedColumnDiff.entriesDiffering().keySet()) addDroppedColumnToSchemaMutation(newTable, newTable.droppedColumns.get(name), builder);
MapDifference<String, TriggerMetadata> triggerDiff = triggersDiff(oldTable.triggers, newTable.triggers);
// dropped triggers
for (TriggerMetadata trigger : triggerDiff.entriesOnlyOnLeft().values()) dropTriggerFromSchemaMutation(oldTable, trigger, builder);
// newly created triggers
for (TriggerMetadata trigger : triggerDiff.entriesOnlyOnRight().values()) addTriggerToSchemaMutation(newTable, trigger, builder);
MapDifference<String, IndexMetadata> indexesDiff = indexesDiff(oldTable.indexes, newTable.indexes);
// dropped indexes
for (IndexMetadata index : indexesDiff.entriesOnlyOnLeft().values()) dropIndexFromSchemaMutation(oldTable, index, builder);
// newly created indexes
for (IndexMetadata index : indexesDiff.entriesOnlyOnRight().values()) addIndexToSchemaMutation(newTable, index, builder);
// updated indexes need to be updated
for (MapDifference.ValueDifference<IndexMetadata> diff : indexesDiff.entriesDiffering().values()) addUpdatedIndexToSchemaMutation(newTable, diff.rightValue(), builder);
return builder;
}
use of com.google.common.collect.MapDifference in project cassandra by apache.
the class Schema method reload.
private void reload(KeyspaceMetadata previous, KeyspaceMetadata updated) {
Keyspace keyspace = getKeyspaceInstance(updated.name);
if (keyspace != null)
keyspace.setMetadata(updated);
MapDifference<TableId, TableMetadata> tablesDiff = previous.tables.diff(updated.tables);
MapDifference<TableId, ViewMetadata> viewsDiff = previous.views.diff(updated.views);
MapDifference<String, TableMetadata> indexesDiff = previous.tables.indexesDiff(updated.tables);
// clean up after removed entries
tablesDiff.entriesOnlyOnLeft().values().forEach(table -> metadataRefs.remove(table.id));
viewsDiff.entriesOnlyOnLeft().values().forEach(view -> metadataRefs.remove(view.metadata.id));
indexesDiff.entriesOnlyOnLeft().values().forEach(indexTable -> indexMetadataRefs.remove(Pair.create(indexTable.keyspace, indexTable.indexName().get())));
// load up new entries
tablesDiff.entriesOnlyOnRight().values().forEach(table -> metadataRefs.put(table.id, new TableMetadataRef(table)));
viewsDiff.entriesOnlyOnRight().values().forEach(view -> metadataRefs.put(view.metadata.id, new TableMetadataRef(view.metadata)));
indexesDiff.entriesOnlyOnRight().values().forEach(indexTable -> indexMetadataRefs.put(Pair.create(indexTable.keyspace, indexTable.indexName().get()), new TableMetadataRef(indexTable)));
// refresh refs to updated ones
tablesDiff.entriesDiffering().values().forEach(diff -> metadataRefs.get(diff.rightValue().id).set(diff.rightValue()));
viewsDiff.entriesDiffering().values().forEach(diff -> metadataRefs.get(diff.rightValue().metadata.id).set(diff.rightValue().metadata));
indexesDiff.entriesDiffering().values().stream().map(MapDifference.ValueDifference::rightValue).forEach(indexTable -> indexMetadataRefs.get(Pair.create(indexTable.keyspace, indexTable.indexName().get())).set(indexTable));
}
use of com.google.common.collect.MapDifference 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