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