Search in sources :

Example 21 with ConjureStartTransactionsResponse

use of com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse in project atlasdb by palantir.

the class TimestampCorroboratingTimelockServiceTest method startTransactionsBoundIncreasesWithLargeInterval.

@Test
public void startTransactionsBoundIncreasesWithLargeInterval() {
    ConjureStartTransactionsResponse response = ConjureStartTransactionsResponse.builder().immutableTimestamp(LOCK_IMMUTABLE_TIMESTAMP_RESPONSE).lease(Lease.of(LeaderTime.of(LeadershipId.random(), NanoTime.now()), Duration.ZERO)).lockWatchUpdate(LOCK_WATCH_UPDATE).timestamps(ImmutablePartitionedTimestamps.builder().start(5L).count(100).interval(12).build()).build();
    when(rawTimelockService.startTransactions(startTransactionsRequest)).thenReturn(response);
    timelockService.startTransactions(startTransactionsRequest);
    assertThat(timelockService.getTimestampBounds().boundFromTransactions().lowerBoundForNextRequest()).isEqualTo(5 + (99 * 12));
    assertThat(timelockService.getTimestampBounds().boundFromTransactions().operationType()).isEqualTo(OperationType.TRANSACTION);
    verifyNoInteractions(callback);
}
Also used : ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse) Test(org.junit.Test)

Example 22 with ConjureStartTransactionsResponse

use of com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse in project atlasdb by palantir.

the class TransactionStarterTest method shouldDeriveStartTransactionResponseFromBatchedResponse_singleTransaction.

@Test
public void shouldDeriveStartTransactionResponseFromBatchedResponse_singleTransaction() {
    ConjureStartTransactionsResponse startTransactionResponse = StartTransactionsTestUtils.getStartTransactionResponse(12, 1);
    when(lockLeaseService.startTransactionsWithWatches(version, 1)).thenReturn(startTransactionResponse);
    StartIdentifiedAtlasDbTransactionResponse response = Iterables.getOnlyElement(transactionStarter.startIdentifiedAtlasDbTransactionBatch(1));
    assertDerivableFromBatchedResponse(response, startTransactionResponse);
}
Also used : StartIdentifiedAtlasDbTransactionResponse(com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse) ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse) Test(org.junit.Test)

Example 23 with ConjureStartTransactionsResponse

use of com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse 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)

Example 24 with ConjureStartTransactionsResponse

use of com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse in project atlasdb by palantir.

the class MultiClientTransactionStarter method getProcessedStartTransactionResponses.

private static Map<Namespace, List<StartIdentifiedAtlasDbTransactionResponse>> getProcessedStartTransactionResponses(Map<Namespace, RequestParams> originalRequestMap, InternalMultiClientConjureTimelockService delegate, UUID requestorId) {
    Map<Namespace, ConjureStartTransactionsRequest> requests = getConjureRequests(originalRequestMap, requestorId);
    Map<Namespace, ConjureStartTransactionsResponse> responseMap = getResponseMap(delegate, requests);
    Map<Namespace, List<StartIdentifiedAtlasDbTransactionResponse>> processedResult = new HashMap<>();
    for (Map.Entry<Namespace, ConjureStartTransactionsResponse> entry : responseMap.entrySet()) {
        Namespace namespace = entry.getKey();
        ConjureStartTransactionsResponse response = entry.getValue();
        TransactionStarterHelper.updateCacheWithStartTransactionResponse(originalRequestMap.get(namespace).cache(), response);
        processedResult.put(namespace, TransactionStarterHelper.split(response));
    }
    return processedResult;
}
Also used : ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse) HashMap(java.util.HashMap) ConjureStartTransactionsRequest(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Namespace(com.palantir.atlasdb.timelock.api.Namespace)

Example 25 with ConjureStartTransactionsResponse

use of com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse in project atlasdb by palantir.

the class LockDiagnosticConjureTimelockService method startTransactions.

@Override
public ConjureStartTransactionsResponse startTransactions(AuthHeader authHeader, String namespace, ConjureStartTransactionsRequest request) {
    ConjureStartTransactionsResponse response = conjureDelegate.startTransactions(authHeader, namespace, request);
    lockDiagnosticCollector.collect(response.getTimestamps().stream(), response.getImmutableTimestamp().getImmutableTimestamp(), request.getRequestId());
    return response;
}
Also used : ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse)

Aggregations

ConjureStartTransactionsResponse (com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse)29 Test (org.junit.Test)22 ImmutableList (com.google.common.collect.ImmutableList)12 List (java.util.List)12 Namespace (com.palantir.atlasdb.timelock.api.Namespace)9 StartIdentifiedAtlasDbTransactionResponse (com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse)9 ArrayList (java.util.ArrayList)9 BatchElement (com.palantir.atlasdb.autobatch.BatchElement)6 Cell (com.palantir.atlasdb.keyvalue.api.Cell)6 ConjureStartTransactionsRequest (com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest)6 Transaction (com.palantir.atlasdb.transaction.api.Transaction)6 LockImmutableTimestampResponse (com.palantir.lock.v2.LockImmutableTimestampResponse)6 Optional (java.util.Optional)6 UUID (java.util.UUID)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)6 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 Iterables (com.google.common.collect.Iterables)5 Futures (com.google.common.util.concurrent.Futures)5 TimelockService (com.palantir.lock.v2.TimelockService)5