Search in sources :

Example 6 with LockWatchReference

use of com.palantir.lock.watch.LockWatchReferences.LockWatchReference in project atlasdb by palantir.

the class LockWatchingServiceImpl method filterNewWatches.

private Optional<LockWatches> filterNewWatches(LockWatchRequest request, LockWatches oldWatches) {
    Set<LockWatchReference> newRefs = new HashSet<>();
    RangeSet<LockDescriptor> newRanges = TreeRangeSet.create();
    for (LockWatchReference singleReference : request.getReferences()) {
        Range<LockDescriptor> referenceAsRange = singleReference.accept(LockWatchReferences.TO_RANGES_VISITOR);
        if (!oldWatches.ranges().encloses(referenceAsRange)) {
            newRefs.add(singleReference);
            newRanges.add(referenceAsRange);
        }
    }
    return newRefs.isEmpty() ? Optional.empty() : Optional.of(ImmutableLockWatches.of(newRefs, newRanges));
}
Also used : LockDescriptor(com.palantir.lock.LockDescriptor) LockWatchReference(com.palantir.lock.watch.LockWatchReferences.LockWatchReference) HashSet(java.util.HashSet)

Example 7 with LockWatchReference

use of com.palantir.lock.watch.LockWatchReferences.LockWatchReference in project atlasdb by palantir.

the class LockEventLogImplTest method requestForTheFutureReturnsSnapshot.

@Test
public void requestForTheFutureReturnsSnapshot() {
    LockWatchReference entireTable = LockWatchReferenceUtils.entireTable(TABLE_REF);
    lockWatches.set(createWatchesFor(entireTable));
    LockWatchStateUpdate update = log.getLogDiff(FUTURE_VERSION_CURRENT_LOG_ID);
    LockWatchStateUpdate.Snapshot snapshot = UpdateVisitors.assertSnapshot(update);
    assertThat(snapshot.lastKnownVersion()).isEqualTo(-1L);
    assertThat(snapshot.locked()).containsExactlyInAnyOrder(DESCRIPTOR_2, DESCRIPTOR_3);
    assertThat(snapshot.lockWatches()).containsExactly(entireTable);
}
Also used : LockWatchStateUpdate(com.palantir.lock.watch.LockWatchStateUpdate) LockWatchReference(com.palantir.lock.watch.LockWatchReferences.LockWatchReference) Test(org.junit.Test)

Example 8 with LockWatchReference

use of com.palantir.lock.watch.LockWatchReferences.LockWatchReference in project atlasdb by palantir.

the class LockWatchingServiceImplTest method registeringWatchWithOverlappingScopeLogsAlreadyWatchedLocksInScopeAgain.

@Test
public void registeringWatchWithOverlappingScopeLogsAlreadyWatchedLocksInScopeAgain() {
    LockDescriptor ab = AtlasRowLockDescriptor.of(TABLE.getQualifiedName(), PtBytes.toBytes("ab"));
    LockDescriptor bc = AtlasRowLockDescriptor.of(TABLE.getQualifiedName(), PtBytes.toBytes("bc"));
    LockDescriptor cd = AtlasRowLockDescriptor.of(TABLE.getQualifiedName(), PtBytes.toBytes("cd"));
    when(heldLocks.getLocks()).thenReturn(ImmutableList.of(LOCK, new ExclusiveLock(ab), new ExclusiveLock(bc), new ExclusiveLock(cd)));
    LockWatchReference acRange = LockWatchReferenceUtils.rowRange(TABLE, PtBytes.toBytes("a"), PtBytes.toBytes("c"));
    LockWatchReference bdRange = LockWatchReferenceUtils.rowRange(TABLE, PtBytes.toBytes("b"), PtBytes.toBytes("d"));
    lockWatcher.startWatching(LockWatchRequest.of(ImmutableSet.of(acRange)));
    lockWatcher.startWatching(LockWatchRequest.of(ImmutableSet.of(bdRange)));
    List<LockWatchEvent> expectedEvents = ImmutableList.of(createdEvent(ImmutableSet.of(acRange), ImmutableSet.of(ab, bc)), createdEvent(ImmutableSet.of(bdRange), ImmutableSet.of(bc, cd)));
    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) LockWatchReference(com.palantir.lock.watch.LockWatchReferences.LockWatchReference) Test(org.junit.Test)

Example 9 with LockWatchReference

use of com.palantir.lock.watch.LockWatchReferences.LockWatchReference in project atlasdb by palantir.

the class LockWatchingServiceImplTest method onlyAlreadyWatchedRangesAreIgnoredOnRegistration.

@Test
public void onlyAlreadyWatchedRangesAreIgnoredOnRegistration() {
    LockWatchRequest request = tableRequest();
    lockWatcher.startWatching(request);
    LockWatchReference newWatch = LockWatchReferenceUtils.entireTable(TABLE_2);
    LockWatchRequest prefixAndOtherTableRequest = LockWatchRequest.of(ImmutableSet.of(LockWatchReferenceUtils.rowPrefix(TABLE, ROW), newWatch));
    lockWatcher.startWatching(prefixAndOtherTableRequest);
    List<LockWatchEvent> expectedEvents = ImmutableList.of(createdEvent(request.getReferences(), ImmutableSet.of(ROW_DESCRIPTOR)), createdEvent(ImmutableSet.of(newWatch), ImmutableSet.of(descriptorForOtherTable())));
    assertLoggedEvents(expectedEvents);
}
Also used : LockWatchEvent(com.palantir.lock.watch.LockWatchEvent) LockWatchRequest(com.palantir.atlasdb.timelock.api.LockWatchRequest) LockWatchReference(com.palantir.lock.watch.LockWatchReferences.LockWatchReference) Test(org.junit.Test)

Aggregations

LockWatchReference (com.palantir.lock.watch.LockWatchReferences.LockWatchReference)9 Test (org.junit.Test)7 LockWatchStateUpdate (com.palantir.lock.watch.LockWatchStateUpdate)5 LockWatchRequest (com.palantir.atlasdb.timelock.api.LockWatchRequest)2 LockDescriptor (com.palantir.lock.LockDescriptor)2 LockWatchEvent (com.palantir.lock.watch.LockWatchEvent)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 LockWatchCachingConfig (com.palantir.atlasdb.keyvalue.api.LockWatchCachingConfig)1 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)1 CacheMetrics (com.palantir.atlasdb.keyvalue.api.cache.CacheMetrics)1 LockWatchValueScopingCache (com.palantir.atlasdb.keyvalue.api.cache.LockWatchValueScopingCache)1 LockWatchValueScopingCacheImpl (com.palantir.atlasdb.keyvalue.api.cache.LockWatchValueScopingCacheImpl)1 TransactionScopedCache (com.palantir.atlasdb.keyvalue.api.cache.TransactionScopedCache)1 Schema (com.palantir.atlasdb.table.description.Schema)1 ExclusiveLock (com.palantir.atlasdb.timelock.lock.ExclusiveLock)1 MetricsManager (com.palantir.atlasdb.util.MetricsManager)1 PTExecutors (com.palantir.common.concurrent.PTExecutors)1 AtlasCellLockDescriptor (com.palantir.lock.AtlasCellLockDescriptor)1 AtlasRowLockDescriptor (com.palantir.lock.AtlasRowLockDescriptor)1 LockWatchStarter (com.palantir.lock.client.LockWatchStarter)1