Search in sources :

Example 1 with LockWatchVersion

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

the class LockWatchEventCacheImpl method getCommitUpdate.

@Override
public CommitUpdate getCommitUpdate(long startTs) {
    Optional<TimestampStateStore.TimestampVersionInfo> timestampInfo = timestampStateStore.getTimestampInfo(startTs);
    Optional<LockWatchVersion> startVersion = timestampInfo.map(TimestampStateStore.TimestampVersionInfo::version);
    Optional<CommitInfo> maybeCommitInfo = timestampInfo.flatMap(TimestampStateStore.TimestampVersionInfo::commitInfo);
    assertTrue(maybeCommitInfo.isPresent() && startVersion.isPresent(), "start or commit info not processed for start timestamp");
    CommitInfo commitInfo = maybeCommitInfo.get();
    VersionBounds versionBounds = VersionBounds.builder().startVersion(startVersion).endVersion(commitInfo.commitVersion()).build();
    return eventLog.getEventsBetweenVersions(versionBounds).toCommitUpdate(startVersion.get(), commitInfo.commitVersion(), maybeCommitInfo);
}
Also used : LockWatchVersion(com.palantir.lock.watch.LockWatchVersion) CommitInfo(com.palantir.atlasdb.keyvalue.api.watch.TimestampStateStore.CommitInfo)

Example 2 with LockWatchVersion

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

the class LockWatchEventLogTest method getEventsBetweenVersionsWithUpToDateVersionsReturnsNoEvents.

@Test
public void getEventsBetweenVersionsWithUpToDateVersionsReturnsNoEvents() {
    processInitialSnapshotAndSuccessUpToVersionFour();
    LockWatchVersion initialLeaderAtSequenceFour = LockWatchVersion.of(INITIAL_LEADER, SEQUENCE_4);
    ClientLogEvents events = eventLog.getEventsBetweenVersions(VersionBounds.builder().startVersion(initialLeaderAtSequenceFour).endVersion(initialLeaderAtSequenceFour).build());
    assertThat(events.clearCache()).isFalse();
    assertThat(events.events().events()).isEmpty();
}
Also used : LockWatchVersion(com.palantir.lock.watch.LockWatchVersion) Test(org.junit.Test)

Example 3 with LockWatchVersion

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

the class LockWatchEventLogTest method successUpdateWithNoEventsDoesNotThrow.

@Test
public void successUpdateWithNoEventsDoesNotThrow() {
    eventLog.processUpdate(INITIAL_SNAPSHOT_VERSION_1);
    CacheUpdate cacheUpdate = eventLog.processUpdate(LockWatchStateUpdate.success(INITIAL_LEADER, SEQUENCE_1, ImmutableList.of()));
    LockWatchVersion initialLeaderAtSequenceOne = LockWatchVersion.of(INITIAL_LEADER, SEQUENCE_1);
    assertThat(cacheUpdate.shouldClearCache()).isFalse();
    assertThat(cacheUpdate.getVersion()).hasValue(initialLeaderAtSequenceOne);
}
Also used : LockWatchVersion(com.palantir.lock.watch.LockWatchVersion) Test(org.junit.Test)

Example 4 with LockWatchVersion

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

the class LockWatchEventLogTest method successUpdateWithOverlappingEventsOnlyAppliesNewEvents.

@Test
public void successUpdateWithOverlappingEventsOnlyAppliesNewEvents() {
    eventLog.processUpdate(INITIAL_SNAPSHOT_VERSION_1);
    eventLog.processUpdate(LockWatchStateUpdate.success(INITIAL_LEADER, SEQUENCE_3, ImmutableList.of(LOCK_DESCRIPTOR_2_VERSION_2, UNLOCK_DESCRIPTOR_1_VERSION_3)));
    LockWatchVersion initialLeaderAtSequenceFour = LockWatchVersion.of(INITIAL_LEADER, SEQUENCE_4);
    CacheUpdate spanningUpdate = eventLog.processUpdate(SUCCESS_VERSION_2_TO_4);
    assertThat(spanningUpdate.shouldClearCache()).isFalse();
    assertThat(spanningUpdate.getVersion()).hasValue(initialLeaderAtSequenceFour);
    assertThat(eventLog.getLatestKnownVersion()).hasValue(initialLeaderAtSequenceFour);
    assertThat(eventLog.getStateForTesting()).isEqualTo(ImmutableLockWatchEventLogState.builder().latestVersion(initialLeaderAtSequenceFour).snapshotState(SNAPSHOT_STATE_VERSION_1).eventStoreState(ImmutableVersionedEventStoreState.builder().eventMap(ImmutableSortedMap.of(Sequence.of(SEQUENCE_2), LOCK_DESCRIPTOR_2_VERSION_2, Sequence.of(SEQUENCE_3), UNLOCK_DESCRIPTOR_1_VERSION_3, Sequence.of(SEQUENCE_4), LOCK_DESCRIPTOR_1_VERSION_4)).build()).build());
}
Also used : LockWatchVersion(com.palantir.lock.watch.LockWatchVersion) Test(org.junit.Test)

Example 5 with LockWatchVersion

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

the class LockWatchEventLogTest method snapshotUpdateSetsContextAndInstructsClientsToClearCache.

@Test
public void snapshotUpdateSetsContextAndInstructsClientsToClearCache() {
    CacheUpdate cacheUpdate = eventLog.processUpdate(INITIAL_SNAPSHOT_VERSION_1);
    LockWatchVersion initialLeaderAtSequenceOne = LockWatchVersion.of(INITIAL_LEADER, SEQUENCE_1);
    assertThat(cacheUpdate.shouldClearCache()).isTrue();
    assertThat(cacheUpdate.getVersion()).hasValue(initialLeaderAtSequenceOne);
    assertThat(eventLog.getLatestKnownVersion()).hasValue(initialLeaderAtSequenceOne);
    assertThat(eventLog.getStateForTesting()).isEqualTo(ImmutableLockWatchEventLogState.builder().latestVersion(initialLeaderAtSequenceOne).snapshotState(SNAPSHOT_STATE_VERSION_1).eventStoreState(EMPTY_EVENT_STORE_STATE).build());
}
Also used : LockWatchVersion(com.palantir.lock.watch.LockWatchVersion) Test(org.junit.Test)

Aggregations

LockWatchVersion (com.palantir.lock.watch.LockWatchVersion)23 Test (org.junit.Test)16 TransactionsLockWatchUpdate (com.palantir.lock.watch.TransactionsLockWatchUpdate)5 OpenTransaction (com.palantir.atlasdb.transaction.api.OpenTransaction)2 LockWatchEvent (com.palantir.lock.watch.LockWatchEvent)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1 Autobatchers (com.palantir.atlasdb.autobatch.Autobatchers)1 BatchElement (com.palantir.atlasdb.autobatch.BatchElement)1 DisruptorAutobatcher (com.palantir.atlasdb.autobatch.DisruptorAutobatcher)1 AtlasFutures (com.palantir.atlasdb.futures.AtlasFutures)1 Sequence (com.palantir.atlasdb.keyvalue.api.watch.Sequence)1 StartTimestamp (com.palantir.atlasdb.keyvalue.api.watch.StartTimestamp)1 CommitInfo (com.palantir.atlasdb.keyvalue.api.watch.TimestampStateStore.CommitInfo)1 ConjureStartTransactionsResponse (com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse)1 Throwables (com.palantir.common.base.Throwables)1 LockDescriptor (com.palantir.lock.LockDescriptor)1 StringLockDescriptor (com.palantir.lock.StringLockDescriptor)1 LockToken (com.palantir.lock.v2.LockToken)1 StartIdentifiedAtlasDbTransactionResponse (com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse)1