Search in sources :

Example 6 with LockWatchEvent

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

the class LockWatchingServiceImplTest method exactCellWatchMatchesExactDescriptorOnly.

@Test
public void exactCellWatchMatchesExactDescriptorOnly() {
    LockDescriptor cellSuffixDescriptor = AtlasCellLockDescriptor.of(TABLE.getQualifiedName(), CELL.getRowName(), PtBytes.toBytes("col2"));
    LockWatchRequest request = LockWatchRequest.of(ImmutableSet.of(LockWatchReferenceUtils.exactCell(TABLE, CELL)));
    lockWatcher.startWatching(request);
    ImmutableSet<LockDescriptor> locks = ImmutableSet.of(CELL_DESCRIPTOR, cellSuffixDescriptor);
    lockWatcher.registerLock(locks, TOKEN);
    List<LockWatchEvent> expectedEvents = ImmutableList.of(createdEvent(request.getReferences(), ImmutableSet.of()), lockEvent(ImmutableSet.of(CELL_DESCRIPTOR)));
    assertLoggedEvents(expectedEvents);
}
Also used : LockDescriptor(com.palantir.lock.LockDescriptor) AtlasCellLockDescriptor(com.palantir.lock.AtlasCellLockDescriptor) AtlasRowLockDescriptor(com.palantir.lock.AtlasRowLockDescriptor) LockWatchEvent(com.palantir.lock.watch.LockWatchEvent) LockWatchRequest(com.palantir.atlasdb.timelock.api.LockWatchRequest) Test(org.junit.Test)

Example 7 with LockWatchEvent

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

the class LockWatchingServiceImplTest method unlockWithoutLockTest.

@Test
public void unlockWithoutLockTest() {
    LockWatchRequest tableRequest = tableRequest();
    lockWatcher.startWatching(tableRequest);
    lockWatcher.registerUnlock(ImmutableSet.of(CELL_DESCRIPTOR));
    List<LockWatchEvent> expectedEvents = ImmutableList.of(createdEvent(tableRequest.getReferences(), ImmutableSet.of(ROW_DESCRIPTOR)), unlockEvent(ImmutableSet.of(CELL_DESCRIPTOR)));
    assertLoggedEvents(expectedEvents);
}
Also used : LockWatchEvent(com.palantir.lock.watch.LockWatchEvent) LockWatchRequest(com.palantir.atlasdb.timelock.api.LockWatchRequest) Test(org.junit.Test)

Example 8 with LockWatchEvent

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

the class LockWatchingServiceImplTest method registeringWatchWithNarrowerScopeIsNoop.

@Test
public void registeringWatchWithNarrowerScopeIsNoop() {
    LockWatchRequest request = tableRequest();
    lockWatcher.startWatching(request);
    LockWatchRequest prefixRequest = prefixRequest(ROW);
    lockWatcher.startWatching(prefixRequest);
    List<LockWatchEvent> expectedEvents = ImmutableList.of(createdEvent(request.getReferences(), ImmutableSet.of(ROW_DESCRIPTOR)));
    assertLoggedEvents(expectedEvents);
}
Also used : LockWatchEvent(com.palantir.lock.watch.LockWatchEvent) LockWatchRequest(com.palantir.atlasdb.timelock.api.LockWatchRequest) Test(org.junit.Test)

Example 9 with LockWatchEvent

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

the class ArrayLockEventSlidingWindow method add.

void add(LockWatchEvent.Builder eventBuilder) {
    LockWatchEvent event = eventBuilder.build(nextSequence);
    buffer[LongMath.mod(nextSequence, maxSize)] = event;
    nextSequence++;
}
Also used : LockWatchEvent(com.palantir.lock.watch.LockWatchEvent)

Example 10 with LockWatchEvent

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

the class LockWatchEventLog method getEventsBetweenVersionsInternal.

private ClientLogEvents getEventsBetweenVersionsInternal(VersionBounds versionBounds) {
    Optional<LockWatchVersion> startVersion = versionBounds.startVersion().map(this::createStartVersion);
    LockWatchVersion currentVersion = getLatestVersionAndVerify(versionBounds.endVersion());
    if (startVersion.isEmpty() || differentLeaderOrTooFarBehind(currentVersion, versionBounds.startVersion().get(), startVersion.get())) {
        long snapshotVersion = versionBounds.snapshotVersion() + 1;
        Collection<LockWatchEvent> afterSnapshotEvents;
        if (snapshotVersion > versionBounds.endVersion().version()) {
            afterSnapshotEvents = ImmutableList.of();
        } else {
            afterSnapshotEvents = eventStore.getEventsBetweenVersionsInclusive(Optional.of(snapshotVersion), versionBounds.endVersion().version());
        }
        return ClientLogEvents.builder().clearCache(true).events(LockWatchEvents.builder().addEvents(getCompressedSnapshot(versionBounds)).addAllEvents(afterSnapshotEvents).build()).build();
    } else {
        versionBounds.startVersion().ifPresent(version -> Preconditions.checkState(version.version() <= versionBounds.endVersion().version(), "Cannot get update for transactions when the last known version is more recent than the " + "transactions"));
        return ClientLogEvents.builder().clearCache(false).events(LockWatchEvents.builder().addAllEvents(eventStore.getEventsBetweenVersionsInclusive(Optional.of(startVersion.get().version()), versionBounds.endVersion().version())).build()).build();
    }
}
Also used : LockWatchVersion(com.palantir.lock.watch.LockWatchVersion) LockWatchEvent(com.palantir.lock.watch.LockWatchEvent)

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