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);
}
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);
}
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);
}
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());
}
Aggregations