Search in sources :

Example 1 with LockWatchCache

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

the class TimeLockHelperServices method create.

static TimeLockHelperServices create(String namespace, MetricsManager metricsManager, Set<Schema> schemas, LockWatchStarter lockWatchStarter, LockWatchCachingConfig lockWatchCachingConfig, Supplier<Optional<RequestBatchersFactory.MultiClientRequestBatchers>> requestBatcherProvider) {
    LockWatchManagerInternal lockWatchManager = LockWatchManagerImpl.create(metricsManager, schemas, lockWatchStarter, lockWatchCachingConfig);
    LockWatchCache lockWatchCache = lockWatchManager.getCache();
    RequestBatchersFactory requestBatchersFactory = RequestBatchersFactory.create(lockWatchCache, Namespace.of(namespace), requestBatcherProvider.get());
    return ImmutableTimeLockHelperServices.builder().lockWatchManager(lockWatchManager).requestBatchersFactory(requestBatchersFactory).build();
}
Also used : LockWatchCache(com.palantir.lock.watch.LockWatchCache) LockWatchManagerInternal(com.palantir.atlasdb.keyvalue.api.watch.LockWatchManagerInternal) RequestBatchersFactory(com.palantir.lock.client.RequestBatchersFactory)

Example 2 with LockWatchCache

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

the class MultiClientCommitTimestampGetterTest method updatesCacheWhileProcessingResponse.

@Test
public void updatesCacheWhileProcessingResponse() {
    Namespace client = Namespace.of("Kitty");
    List<BatchElement<NamespacedRequest, Long>> batchElements = IntStream.range(0, COMMIT_TS_LIMIT_PER_REQUEST * 2).mapToObj(ind -> batchElementForNamespace(client)).collect(toList());
    setupServiceAndAssertSanityOfResponse(batchElements);
    LockWatchCache cache = lockWatchCacheMap.get(client);
    verify(cache, times(2)).processCommitTimestampsUpdate(any(), any());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DisruptorFuture(com.palantir.atlasdb.autobatch.DisruptorAutobatcher.DisruptorFuture) IntStream(java.util.stream.IntStream) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) LockWatchStateUpdate(com.palantir.lock.watch.LockWatchStateUpdate) HashMap(java.util.HashMap) GetCommitTimestampsRequest(com.palantir.atlasdb.timelock.api.GetCommitTimestampsRequest) Mockito.spy(org.mockito.Mockito.spy) BatchElement(com.palantir.atlasdb.autobatch.BatchElement) ArrayList(java.util.ArrayList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) GetCommitTimestampsResponse(com.palantir.atlasdb.timelock.api.GetCommitTimestampsResponse) LockWatchCache(com.palantir.lock.watch.LockWatchCache) NamespacedRequest(com.palantir.lock.client.MultiClientCommitTimestampGetter.NamespacedRequest) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) KeyedStream(com.palantir.common.streams.KeyedStream) LockToken(com.palantir.lock.v2.LockToken) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) UUID(java.util.UUID) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) Collectors.toList(java.util.stream.Collectors.toList) Mockito.never(org.mockito.Mockito.never) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) StreamEx(one.util.streamex.StreamEx) LockWatchCacheImpl(com.palantir.lock.watch.LockWatchCacheImpl) Mockito.mock(org.mockito.Mockito.mock) LockWatchCache(com.palantir.lock.watch.LockWatchCache) BatchElement(com.palantir.atlasdb.autobatch.BatchElement) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

Example 3 with LockWatchCache

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

the class MultiClientCommitTimestampGetterTest method doesNotUpdateCacheIfClientNotServed.

@Test
public void doesNotUpdateCacheIfClientNotServed() {
    Namespace alpha = Namespace.of("alpha" + UUID.randomUUID());
    Namespace beta = Namespace.of("beta" + UUID.randomUUID());
    BatchElement<NamespacedRequest, Long> requestForAlpha = batchElementForNamespace(alpha);
    BatchElement<NamespacedRequest, Long> requestForBeta = batchElementForNamespace(beta);
    List<BatchElement<NamespacedRequest, Long>> allRequests = ImmutableList.of(requestForAlpha, requestForBeta);
    List<BatchElement<NamespacedRequest, Long>> alphaRequestList = ImmutableList.of(requestForAlpha);
    Map<Namespace, GetCommitTimestampsResponse> responseMap = getCommitTimestamps(alphaRequestList);
    when(timelockService.getCommitTimestamps(any())).thenReturn(responseMap).thenThrow(EXCEPTION);
    assertThatThrownBy(() -> consumer.accept(allRequests)).isEqualTo(EXCEPTION);
    // assert requests made by client alpha are served
    assertSanityOfResponse(alphaRequestList, ImmutableMap.of(alpha, ImmutableList.of(responseMap.get(alpha))));
    LockWatchCache alphaCache = lockWatchCacheMap.get(alpha);
    verify(alphaCache).processCommitTimestampsUpdate(any(), any());
    assertThat(requestForBeta.result().isDone()).as("No requests made by client - beta were successful").isFalse();
    LockWatchCache betaCache = lockWatchCacheMap.get(beta);
    verify(betaCache, never()).processCommitTimestampsUpdate(any(), any());
}
Also used : NamespacedRequest(com.palantir.lock.client.MultiClientCommitTimestampGetter.NamespacedRequest) LockWatchCache(com.palantir.lock.watch.LockWatchCache) BatchElement(com.palantir.atlasdb.autobatch.BatchElement) Namespace(com.palantir.atlasdb.timelock.api.Namespace) GetCommitTimestampsResponse(com.palantir.atlasdb.timelock.api.GetCommitTimestampsResponse) Test(org.junit.Test)

Example 4 with LockWatchCache

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

the class LockWatchValueIntegrationTest method nearbyCommitsDoNotAffectResultsPresentInCache.

@Test
public void nearbyCommitsDoNotAffectResultsPresentInCache() {
    createTransactionManager(1.0);
    txnManager.runTaskThrowOnConflict(txn -> {
        txn.put(TABLE_REF, ImmutableMap.of(CELL_1, DATA_1, CELL_2, DATA_2, CELL_3, DATA_3));
        return null;
    });
    LockWatchIntegrationTestUtilities.awaitAllUnlocked(txnManager);
    LockWatchIntegrationTestUtilities.CommitStageCondition<Void> condition = new LockWatchIntegrationTestUtilities.CommitStageCondition<>((startTs, commitTs) -> {
        LockWatchCache cache = LockWatchIntegrationTestUtilities.extractInternalLockWatchManager(txnManager).getCache();
        simulateOverlappingWriteTransaction(cache, startTs, commitTs);
        return null;
    });
    assertThatCode(() -> txnManager.runTaskWithConditionThrowOnConflict(condition, (txn, _unused) -> {
        condition.initialiseWithStartTimestamp(txn.getTimestamp());
        txnManager.getTimestampManagementService().fastForwardTimestamp(txn.getTimestamp() + 1_000_000);
        txn.get(TABLE_REF, ImmutableSet.of(CELL_1));
        // A write forces this to go through serializable conflict checking
        txn.put(TABLE_REF, ImmutableMap.of(CELL_2, DATA_1));
        return null;
    })).doesNotThrowAnyException();
}
Also used : LockWatchCache(com.palantir.lock.watch.LockWatchCache) Test(org.junit.Test)

Example 5 with LockWatchCache

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

the class BatchingIdentifiedAtlasDbTransactionStarter method getStartTransactionResponses.

private static List<StartIdentifiedAtlasDbTransactionResponse> getStartTransactionResponses(LockLeaseService lockLeaseService, LockWatchCache cache, int numberOfTransactions) {
    List<StartIdentifiedAtlasDbTransactionResponse> result = new ArrayList<>();
    while (result.size() < numberOfTransactions) {
        try {
            Optional<LockWatchVersion> requestedVersion = cache.getEventCache().lastKnownVersion();
            ConjureStartTransactionsResponse response = lockLeaseService.startTransactionsWithWatches(requestedVersion, numberOfTransactions - result.size());
            TransactionStarterHelper.updateCacheWithStartTransactionResponse(cache, response);
            result.addAll(TransactionStarterHelper.split(response));
        } catch (Throwable t) {
            TransactionStarterHelper.cleanUpCaches(cache, result);
            TransactionStarterHelper.unlock(result.stream().map(response -> response.immutableTimestamp().getLock()).collect(Collectors.toSet()), lockLeaseService);
            throw Throwables.throwUncheckedException(t);
        }
    }
    return result;
}
Also used : Autobatchers(com.palantir.atlasdb.autobatch.Autobatchers) Throwables(com.palantir.common.base.Throwables) LockWatchVersion(com.palantir.lock.watch.LockWatchVersion) Collectors(java.util.stream.Collectors) BatchElement(com.palantir.atlasdb.autobatch.BatchElement) ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Duration(java.time.Duration) LockWatchCache(com.palantir.lock.watch.LockWatchCache) StartIdentifiedAtlasDbTransactionResponse(com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) DisruptorAutobatcher(com.palantir.atlasdb.autobatch.DisruptorAutobatcher) AtlasFutures(com.palantir.atlasdb.futures.AtlasFutures) Preconditions(com.palantir.logsafe.Preconditions) StartIdentifiedAtlasDbTransactionResponse(com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse) LockWatchVersion(com.palantir.lock.watch.LockWatchVersion) ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse) ArrayList(java.util.ArrayList)

Aggregations

LockWatchCache (com.palantir.lock.watch.LockWatchCache)5 BatchElement (com.palantir.atlasdb.autobatch.BatchElement)3 Test (org.junit.Test)3 ImmutableList (com.google.common.collect.ImmutableList)2 GetCommitTimestampsResponse (com.palantir.atlasdb.timelock.api.GetCommitTimestampsResponse)2 Namespace (com.palantir.atlasdb.timelock.api.Namespace)2 NamespacedRequest (com.palantir.lock.client.MultiClientCommitTimestampGetter.NamespacedRequest)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Consumer (java.util.function.Consumer)2 Collectors (java.util.stream.Collectors)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Maps (com.google.common.collect.Maps)1 Futures (com.google.common.util.concurrent.Futures)1 Autobatchers (com.palantir.atlasdb.autobatch.Autobatchers)1 DisruptorAutobatcher (com.palantir.atlasdb.autobatch.DisruptorAutobatcher)1 DisruptorFuture (com.palantir.atlasdb.autobatch.DisruptorAutobatcher.DisruptorFuture)1 AtlasFutures (com.palantir.atlasdb.futures.AtlasFutures)1