Search in sources :

Example 21 with Namespace

use of com.palantir.atlasdb.timelock.api.Namespace in project atlasdb by palantir.

the class MultiClientTransactionStarterTest method shouldNotFreeResourcesIfRequestIsServed.

@Test
public void shouldNotFreeResourcesIfRequestIsServed() {
    Namespace alpha = Namespace.of("alpha" + UUID.randomUUID());
    Namespace beta = Namespace.of("beta" + UUID.randomUUID());
    BatchElement<NamespaceAndRequestParams, List<StartIdentifiedAtlasDbTransactionResponse>> requestForAlpha = batchElementForNamespace(alpha, PARTITIONED_TIMESTAMPS_LIMIT_PER_SERVER_CALL - 1);
    BatchElement<NamespaceAndRequestParams, List<StartIdentifiedAtlasDbTransactionResponse>> requestForBeta = batchElementForNamespace(beta, PARTITIONED_TIMESTAMPS_LIMIT_PER_SERVER_CALL * 5);
    UUID requestorId = UUID.randomUUID();
    List<BatchElement<NamespaceAndRequestParams, List<StartIdentifiedAtlasDbTransactionResponse>>> requests = ImmutableList.of(requestForAlpha, requestForBeta);
    Map<Namespace, ConjureStartTransactionsResponse> responseMap = startTransactionsResponse(requests, requestorId);
    when(timelockService.startTransactions(any())).thenReturn(responseMap).thenThrow(EXCEPTION);
    assertThatThrownBy(() -> processBatch(timelockService, requestorId, requests)).isEqualTo(EXCEPTION);
    // assert requests made by client alpha are served
    assertSanityOfRequestBatch(ImmutableList.of(requestForAlpha), ImmutableMap.of(alpha, ImmutableList.of(responseMap.get(alpha))));
    verify(LOCK_CLEANUP_SERVICE_MAP.get(alpha), never()).unlock(any());
    verify(LOCK_CLEANUP_SERVICE_MAP.get(beta)).refreshLockLeases(any());
    verify(LOCK_CLEANUP_SERVICE_MAP.get(beta)).unlock(any());
    verify(NAMESPACE_CACHE_MAP.get(alpha), never()).removeTransactionStateFromCache(anyLong());
    // The size of each batch is 5 here, and thus for a single batch we need to clean up five times
    verify(NAMESPACE_CACHE_MAP.get(beta), times(5)).removeTransactionStateFromCache(anyLong());
}
Also used : StartIdentifiedAtlasDbTransactionResponse(com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse) ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse) NamespaceAndRequestParams(com.palantir.lock.client.MultiClientTransactionStarter.NamespaceAndRequestParams) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) BatchElement(com.palantir.atlasdb.autobatch.BatchElement) UUID(java.util.UUID) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

Example 22 with Namespace

use of com.palantir.atlasdb.timelock.api.Namespace in project atlasdb by palantir.

the class MultiClientTransactionStarterTest method canServiceOneRequestWithMultipleServerRequests.

@Test
public void canServiceOneRequestWithMultipleServerRequests() {
    Namespace namespace = Namespace.of("Test_0");
    setupServiceAndAssertSanity(ImmutableList.of(batchElementForNamespace(namespace, 127)));
}
Also used : Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

Example 23 with Namespace

use of com.palantir.atlasdb.timelock.api.Namespace in project atlasdb by palantir.

the class MultiClientTransactionStarter method getResponseHandlers.

private static Map<Namespace, ResponseHandler> getResponseHandlers(List<BatchElement<NamespaceAndRequestParams, List<StartIdentifiedAtlasDbTransactionResponse>>> batch) {
    Map<Namespace, ResponseHandler> responseHandlers = new HashMap<>();
    for (BatchElement<NamespaceAndRequestParams, List<StartIdentifiedAtlasDbTransactionResponse>> element : batch) {
        NamespaceAndRequestParams requestParams = element.argument();
        Namespace namespace = requestParams.namespace();
        responseHandlers.computeIfAbsent(namespace, _unused -> new ResponseHandler(requestParams.params().lockCleanupService(), requestParams.params().cache())).addPendingFuture(SettableResponse.of(requestParams.params().numTransactions(), element.result()));
    }
    return responseHandlers;
}
Also used : DisruptorFuture(com.palantir.atlasdb.autobatch.DisruptorAutobatcher.DisruptorFuture) ConjureLockRequests.toConjure(com.palantir.lock.client.ConjureLockRequests.toConjure) HashMap(java.util.HashMap) BatchElement(com.palantir.atlasdb.autobatch.BatchElement) ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse) ConjureStartTransactionsRequest(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest) ImmutableList(com.google.common.collect.ImmutableList) Value(org.immutables.value.Value) Duration(java.time.Duration) Map(java.util.Map) LockWatchCache(com.palantir.lock.watch.LockWatchCache) DisruptorAutobatcher(com.palantir.atlasdb.autobatch.DisruptorAutobatcher) AtlasFutures(com.palantir.atlasdb.futures.AtlasFutures) Autobatchers(com.palantir.atlasdb.autobatch.Autobatchers) KeyedStream(com.palantir.common.streams.KeyedStream) UUID(java.util.UUID) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) List(java.util.List) StartIdentifiedAtlasDbTransactionResponse(com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Queue(java.util.Queue) ArrayDeque(java.util.ArrayDeque) Preconditions(com.palantir.logsafe.Preconditions) HashMap(java.util.HashMap) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Namespace(com.palantir.atlasdb.timelock.api.Namespace)

Example 24 with Namespace

use of com.palantir.atlasdb.timelock.api.Namespace in project atlasdb by palantir.

the class MultiNodePaxosTimeLockServerIntegrationTest method assertSanityAndGetLeaderTimes.

private LeaderTimes assertSanityAndGetLeaderTimes(TestableTimelockServer leader, Set<Namespace> expectedNamespaces) {
    MultiClientConjureTimelockService multiClientConjureTimelockService = leader.multiClientService();
    LeaderTimes leaderTimes = multiClientConjureTimelockService.leaderTimes(AUTH_HEADER, expectedNamespaces);
    Set<Namespace> namespaces = leaderTimes.getLeaderTimes().keySet();
    assertThat(namespaces).hasSameElementsAs(expectedNamespaces);
    return leaderTimes;
}
Also used : MultiClientConjureTimelockService(com.palantir.atlasdb.timelock.api.MultiClientConjureTimelockService) LeaderTimes(com.palantir.atlasdb.timelock.api.LeaderTimes) Namespace(com.palantir.atlasdb.timelock.api.Namespace)

Example 25 with Namespace

use of com.palantir.atlasdb.timelock.api.Namespace in project atlasdb by palantir.

the class MultiNodePaxosTimeLockServerIntegrationTest method sanityCheckMultiClientLeaderTime.

@Test
public void sanityCheckMultiClientLeaderTime() {
    TestableTimelockServer leader = cluster.currentLeaderFor(client.namespace());
    // Multi client batched TimeLock endpoints do not support multi-leader mode on TimeLock
    Assume.assumeFalse(leader.isMultiLeader());
    Set<Namespace> expectedNamespaces = ImmutableSet.of(Namespace.of("client1"), Namespace.of("client2"));
    LeaderTimes leaderTimes = assertSanityAndGetLeaderTimes(leader, expectedNamespaces);
    // leaderTimes for namespaces are computed by their respective underlying AsyncTimelockService instances
    Set<UUID> leadershipIds = leaderTimes.getLeaderTimes().values().stream().map(LeaderTime::id).map(LeadershipId::id).collect(Collectors.toSet());
    assertThat(leadershipIds).hasSameSizeAs(expectedNamespaces);
}
Also used : LeaderTime(com.palantir.lock.v2.LeaderTime) LeaderTimes(com.palantir.atlasdb.timelock.api.LeaderTimes) UUID(java.util.UUID) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

Aggregations

Namespace (com.palantir.atlasdb.timelock.api.Namespace)53 Test (org.junit.Test)39 ImmutableList (com.google.common.collect.ImmutableList)12 List (java.util.List)11 Map (java.util.Map)11 Set (java.util.Set)11 UUID (java.util.UUID)11 AtlasService (com.palantir.atlasdb.backup.api.AtlasService)10 CompletedBackup (com.palantir.atlasdb.backup.api.CompletedBackup)10 ConjureStartTransactionsResponse (com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse)10 DisableNamespacesResponse (com.palantir.atlasdb.timelock.api.DisableNamespacesResponse)9 SuccessfulDisableNamespacesResponse (com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse)9 UnsuccessfulDisableNamespacesResponse (com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse)9 KeyedStream (com.palantir.common.streams.KeyedStream)9 ImmutableSet (com.google.common.collect.ImmutableSet)8 SafeIllegalStateException (com.palantir.logsafe.exceptions.SafeIllegalStateException)8 Collectors (java.util.stream.Collectors)8 BatchElement (com.palantir.atlasdb.autobatch.BatchElement)7 ReenableNamespacesRequest (com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest)7 ArrayList (java.util.ArrayList)7