Search in sources :

Example 1 with TransactionsLockWatchUpdate

use of com.palantir.lock.watch.TransactionsLockWatchUpdate 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 2 with TransactionsLockWatchUpdate

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

the class LockWatchEventCacheIntegrationTest method clientPartiallyUpToDateDoesNotThrow.

@Test
public void clientPartiallyUpToDateDoesNotThrow() {
    setupInitialState();
    eventCache.processStartTransactionsUpdate(TIMESTAMPS_2, SUCCESS);
    TransactionsLockWatchUpdate update = eventCache.getUpdateForTransactions(Sets.union(TIMESTAMPS, TIMESTAMPS_2), Optional.of(LockWatchVersion.of(LEADER, 5L)));
    assertThat(update.clearCache()).isFalse();
    assertThat(update.events().size()).isEqualTo(1);
    assertThat(update.startTsToSequence()).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(START_TS_1, LockWatchVersion.of(LEADER, 3L), START_TS_2, LockWatchVersion.of(LEADER, 6L)));
}
Also used : TransactionsLockWatchUpdate(com.palantir.lock.watch.TransactionsLockWatchUpdate) Test(org.junit.Test)

Example 3 with TransactionsLockWatchUpdate

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

the class ClientLogEventsTest method toTransactionsWithVeryOldClientVersion.

@Test
public void toTransactionsWithVeryOldClientVersion() {
    ClientLogEvents clientLogEvents = ClientLogEvents.builder().clearCache(true).events(EVENTS_2_TO_4).build();
    TimestampMapping mapping = createTimestampMappingWithSequences(SEQUENCE_2, SEQUENCE_4);
    TransactionsLockWatchUpdate update = clientLogEvents.toTransactionsLockWatchUpdate(mapping, Optional.of(VERSION_0));
    assertThat(update.events()).containsExactly(LOCK_DESCRIPTOR_2_VERSION_2, UNLOCK_DESCRIPTOR_2_VERSION_3, LOCK_DESCRIPTOR_1_VERSION_4);
}
Also used : TransactionsLockWatchUpdate(com.palantir.lock.watch.TransactionsLockWatchUpdate) Test(org.junit.Test)

Example 4 with TransactionsLockWatchUpdate

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

the class ClientLogEventsTest method toTransactionsWithOldClientVersion.

@Test
public void toTransactionsWithOldClientVersion() {
    TimestampMapping mapping = createTimestampMappingWithSequences(SEQUENCE_2, SEQUENCE_4);
    TransactionsLockWatchUpdate update = CLIENT_EVENTS_2_TO_4_NO_CLEAR_CACHE.toTransactionsLockWatchUpdate(mapping, Optional.of(VERSION_1));
    assertThat(update.events()).containsExactly(LOCK_DESCRIPTOR_2_VERSION_2, UNLOCK_DESCRIPTOR_2_VERSION_3, LOCK_DESCRIPTOR_1_VERSION_4);
}
Also used : TransactionsLockWatchUpdate(com.palantir.lock.watch.TransactionsLockWatchUpdate) Test(org.junit.Test)

Example 5 with TransactionsLockWatchUpdate

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

the class LockWatchValueScopingCacheImpl method processStartTransactions.

@Override
public synchronized void processStartTransactions(Set<Long> startTimestamps) {
    TransactionsLockWatchUpdate updateForTransactions = eventCache.getUpdateForTransactions(startTimestamps, currentVersion);
    Optional<LockWatchVersion> latestVersionFromUpdate = computeMaxUpdateVersion(updateForTransactions);
    if (updateForTransactions.clearCache()) {
        clearCache(updateForTransactions, latestVersionFromUpdate);
    }
    updateStores(updateForTransactions);
    updateCurrentVersion(latestVersionFromUpdate);
}
Also used : TransactionsLockWatchUpdate(com.palantir.lock.watch.TransactionsLockWatchUpdate) LockWatchVersion(com.palantir.lock.watch.LockWatchVersion)

Aggregations

TransactionsLockWatchUpdate (com.palantir.lock.watch.TransactionsLockWatchUpdate)19 Test (org.junit.Test)18 LockWatchVersion (com.palantir.lock.watch.LockWatchVersion)5 OpenTransaction (com.palantir.atlasdb.transaction.api.OpenTransaction)2 LockWatchEvent (com.palantir.lock.watch.LockWatchEvent)1 LockWatchStateUpdate (com.palantir.lock.watch.LockWatchStateUpdate)1 UUID (java.util.UUID)1