use of com.palantir.atlasdb.keyvalue.api.watch.Sequence in project atlasdb by palantir.
the class LockWatchValueScopingCacheImpl method updateStores.
/**
* In order to maintain the necessary invariants, we need to do the following:
*
* 1. For each new event, we apply it to the cache. The effects of this application is described in
* {@link LockWatchValueScopingCache}.
* 2. For each transaction, we must ensure that we store a snapshot of the cache at the sequence corresponding
* to the transaction's start timestamp. Note that not every sequence will have a corresponding timestamp, so we
* don't bother storing a snapshot for those sequences. Also note that we know that each call here will only
* ever have new events, and that consecutive calls to this method will *always* have increasing sequences
* (without this last guarantee, we'd need to store snapshots for all sequences).
* 3. For each transaction, we must create a transaction scoped cache. We do this now as we have tighter guarantees
* around when the cache is created, and thus deleted.
*/
private synchronized void updateStores(TransactionsLockWatchUpdate updateForTransactions) {
Multimap<Sequence, StartTimestamp> reversedMap = createSequenceTimestampMultimap(updateForTransactions);
// Without this block, updates with no events would not store a snapshot.
currentVersion.map(LockWatchVersion::version).map(Sequence::of).ifPresent(sequence -> snapshotStore.storeSnapshot(sequence, reversedMap.get(sequence), valueStore.getSnapshot()));
updateForTransactions.events().stream().filter(this::isNewEvent).forEach(event -> {
valueStore.applyEvent(event);
Sequence sequence = Sequence.of(event.sequence());
snapshotStore.storeSnapshot(sequence, reversedMap.get(sequence), valueStore.getSnapshot());
});
updateForTransactions.startTsToSequence().keySet().forEach(timestamp -> cacheStore.createCache(StartTimestamp.of(timestamp)));
if (valueStore.getSnapshot().hasAnyTablesWatched()) {
assertNoSnapshotsMissing(reversedMap);
}
}
Aggregations