Search in sources :

Example 1 with LockWatchReference

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

the class LockWatchManagerImpl method create.

public static LockWatchManagerInternal create(MetricsManager metricsManager, Set<Schema> schemas, LockWatchStarter lockWatchingService, LockWatchCachingConfig config) {
    Set<LockWatchReference> referencesFromSchema = schemas.stream().map(Schema::getLockWatches).flatMap(Set::stream).collect(Collectors.toSet());
    Set<TableReference> watchedTablesFromSchema = referencesFromSchema.stream().map(schema -> schema.accept(LockWatchReferencesVisitor.INSTANCE)).collect(Collectors.toSet());
    CacheMetrics metrics = CacheMetrics.create(metricsManager);
    LockWatchEventCache eventCache = LockWatchEventCacheImpl.create(metrics);
    LockWatchValueScopingCache valueCache = LockWatchValueScopingCacheImpl.create(eventCache, metrics, config.cacheSize(), config.validationProbability(), watchedTablesFromSchema);
    return new LockWatchManagerImpl(referencesFromSchema, eventCache, valueCache, lockWatchingService);
}
Also used : SafeLoggerFactory(com.palantir.logsafe.logger.SafeLoggerFactory) ScheduledFuture(java.util.concurrent.ScheduledFuture) LockWatchRequest(com.palantir.atlasdb.timelock.api.LockWatchRequest) CommitUpdate(com.palantir.lock.watch.CommitUpdate) SafeLogger(com.palantir.logsafe.logger.SafeLogger) MetricsManager(com.palantir.atlasdb.util.MetricsManager) LockWatchEventCache(com.palantir.lock.watch.LockWatchEventCache) PTExecutors(com.palantir.common.concurrent.PTExecutors) LockWatchCache(com.palantir.lock.watch.LockWatchCache) TransactionsLockWatchUpdate(com.palantir.lock.watch.TransactionsLockWatchUpdate) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) LockWatchReference(com.palantir.lock.watch.LockWatchReferences.LockWatchReference) LockWatchValueScopingCacheImpl(com.palantir.atlasdb.keyvalue.api.cache.LockWatchValueScopingCacheImpl) LockWatchValueScopingCache(com.palantir.atlasdb.keyvalue.api.cache.LockWatchValueScopingCache) LockWatchVersion(com.palantir.lock.watch.LockWatchVersion) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Collectors(java.util.stream.Collectors) LockWatchReferences(com.palantir.lock.watch.LockWatchReferences) TimeUnit(java.util.concurrent.TimeUnit) TransactionScopedCache(com.palantir.atlasdb.keyvalue.api.cache.TransactionScopedCache) LockWatchCachingConfig(com.palantir.atlasdb.keyvalue.api.LockWatchCachingConfig) UnsafeArg(com.palantir.logsafe.UnsafeArg) CacheMetrics(com.palantir.atlasdb.keyvalue.api.cache.CacheMetrics) LockWatchReferencesVisitor(com.palantir.lock.watch.LockWatchReferencesVisitor) LockWatchCacheImpl(com.palantir.lock.watch.LockWatchCacheImpl) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) LockWatchStarter(com.palantir.lock.client.LockWatchStarter) Schema(com.palantir.atlasdb.table.description.Schema) CacheMetrics(com.palantir.atlasdb.keyvalue.api.cache.CacheMetrics) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) LockWatchEventCache(com.palantir.lock.watch.LockWatchEventCache) Schema(com.palantir.atlasdb.table.description.Schema) LockWatchReference(com.palantir.lock.watch.LockWatchReferences.LockWatchReference) LockWatchValueScopingCache(com.palantir.atlasdb.keyvalue.api.cache.LockWatchValueScopingCache)

Example 2 with LockWatchReference

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

the class LockEventLogImplTest method noKnownVersionReturnsSnapshotContainingCurrentMatchingLocks.

@Test
public void noKnownVersionReturnsSnapshotContainingCurrentMatchingLocks() {
    LockWatchReference entireTable = LockWatchReferenceUtils.entireTable(TABLE_REF);
    lockWatches.set(createWatchesFor(entireTable));
    LockWatchStateUpdate update = log.getLogDiff(Optional.empty());
    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 3 with LockWatchReference

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

the class LockEventLogImplTest method snapshotIgnoresPreviousLogEntriesInLocksCalculation.

@Test
public void snapshotIgnoresPreviousLogEntriesInLocksCalculation() {
    LockWatchReference entireTable = LockWatchReferenceUtils.entireTable(TABLE_REF);
    lockWatches.set(createWatchesFor(entireTable));
    log.logLock(ImmutableSet.of(DESCRIPTOR), TOKEN);
    LockWatchStateUpdate update = log.getLogDiff(Optional.empty());
    LockWatchStateUpdate.Snapshot snapshot = UpdateVisitors.assertSnapshot(update);
    assertThat(snapshot.lastKnownVersion()).isEqualTo(0L);
    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 4 with LockWatchReference

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

the class LockEventLogImplTest method createLockWatchUpdateTest.

@Test
public void createLockWatchUpdateTest() {
    LockWatchReference secondRowReference = LockWatchReferenceUtils.rowPrefix(TABLE_REF, PtBytes.toBytes("2"));
    LockWatches newWatches = createWatchesFor(secondRowReference);
    log.logLockWatchCreated(newWatches);
    LockWatchStateUpdate update = log.getLogDiff(NEGATIVE_VERSION_CURRENT_LOG_ID);
    LockWatchStateUpdate.Success success = UpdateVisitors.assertSuccess(update);
    assertThat(success.events()).containsExactly(LockWatchCreatedEvent.builder(newWatches.references(), ImmutableSet.of(DESCRIPTOR_2)).build(0L));
}
Also used : LockWatchStateUpdate(com.palantir.lock.watch.LockWatchStateUpdate) LockWatchReference(com.palantir.lock.watch.LockWatchReferences.LockWatchReference) Test(org.junit.Test)

Example 5 with LockWatchReference

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

the class LockEventLogImplTest method requestWithStaleLogIdReturnsSnapshot.

@Test
public void requestWithStaleLogIdReturnsSnapshot() {
    LockWatchReference entireTable = LockWatchReferenceUtils.entireTable(TABLE_REF);
    lockWatches.set(createWatchesFor(entireTable));
    LockWatchStateUpdate update = log.getLogDiff(Optional.of(LockWatchVersion.of(STALE_LOG_ID, -1L)));
    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)

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