Search in sources :

Example 1 with StartTransactionResponseV4

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

the class LockLeaseServiceTest method startTransactionsResponseHasCorrectLeasedLock.

@Test
public void startTransactionsResponseHasCorrectLeasedLock() {
    Lease lease = getLease();
    when(timelock.startTransactions(any())).thenReturn(startTransactionsResponseWith(LOCK_TOKEN, lease));
    StartTransactionResponseV4 clientResponse = lockLeaseService.startTransactions(2);
    verify(timelock).startTransactions(any());
    LeasedLockToken leasedLock = (LeasedLockToken) clientResponse.immutableTimestamp().getLock();
    assertThat(leasedLock.serverToken()).isEqualTo(LOCK_TOKEN);
    assertThat(leasedLock.getLease()).isEqualTo(lease);
}
Also used : StartTransactionResponseV4(com.palantir.lock.v2.StartTransactionResponseV4) Lease(com.palantir.lock.v2.Lease) Test(org.junit.Test)

Example 2 with StartTransactionResponseV4

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

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

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

the class AsyncTimelockServiceImpl method startTransactions.

@Override
public StartTransactionResponseV4 startTransactions(StartTransactionRequestV4 request) {
    Leased<LockImmutableTimestampResponse> leasedLockImmutableTimestampResponse = lockImmutableTimestampWithLease(request.requestId());
    PartitionedTimestamps partitionedTimestamps = timestampService.getFreshTimestampsForClient(request.requestorId(), request.numTransactions());
    return StartTransactionResponseV4.of(leasedLockImmutableTimestampResponse.value(), partitionedTimestamps, leasedLockImmutableTimestampResponse.lease());
}
Also used : LockImmutableTimestampResponse(com.palantir.lock.v2.LockImmutableTimestampResponse) PartitionedTimestamps(com.palantir.lock.v2.PartitionedTimestamps)

Aggregations

StartTransactionResponseV4 (com.palantir.lock.v2.StartTransactionResponseV4)3 ConjureStartTransactionsRequest (com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest)2 Lease (com.palantir.lock.v2.Lease)2 LockImmutableTimestampResponse (com.palantir.lock.v2.LockImmutableTimestampResponse)2 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 LockDiagnosticInfo (com.palantir.atlasdb.debug.LockDiagnosticInfo)1 ConjureStartTransactionsResponse (com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse)1 LockLog (com.palantir.atlasdb.timelock.lock.LockLog)1 PTExecutors (com.palantir.common.concurrent.PTExecutors)1 IdentifiedLockRequest (com.palantir.lock.client.IdentifiedLockRequest)1 IdentifiedTimeLockRequest (com.palantir.lock.v2.IdentifiedTimeLockRequest)1 ImmutableStartTransactionResponseV4 (com.palantir.lock.v2.ImmutableStartTransactionResponseV4)1 LockResponse (com.palantir.lock.v2.LockResponse)1 LockResponseV2 (com.palantir.lock.v2.LockResponseV2)1 LockToken (com.palantir.lock.v2.LockToken)1 PartitionedTimestamps (com.palantir.lock.v2.PartitionedTimestamps)1 RefreshLockResponseV2 (com.palantir.lock.v2.RefreshLockResponseV2)1