Search in sources :

Example 1 with LockWatchEvent

use of com.palantir.lock.watch.LockWatchEvent in project atlasdb by palantir.

the class LockWatchValueScopingCacheImpl method clearCache.

private synchronized void clearCache(TransactionsLockWatchUpdate updateForTransactions, Optional<LockWatchVersion> latestVersionFromUpdate) {
    LockWatchEvent firstEvent = null;
    LockWatchEvent lastEvent = null;
    List<LockWatchEvent> events = updateForTransactions.events();
    if (!events.isEmpty()) {
        firstEvent = events.get(0);
        lastEvent = events.get(events.size() - 1);
    }
    log.info("Clearing all value cache state", SafeArg.of("currentVersion", currentVersion), SafeArg.of("latestUpdateFromUpdate", latestVersionFromUpdate), SafeArg.of("firstEventSequence", firstEvent), SafeArg.of("lastEventSequence", lastEvent));
    valueStore.reset();
    snapshotStore.reset();
    cacheStore.reset();
    currentVersion = Optional.empty();
}
Also used : LockWatchEvent(com.palantir.lock.watch.LockWatchEvent)

Example 2 with LockWatchEvent

use of com.palantir.lock.watch.LockWatchEvent in project atlasdb by palantir.

the class LockWatchEventCacheImplTest method getUpdateForTransactionsReturnsOnlyRelevantEventsForBatch.

@Test
public void getUpdateForTransactionsReturnsOnlyRelevantEventsForBatch() {
    eventCache.processStartTransactionsUpdate(ImmutableSet.of(TIMESTAMP_1), SNAPSHOT_VERSION_1);
    eventCache.processStartTransactionsUpdate(ImmutableSet.of(TIMESTAMP_2), SUCCESS_VERSION_2);
    eventCache.processStartTransactionsUpdate(ImmutableSet.of(TIMESTAMP_3), SUCCESS_VERSION_3);
    verify(eventLog).processUpdate(SNAPSHOT_VERSION_1);
    verify(eventLog).processUpdate(SUCCESS_VERSION_2);
    verify(eventLog).processUpdate(SUCCESS_VERSION_3);
    TransactionsLockWatchUpdate update = eventCache.getUpdateForTransactions(ImmutableSet.of(TIMESTAMP_1, TIMESTAMP_2), Optional.empty());
    // This event is effectively a snapshot, and is used as such by the event cache
    LockWatchEvent snapshotEventAtSequence1 = LockWatchCreatedEvent.builder(ImmutableSet.of(REFERENCE_1), ImmutableSet.of(DESCRIPTOR_1)).build(SEQUENCE_1);
    assertThat(update.clearCache()).as("must clear cache due to no past user version").isTrue();
    assertThat(update.events()).as("snapshot up to earliest sequence corresponding to a timestamp, then events up to latest known" + " version").containsExactly(snapshotEventAtSequence1, LOCK_DESCRIPTOR_2_VERSION_2);
    assertThat(update.startTsToSequence()).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(TIMESTAMP_1, VERSION_1, TIMESTAMP_2, VERSION_2));
}
Also used : TransactionsLockWatchUpdate(com.palantir.lock.watch.TransactionsLockWatchUpdate) LockWatchEvent(com.palantir.lock.watch.LockWatchEvent) Test(org.junit.Test)

Example 3 with LockWatchEvent

use of com.palantir.lock.watch.LockWatchEvent in project atlasdb by palantir.

the class LockWatchEventCacheIntegrationTest method emptySuccessesFollowingSnapshotsDoNotCauseAdditionalCacheClearance.

@Test
public void emptySuccessesFollowingSnapshotsDoNotCauseAdditionalCacheClearance() {
    LockWatchStateUpdate snapshot = LockWatchStateUpdate.snapshot(LEADER, 3L, ImmutableSet.of(DESCRIPTOR_2), ImmutableSet.of());
    LockWatchStateUpdate emptySuccess = LockWatchStateUpdate.success(LEADER, 3L, ImmutableList.of());
    LockWatchEvent lockEvent = LockEvent.builder(ImmutableSet.of(DESCRIPTOR_3), COMMIT_TOKEN).build(4L);
    LockWatchStateUpdate success = LockWatchStateUpdate.success(LEADER, 4L, ImmutableList.of(lockEvent));
    setupInitialState();
    verifyStage();
    eventCache.processStartTransactionsUpdate(ImmutableSet.of(1L), snapshot);
    verifyStage();
    assertThat(eventCache.getUpdateForTransactions(ImmutableSet.of(1L), Optional.of(LockWatchVersion.of(LEADER, 2L))).clearCache()).isTrue();
    assertThat(eventCache.getUpdateForTransactions(ImmutableSet.of(1L), Optional.of(LockWatchVersion.of(LEADER, 3L))).clearCache()).isFalse();
    eventCache.processStartTransactionsUpdate(ImmutableSet.of(2L), emptySuccess);
    verifyStage();
    assertThat(eventCache.getUpdateForTransactions(ImmutableSet.of(2L), Optional.of(LockWatchVersion.of(LEADER, 3L))).clearCache()).isFalse();
    eventCache.processStartTransactionsUpdate(ImmutableSet.of(3L), emptySuccess);
    verifyStage();
    assertThat(eventCache.getUpdateForTransactions(ImmutableSet.of(3L), Optional.of(LockWatchVersion.of(LEADER, 3L))).clearCache()).isFalse();
    eventCache.processStartTransactionsUpdate(ImmutableSet.of(99L), success);
    verifyStage();
    assertThat(eventCache.getUpdateForTransactions(ImmutableSet.of(99L), Optional.of(LockWatchVersion.of(LEADER, 3L))).events()).containsExactly(lockEvent);
    assertThat(eventCache.getUpdateForTransactions(ImmutableSet.of(99L), Optional.of(LockWatchVersion.of(LEADER, 4L))).events()).isEmpty();
}
Also used : LockWatchStateUpdate(com.palantir.lock.watch.LockWatchStateUpdate) LockWatchEvent(com.palantir.lock.watch.LockWatchEvent) Test(org.junit.Test)

Example 4 with LockWatchEvent

use of com.palantir.lock.watch.LockWatchEvent in project atlasdb by palantir.

the class LockWatchEventLogTest method successUpdateUpdatesContextAndShouldInstructClientsNotToClearCache.

@Test
public void successUpdateUpdatesContextAndShouldInstructClientsNotToClearCache() {
    eventLog.processUpdate(INITIAL_SNAPSHOT_VERSION_1);
    LockWatchEvent lockEvent = LockEvent.builder(ImmutableSet.of(DESCRIPTOR_2), LOCK_TOKEN).build(SEQUENCE_2);
    CacheUpdate cacheUpdate = eventLog.processUpdate(LockWatchStateUpdate.success(INITIAL_LEADER, SEQUENCE_2, ImmutableList.of(lockEvent)));
    LockWatchVersion initialLeaderAtSequenceTwo = LockWatchVersion.of(INITIAL_LEADER, SEQUENCE_2);
    assertThat(cacheUpdate.shouldClearCache()).isFalse();
    assertThat(cacheUpdate.getVersion()).hasValue(initialLeaderAtSequenceTwo);
    assertThat(eventLog.getLatestKnownVersion()).hasValue(initialLeaderAtSequenceTwo);
    assertThat(eventLog.getStateForTesting()).isEqualTo(ImmutableLockWatchEventLogState.builder().latestVersion(initialLeaderAtSequenceTwo).snapshotState(SNAPSHOT_STATE_VERSION_1).eventStoreState(ImmutableVersionedEventStoreState.builder().eventMap(ImmutableSortedMap.of(Sequence.of(SEQUENCE_2), lockEvent)).build()).build());
}
Also used : LockWatchVersion(com.palantir.lock.watch.LockWatchVersion) LockWatchEvent(com.palantir.lock.watch.LockWatchEvent) Test(org.junit.Test)

Example 5 with LockWatchEvent

use of com.palantir.lock.watch.LockWatchEvent in project atlasdb by palantir.

the class LockWatchingServiceImplTest method registeringWatchWithWiderScopeLogsAlreadyWatchedLocksAgain.

@Test
public void registeringWatchWithWiderScopeLogsAlreadyWatchedLocksAgain() {
    LockDescriptor secondRow = AtlasRowLockDescriptor.of(TABLE.getQualifiedName(), PtBytes.toBytes("other_row"));
    when(heldLocks.getLocks()).thenReturn(ImmutableList.of(LOCK, new ExclusiveLock(secondRow)));
    LockWatchRequest prefixRequest = prefixRequest(ROW);
    lockWatcher.startWatching(prefixRequest);
    LockWatchRequest entireTableRequest = tableRequest();
    lockWatcher.startWatching(entireTableRequest);
    List<LockWatchEvent> expectedEvents = ImmutableList.of(createdEvent(prefixRequest.getReferences(), ImmutableSet.of(ROW_DESCRIPTOR)), createdEvent(entireTableRequest.getReferences(), ImmutableSet.of(ROW_DESCRIPTOR, secondRow)));
    assertLoggedEvents(expectedEvents);
}
Also used : LockDescriptor(com.palantir.lock.LockDescriptor) AtlasCellLockDescriptor(com.palantir.lock.AtlasCellLockDescriptor) AtlasRowLockDescriptor(com.palantir.lock.AtlasRowLockDescriptor) ExclusiveLock(com.palantir.atlasdb.timelock.lock.ExclusiveLock) LockWatchEvent(com.palantir.lock.watch.LockWatchEvent) LockWatchRequest(com.palantir.atlasdb.timelock.api.LockWatchRequest) Test(org.junit.Test)

Aggregations

LockWatchEvent (com.palantir.lock.watch.LockWatchEvent)20 Test (org.junit.Test)16 LockWatchRequest (com.palantir.atlasdb.timelock.api.LockWatchRequest)10 AtlasCellLockDescriptor (com.palantir.lock.AtlasCellLockDescriptor)7 AtlasRowLockDescriptor (com.palantir.lock.AtlasRowLockDescriptor)7 LockDescriptor (com.palantir.lock.LockDescriptor)7 LockWatchStateUpdate (com.palantir.lock.watch.LockWatchStateUpdate)3 ExclusiveLock (com.palantir.atlasdb.timelock.lock.ExclusiveLock)2 LockWatchReference (com.palantir.lock.watch.LockWatchReferences.LockWatchReference)2 LockWatchVersion (com.palantir.lock.watch.LockWatchVersion)2 TransactionLockWatchFailedException (com.palantir.atlasdb.transaction.api.TransactionLockWatchFailedException)1 TransactionsLockWatchUpdate (com.palantir.lock.watch.TransactionsLockWatchUpdate)1