Search in sources :

Example 1 with PartitionedTimestamps

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;
}
Also used : LeaderTime(com.palantir.lock.v2.LeaderTime) AsyncTimelockService(com.palantir.atlasdb.timelock.AsyncTimelockService) LeadershipId(com.palantir.lock.v2.LeadershipId)

Example 2 with PartitionedTimestamps

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());
}
Also used : LockImmutableTimestampResponse(com.palantir.lock.v2.LockImmutableTimestampResponse) PartitionedTimestamps(com.palantir.lock.v2.PartitionedTimestamps)

Example 3 with PartitionedTimestamps

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());
}
Also used : LockImmutableTimestampResponse(com.palantir.lock.v2.LockImmutableTimestampResponse) LockToken(com.palantir.lock.v2.LockToken) PartitionedTimestamps(com.palantir.lock.v2.PartitionedTimestamps) TimestampAndPartition(com.palantir.lock.v2.TimestampAndPartition)

Example 4 with PartitionedTimestamps

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));
    }
}
Also used : PartitionedTimestamps(com.palantir.lock.v2.PartitionedTimestamps) TimestampRange(com.palantir.timestamp.TimestampRange)

Example 5 with PartitionedTimestamps

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;
}
Also used : MethodSorters(org.junit.runners.MethodSorters) LeadershipId(com.palantir.lock.v2.LeadershipId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) AuthHeader(com.palantir.tokens.auth.AuthHeader) ConjureLockDescriptor(com.palantir.atlasdb.timelock.api.ConjureLockDescriptor) MultiLeaderPaxosSuite(com.palantir.atlasdb.timelock.suite.MultiLeaderPaxosSuite) LockWatchStateUpdate(com.palantir.lock.watch.LockWatchStateUpdate) Bytes(com.palantir.conjure.java.lib.Bytes) ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse) ConjureStartTransactionsRequest(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest) LeaderTime(com.palantir.lock.v2.LeaderTime) ConjureLockRequest(com.palantir.atlasdb.timelock.api.ConjureLockRequest) Duration(java.time.Duration) Map(java.util.Map) GetCommitTimestampsResponse(com.palantir.atlasdb.timelock.api.GetCommitTimestampsResponse) SuccessfulLockResponse(com.palantir.atlasdb.timelock.api.SuccessfulLockResponse) ConjureLockResponse(com.palantir.atlasdb.timelock.api.ConjureLockResponse) ClassRule(org.junit.ClassRule) Parameterized(org.junit.runners.Parameterized) LockDescriptor(com.palantir.lock.LockDescriptor) ConjureLockToken(com.palantir.atlasdb.timelock.api.ConjureLockToken) ImmutableSet(com.google.common.collect.ImmutableSet) KeyedStream(com.palantir.common.streams.KeyedStream) ConjureLockRequests(com.palantir.lock.client.ConjureLockRequests) Set(java.util.Set) ConjureUnlockRequest(com.palantir.atlasdb.timelock.api.ConjureUnlockRequest) UUID(java.util.UUID) ConjureLockRefreshToken(com.palantir.lock.ConjureLockRefreshToken) LockMode(com.palantir.lock.LockMode) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) Stream(java.util.stream.Stream) ClientOptionsConstants(com.palantir.atlasdb.http.v2.ClientOptionsConstants) PartitionedTimestamps(com.palantir.lock.v2.PartitionedTimestamps) Optional(java.util.Optional) ConjureLockV1Request(com.palantir.lock.ConjureLockV1Request) FixMethodOrder(org.junit.FixMethodOrder) WaitForLocksRequest(com.palantir.lock.v2.WaitForLocksRequest) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) MultiClientConjureTimelockService(com.palantir.atlasdb.timelock.api.MultiClientConjureTimelockService) ExceptionMatchers(com.palantir.atlasdb.timelock.util.ExceptionMatchers) Iterables(com.google.common.collect.Iterables) HeldLocksToken(com.palantir.lock.HeldLocksToken) RunWith(org.junit.runner.RunWith) GetCommitTimestampsRequest(com.palantir.atlasdb.timelock.api.GetCommitTimestampsRequest) UnsuccessfulLockResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulLockResponse) SimpleHeldLocksToken(com.palantir.lock.SimpleHeldLocksToken) LockRefreshToken(com.palantir.lock.LockRefreshToken) PtBytes(com.palantir.atlasdb.encoding.PtBytes) HashSet(java.util.HashSet) ConjureSimpleHeldLocksToken(com.palantir.lock.ConjureSimpleHeldLocksToken) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ImmutableList(com.google.common.collect.ImmutableList) WaitForLocksResponse(com.palantir.lock.v2.WaitForLocksResponse) Assume(org.junit.Assume) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Before(org.junit.Before) LockResponse(com.palantir.lock.v2.LockResponse) LockToken(com.palantir.lock.v2.LockToken) Test(org.junit.Test) ConjureRefreshLocksRequest(com.palantir.atlasdb.timelock.api.ConjureRefreshLocksRequest) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Ints(com.google.common.primitives.Ints) ExecutionException(java.util.concurrent.ExecutionException) LockRequest(com.palantir.lock.v2.LockRequest) LockClient(com.palantir.lock.LockClient) StringLockDescriptor(com.palantir.lock.StringLockDescriptor) LeaderTimes(com.palantir.atlasdb.timelock.api.LeaderTimes) ParameterInjector(com.palantir.atlasdb.timelock.util.ParameterInjector) ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse) MultiClientConjureTimelockService(com.palantir.atlasdb.timelock.api.MultiClientConjureTimelockService) ConjureStartTransactionsRequest(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest) Namespace(com.palantir.atlasdb.timelock.api.Namespace)

Aggregations

PartitionedTimestamps (com.palantir.lock.v2.PartitionedTimestamps)5 ConjureStartTransactionsRequest (com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest)2 ConjureStartTransactionsResponse (com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse)2 MultiClientConjureTimelockService (com.palantir.atlasdb.timelock.api.MultiClientConjureTimelockService)2 Namespace (com.palantir.atlasdb.timelock.api.Namespace)2 LockImmutableTimestampResponse (com.palantir.lock.v2.LockImmutableTimestampResponse)2 LockToken (com.palantir.lock.v2.LockToken)2 SafeIllegalStateException (com.palantir.logsafe.exceptions.SafeIllegalStateException)2 Test (org.junit.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 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 Ints (com.google.common.primitives.Ints)1 PtBytes (com.palantir.atlasdb.encoding.PtBytes)1 ClientOptionsConstants (com.palantir.atlasdb.http.v2.ClientOptionsConstants)1 AsyncTimelockService (com.palantir.atlasdb.timelock.AsyncTimelockService)1 ConjureLockDescriptor (com.palantir.atlasdb.timelock.api.ConjureLockDescriptor)1 ConjureLockRequest (com.palantir.atlasdb.timelock.api.ConjureLockRequest)1