use of com.palantir.lock.watch.CommitUpdate in project atlasdb by palantir.
the class LockWatchValueScopingCacheImpl method onSuccessfulCommit.
@Override
public synchronized void onSuccessfulCommit(long startTimestamp) {
StartTimestamp startTs = StartTimestamp.of(startTimestamp);
TransactionScopedCache cache = cacheStore.getCache(startTs);
cache.finalise();
Map<CellReference, CacheValue> cachedValues = cache.getValueDigest().loadedValues();
if (!cachedValues.isEmpty()) {
CommitUpdate commitUpdate = eventCache.getEventUpdate(startTimestamp);
commitUpdate.accept(new CommitUpdate.Visitor<Void>() {
@Override
public Void invalidateAll() {
// because of read-write conflicts, that is handled in the PreCommitCondition.
return null;
}
@Override
public Void invalidateSome(Set<LockDescriptor> invalidatedLocks) {
Set<CellReference> invalidatedCells = invalidatedLocks.stream().map(AtlasLockDescriptorUtils::candidateCells).flatMap(List::stream).collect(Collectors.toSet());
KeyedStream.stream(cachedValues).filterKeys(cellReference -> !invalidatedCells.contains(cellReference)).forEach(valueStore::putValue);
return null;
}
});
}
ensureStateRemoved(startTimestamp);
}
use of com.palantir.lock.watch.CommitUpdate in project atlasdb by palantir.
the class ClientLogEventsTest method toCommitUpdateDoesNotFilterOutBasedOnNonLeasedLockTokens.
@Test
public void toCommitUpdateDoesNotFilterOutBasedOnNonLeasedLockTokens() {
// due to how the commit flow works, the filtering is only done if it is a leased lock token
TimestampStateStore.CommitInfo commitInfo = TimestampStateStore.CommitInfo.of(LOCK_TOKEN_1, VERSION_1);
CommitUpdate commitUpdate = CLIENT_EVENTS_2_TO_4_NO_CLEAR_CACHE.toCommitUpdate(VERSION_1, VERSION_4, Optional.of(commitInfo));
Set<LockDescriptor> lockDescriptors = extractLockDescriptors(commitUpdate);
assertThat(lockDescriptors).containsExactlyInAnyOrder(DESCRIPTOR_1, DESCRIPTOR_2);
}
use of com.palantir.lock.watch.CommitUpdate in project atlasdb by palantir.
the class LockWatchValueScopingCacheImpl method processCommitUpdate.
private synchronized void processCommitUpdate(long startTimestamp) {
StartTimestamp startTs = StartTimestamp.of(startTimestamp);
TransactionScopedCache cache = cacheStore.getCache(startTs);
cache.finalise();
CommitUpdate commitUpdate = eventCache.getCommitUpdate(startTimestamp);
cacheStore.createReadOnlyCache(startTs, commitUpdate);
}
use of com.palantir.lock.watch.CommitUpdate in project atlasdb by palantir.
the class LockWatchEventCacheIntegrationTest method getCommitUpdateIsInvalidateSomeAsEventsAreRetained.
@Test
public void getCommitUpdateIsInvalidateSomeAsEventsAreRetained() {
createEventCache(2);
setupInitialState();
eventCache.processGetCommitTimestampsUpdate(COMMIT_UPDATE, SUCCESS);
eventCache.processStartTransactionsUpdate(ImmutableSet.of(), SUCCESS_2);
verifyStage();
CommitUpdate commitUpdate = eventCache.getCommitUpdate(START_TS_1);
assertThat(commitUpdate.accept(new CommitUpdateVisitor())).containsExactlyInAnyOrder(DESCRIPTOR, DESCRIPTOR_3);
eventCache.removeTransactionStateFromCache(START_TS_1);
verifyStage();
}
use of com.palantir.lock.watch.CommitUpdate in project atlasdb by palantir.
the class ClientLogEventsTest method toCommitUpdateFiltersOutLockEventsWithMatchingLockToken.
@Test
public void toCommitUpdateFiltersOutLockEventsWithMatchingLockToken() {
// due to how the commit flow works, the filtering is only done if it is a leased lock token
LeasedLockToken leasedLockToken = mock(LeasedLockToken.class);
when(leasedLockToken.serverToken()).thenReturn(CONJURE_TOKEN_1);
TimestampStateStore.CommitInfo commitInfo = TimestampStateStore.CommitInfo.of(leasedLockToken, VERSION_1);
CommitUpdate commitUpdate = CLIENT_EVENTS_2_TO_4_NO_CLEAR_CACHE.toCommitUpdate(VERSION_1, VERSION_4, Optional.of(commitInfo));
Set<LockDescriptor> lockDescriptors = extractLockDescriptors(commitUpdate);
assertThat(lockDescriptors).containsExactlyInAnyOrder(DESCRIPTOR_1);
}
Aggregations