Search in sources :

Example 1 with ConjureStartTransactionsRequest

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

the class LockLeaseService method startTransactions.

StartTransactionResponseV4 startTransactions(int batchSize) {
    ConjureStartTransactionsRequest request = ConjureStartTransactionsRequest.builder().requestorId(clientId).requestId(UUID.randomUUID()).numTransactions(batchSize).lastKnownVersion(Optional.empty()).build();
    ConjureStartTransactionsResponse conjureResponse = delegate.startTransactions(request);
    StartTransactionResponseV4 response = StartTransactionResponseV4.of(conjureResponse.getImmutableTimestamp(), conjureResponse.getTimestamps(), conjureResponse.getLease());
    Lease lease = response.lease();
    LeasedLockToken leasedLockToken = LeasedLockToken.of(ConjureLockToken.of(response.immutableTimestamp().getLock().getRequestId()), lease);
    long immutableTs = response.immutableTimestamp().getImmutableTimestamp();
    return StartTransactionResponseV4.of(LockImmutableTimestampResponse.of(immutableTs, leasedLockToken), response.timestamps(), lease);
}
Also used : StartTransactionResponseV4(com.palantir.lock.v2.StartTransactionResponseV4) ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse) Lease(com.palantir.lock.v2.Lease) ConjureStartTransactionsRequest(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest)

Example 2 with ConjureStartTransactionsRequest

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

the class AsyncTimelockServiceIntegrationTest method getSortedBatchedStartTimestamps.

private List<Long> getSortedBatchedStartTimestamps(UUID requestorUuid, int numRequestedTimestamps) {
    ConjureStartTransactionsRequest request = ConjureStartTransactionsRequest.builder().requestId(UUID.randomUUID()).requestorId(requestorUuid).numTransactions(numRequestedTimestamps).lastKnownVersion(Optional.empty()).build();
    ConjureStartTransactionsResponse response = namespace.namespacedConjureTimelockService().startTransactions(request);
    return response.getTimestamps().stream().boxed().collect(Collectors.toList());
}
Also used : ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse) ConjureStartTransactionsRequest(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest)

Example 3 with ConjureStartTransactionsRequest

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

the class AsyncTimelockServiceIntegrationTest method batchedStartTransactionCallShouldLockImmutableTimestamp.

@Test
public void batchedStartTransactionCallShouldLockImmutableTimestamp() {
    // requestor id corresponds to an instance of the timelock service client
    ConjureStartTransactionsRequest request = ConjureStartTransactionsRequest.builder().numTransactions(123).requestorId(UUID.randomUUID()).requestId(UUID.randomUUID()).lastKnownVersion(Optional.empty()).build();
    LockImmutableTimestampResponse response1 = namespace.namespacedConjureTimelockService().startTransactions(request).getImmutableTimestamp();
    LockImmutableTimestampResponse response2 = namespace.namespacedConjureTimelockService().startTransactions(request).getImmutableTimestamp();
    // above are two *separate* batches
    long immutableTs = namespace.timelockService().getImmutableTimestamp();
    assertThat(immutableTs).isEqualTo(response1.getImmutableTimestamp());
    namespace.namespacedConjureTimelockService().unlock(ConjureUnlockRequest.of(ImmutableSet.of(ConjureLockToken.of(response1.getLock().getRequestId()))));
    assertThat(immutableTs).isEqualTo(response2.getImmutableTimestamp());
    namespace.namespacedConjureTimelockService().unlock(ConjureUnlockRequest.of(ImmutableSet.of(ConjureLockToken.of(response2.getLock().getRequestId()))));
}
Also used : LockImmutableTimestampResponse(com.palantir.lock.v2.LockImmutableTimestampResponse) ConjureStartTransactionsRequest(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest) Test(org.junit.Test)

Example 4 with ConjureStartTransactionsRequest

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

the class AsyncTimelockResource method startTransactions.

/**
 * Returns a {@link StartTransactionResponseV4} which has a single immutable ts, and a range of timestamps to
 * be used as start timestamps.
 *
 * It is guaranteed to have at least one usable timestamp matching the partition criteria in the returned timestamp
 * range, but there is no other guarantee given. (It can be less than number of requested timestamps)
 */
@POST
@Path("start-atlasdb-transaction-v4")
public void startTransactions(@Suspended final AsyncResponse response, StartTransactionRequestV4 request) {
    ConjureStartTransactionsRequest conjureRequest = ConjureStartTransactionsRequest.builder().requestId(request.requestId()).requestorId(request.requestorId()).numTransactions(request.numTransactions()).build();
    addJerseyCallback(Futures.transform(timelock.startTransactionsWithWatches(conjureRequest), newResponse -> ImmutableStartTransactionResponseV4.builder().timestamps(newResponse.getTimestamps()).immutableTimestamp(newResponse.getImmutableTimestamp()).lease(newResponse.getLease()).build(), MoreExecutors.directExecutor()), response);
}
Also used : LockResponseV2(com.palantir.lock.v2.LockResponseV2) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) StartIdentifiedAtlasDbTransactionRequest(com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionRequest) StartAtlasDbTransactionResponseV3(com.palantir.lock.v2.StartAtlasDbTransactionResponseV3) StartTransactionRequestV4(com.palantir.lock.v2.StartTransactionRequestV4) Path(javax.ws.rs.Path) LockImmutableTimestampResponse(com.palantir.lock.v2.LockImmutableTimestampResponse) StartTransactionResponseV4(com.palantir.lock.v2.StartTransactionResponseV4) ConjureStartTransactionsRequest(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) PTExecutors(com.palantir.common.concurrent.PTExecutors) Consumes(javax.ws.rs.Consumes) IdentifiedLockRequest(com.palantir.lock.client.IdentifiedLockRequest) RefreshLockResponseV2(com.palantir.lock.v2.RefreshLockResponseV2) ExecutorService(java.util.concurrent.ExecutorService) LockResponse(com.palantir.lock.v2.LockResponse) StartAtlasDbTransactionResponse(com.palantir.lock.v2.StartAtlasDbTransactionResponse) POST(javax.ws.rs.POST) LockToken(com.palantir.lock.v2.LockToken) AsyncResponse(javax.ws.rs.container.AsyncResponse) LockDiagnosticInfo(com.palantir.atlasdb.debug.LockDiagnosticInfo) Set(java.util.Set) UUID(java.util.UUID) Suspended(javax.ws.rs.container.Suspended) FutureCallback(com.google.common.util.concurrent.FutureCallback) ImmutableStartTransactionResponseV4(com.palantir.lock.v2.ImmutableStartTransactionResponseV4) Futures(com.google.common.util.concurrent.Futures) Safe(com.palantir.logsafe.Safe) LockLog(com.palantir.atlasdb.timelock.lock.LockLog) TimestampRange(com.palantir.timestamp.TimestampRange) StartIdentifiedAtlasDbTransactionResponse(com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse) Optional(java.util.Optional) IdentifiedTimeLockRequest(com.palantir.lock.v2.IdentifiedTimeLockRequest) WaitForLocksRequest(com.palantir.lock.v2.WaitForLocksRequest) ConjureStartTransactionsRequest(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 5 with ConjureStartTransactionsRequest

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

Aggregations

ConjureStartTransactionsRequest (com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest)7 ConjureStartTransactionsResponse (com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse)5 Namespace (com.palantir.atlasdb.timelock.api.Namespace)3 Test (org.junit.Test)3 ImmutableList (com.google.common.collect.ImmutableList)2 MultiClientConjureTimelockService (com.palantir.atlasdb.timelock.api.MultiClientConjureTimelockService)2 LockResponse (com.palantir.lock.v2.LockResponse)2 LockToken (com.palantir.lock.v2.LockToken)2 PartitionedTimestamps (com.palantir.lock.v2.PartitionedTimestamps)2 WaitForLocksRequest (com.palantir.lock.v2.WaitForLocksRequest)2 SafeIllegalStateException (com.palantir.logsafe.exceptions.SafeIllegalStateException)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 UUID (java.util.UUID)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 Iterables (com.google.common.collect.Iterables)1 Sets (com.google.common.collect.Sets)1