Search in sources :

Example 11 with StartIdentifiedAtlasDbTransactionResponse

use of com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse 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 12 with StartIdentifiedAtlasDbTransactionResponse

use of com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse 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 13 with StartIdentifiedAtlasDbTransactionResponse

use of com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse in project atlasdb by palantir.

the class TransactionStarterHelper method split.

static List<StartIdentifiedAtlasDbTransactionResponse> split(ConjureStartTransactionsResponse response) {
    PartitionedTimestamps partitionedTimestamps = response.getTimestamps();
    int partition = partitionedTimestamps.partition();
    LockToken immutableTsLock = response.getImmutableTimestamp().getLock();
    long immutableTs = response.getImmutableTimestamp().getImmutableTimestamp();
    Stream<LockImmutableTimestampResponse> immutableTsAndLocks = LockTokenShare.share(immutableTsLock, partitionedTimestamps.count()).map(tokenShare -> LockImmutableTimestampResponse.of(immutableTs, tokenShare));
    Stream<TimestampAndPartition> timestampAndPartitions = partitionedTimestamps.stream().mapToObj(timestamp -> TimestampAndPartition.of(timestamp, partition));
    return Streams.zip(immutableTsAndLocks, timestampAndPartitions, StartIdentifiedAtlasDbTransactionResponse::of).collect(Collectors.toList());
}
Also used : LockImmutableTimestampResponse(com.palantir.lock.v2.LockImmutableTimestampResponse) LockToken(com.palantir.lock.v2.LockToken) PartitionedTimestamps(com.palantir.lock.v2.PartitionedTimestamps) TimestampAndPartition(com.palantir.lock.v2.TimestampAndPartition)

Example 14 with StartIdentifiedAtlasDbTransactionResponse

use of com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse in project atlasdb by palantir.

the class AsyncTimelockServiceIntegrationTest method startIdentifiedAtlasDbTransactionGivesUsStartTimestampsInTheSamePartition.

@Test
public void startIdentifiedAtlasDbTransactionGivesUsStartTimestampsInTheSamePartition() {
    StartIdentifiedAtlasDbTransactionResponse firstResponse = startSingleTransaction(namespace.timelockService());
    StartIdentifiedAtlasDbTransactionResponse secondResponse = startSingleTransaction(namespace.timelockService());
    assertThatStartIdentifiedTransactionResponseTimestampsInSamePartition(firstResponse, secondResponse);
}
Also used : StartIdentifiedAtlasDbTransactionResponse(com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse) Test(org.junit.Test)

Example 15 with StartIdentifiedAtlasDbTransactionResponse

use of com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse in project atlasdb by palantir.

the class AsyncTimelockServiceIntegrationTest method startIdentifiedAtlasDbTransactionGivesUsTimestampsInSequence.

@Test
public void startIdentifiedAtlasDbTransactionGivesUsTimestampsInSequence() {
    StartIdentifiedAtlasDbTransactionResponse firstResponse = startSingleTransaction(namespace.timelockService());
    StartIdentifiedAtlasDbTransactionResponse secondResponse = startSingleTransaction(namespace.timelockService());
    assertThatStartIdentifiedTransactionResponseTimestampsInSequence(firstResponse, secondResponse);
}
Also used : StartIdentifiedAtlasDbTransactionResponse(com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse) Test(org.junit.Test)

Aggregations

StartIdentifiedAtlasDbTransactionResponse (com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse)14 ConjureStartTransactionsResponse (com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse)10 Test (org.junit.Test)10 ImmutableList (com.google.common.collect.ImmutableList)9 List (java.util.List)9 BatchElement (com.palantir.atlasdb.autobatch.BatchElement)7 ArrayList (java.util.ArrayList)6 Namespace (com.palantir.atlasdb.timelock.api.Namespace)5 NamespaceAndRequestParams (com.palantir.lock.client.MultiClientTransactionStarter.NamespaceAndRequestParams)5 UUID (java.util.UUID)5 LockToken (com.palantir.lock.v2.LockToken)4 LockWatchCache (com.palantir.lock.watch.LockWatchCache)4 Collectors (java.util.stream.Collectors)4 DisruptorAutobatcher (com.palantir.atlasdb.autobatch.DisruptorAutobatcher)3 Preconditions (com.palantir.logsafe.Preconditions)3 Duration (java.time.Duration)3 Optional (java.util.Optional)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Iterables (com.google.common.collect.Iterables)2