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);
}
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();
}
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);
}
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());
}
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());
}
Aggregations