use of com.palantir.lock.v2.PartitionedTimestamps in project atlasdb by palantir.
the class MultiClientConjureTimelockResourceTest method createAsyncTimeLockServiceForClient.
private AsyncTimelockService createAsyncTimeLockServiceForClient(String client) {
AsyncTimelockService timelockService = mock(AsyncTimelockService.class);
LeadershipId leadershipId = namespaceToLeaderMap.computeIfAbsent(client, _u -> LeadershipId.random());
LeaderTime leaderTime = LeaderTime.of(leadershipId, NanoTime.createForTests(1L));
when(timelockService.leaderTime()).thenReturn(Futures.immediateFuture(leaderTime));
when(timelockService.startTransactionsWithWatches(any())).thenReturn(Futures.immediateFuture(ConjureStartTransactionsResponse.builder().immutableTimestamp(lockImmutableTimestampResponse).lease(Lease.of(leaderTime, Duration.ofSeconds(977))).timestamps(partitionedTimestamps).lockWatchUpdate(lockWatchStateUpdate).build()));
when(timelockService.getCommitTimestamps(anyInt(), any())).thenReturn(Futures.immediateFuture(getCommitTimestampResponse(client)));
return timelockService;
}
use of com.palantir.lock.v2.PartitionedTimestamps 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());
}
use of com.palantir.lock.v2.PartitionedTimestamps 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());
}
use of com.palantir.lock.v2.PartitionedTimestamps in project atlasdb by palantir.
the class DelegatingClientAwareManagedTimestampService method getFreshTimestampsForClient.
@Override
public PartitionedTimestamps getFreshTimestampsForClient(UUID clientIdentifier, int numTransactionsRequested) {
while (true) {
TimestampRange timestampRange = delegate.getFreshTimestamps(NUM_PARTITIONS * numTransactionsRequested);
int targetResidue = allocator.getRelevantModuli(clientIdentifier).iterator().next();
PartitionedTimestamps partitionedTimestamps = TimestampRanges.getPartitionedTimestamps(timestampRange, targetResidue, NUM_PARTITIONS);
if (partitionedTimestamps.count() > 0) {
return partitionedTimestamps;
}
// Not a bug - getFreshTimestamps is permitted to return less than the number of timestamps asked for,
// so this case is possible.
log.info("The timestamp range we received from the underlying timestamp service - {} -" + " did not contain a value with residue {} modulo {}. We will try again." + " This is not a bug; but if it happens excessively frequently, please contact support.", SafeArg.of("timestampRange", timestampRange), SafeArg.of("targetResidue", targetResidue), SafeArg.of("modulus", NUM_PARTITIONS));
}
}
use of com.palantir.lock.v2.PartitionedTimestamps in project atlasdb by palantir.
the class MultiNodePaxosTimeLockServerIntegrationTest method assertSanityAndStartTransactions.
private Map<Namespace, ConjureStartTransactionsResponse> assertSanityAndStartTransactions(TestableTimelockServer leader, List<String> expectedNamespaces) {
MultiClientConjureTimelockService multiClientConjureTimelockService = leader.multiClientService();
int numTransactions = 5;
Map<Namespace, ConjureStartTransactionsRequest> namespaceToRequestMap = defaultStartTransactionsRequests(expectedNamespaces, numTransactions);
Map<Namespace, ConjureStartTransactionsResponse> startedTransactions = multiClientConjureTimelockService.startTransactionsForClients(AUTH_HEADER, namespaceToRequestMap);
Set<String> namespaces = startedTransactions.keySet().stream().map(Namespace::get).collect(Collectors.toSet());
assertThat(namespaces).hasSameElementsAs(expectedNamespaces);
assertThat(startedTransactions.values().stream().map(ConjureStartTransactionsResponse::getTimestamps).mapToLong(partitionedTimestamps -> partitionedTimestamps.stream().count()).sum()).isEqualTo(namespaces.size() * numTransactions);
return startedTransactions;
}
Aggregations