Search in sources :

Example 1 with CommitUpdate

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);
}
Also used : CommitUpdate(com.palantir.lock.watch.CommitUpdate) Set(java.util.Set) StartTimestamp(com.palantir.atlasdb.keyvalue.api.watch.StartTimestamp) CellReference(com.palantir.atlasdb.keyvalue.api.CellReference) LockDescriptor(com.palantir.lock.LockDescriptor) List(java.util.List)

Example 2 with CommitUpdate

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);
}
Also used : LockDescriptor(com.palantir.lock.LockDescriptor) StringLockDescriptor(com.palantir.lock.StringLockDescriptor) CommitUpdate(com.palantir.lock.watch.CommitUpdate) Test(org.junit.Test)

Example 3 with CommitUpdate

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);
}
Also used : CommitUpdate(com.palantir.lock.watch.CommitUpdate) StartTimestamp(com.palantir.atlasdb.keyvalue.api.watch.StartTimestamp)

Example 4 with 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();
}
Also used : CommitUpdate(com.palantir.lock.watch.CommitUpdate) Test(org.junit.Test)

Example 5 with CommitUpdate

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);
}
Also used : LockDescriptor(com.palantir.lock.LockDescriptor) StringLockDescriptor(com.palantir.lock.StringLockDescriptor) CommitUpdate(com.palantir.lock.watch.CommitUpdate) LeasedLockToken(com.palantir.lock.client.LeasedLockToken) Test(org.junit.Test)

Aggregations

CommitUpdate (com.palantir.lock.watch.CommitUpdate)8 Test (org.junit.Test)6 LockDescriptor (com.palantir.lock.LockDescriptor)5 StringLockDescriptor (com.palantir.lock.StringLockDescriptor)4 StartTimestamp (com.palantir.atlasdb.keyvalue.api.watch.StartTimestamp)2 CellReference (com.palantir.atlasdb.keyvalue.api.CellReference)1 LeasedLockToken (com.palantir.lock.client.LeasedLockToken)1 LockWatchVersion (com.palantir.lock.watch.LockWatchVersion)1 List (java.util.List)1 Set (java.util.Set)1