Search in sources :

Example 36 with Namespace

use of com.palantir.atlasdb.timelock.api.Namespace 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;
}
Also used : ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse) HashMap(java.util.HashMap) ConjureStartTransactionsRequest(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Namespace(com.palantir.atlasdb.timelock.api.Namespace)

Example 37 with Namespace

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

the class AllNodesDisabledNamespacesUpdaterTest method doesNotDisableIfSomeNamespaceAlreadyDisabled.

// Case B: One namespace already disabled on all nodes => should not disable any namespace on any node
// Note that if B and C are combined, we also don't need to roll back. Some namespaces would be
// in an inconsistent state, but because one namespace is disabled on all nodes, we did not
// successfully disable any namespaces ourselves, and we therefore have nothing to roll back.
@Test
public void doesNotDisableIfSomeNamespaceAlreadyDisabled() {
    Set<Namespace> disabledNamespaces = ImmutableSet.of(OTHER_NAMESPACE);
    SingleNodeUpdateResponse unsuccessfulResponse = singleNodeUpdateFailure(disabledNamespaces);
    when(remote1.disable(any(), any())).thenReturn(unsuccessfulResponse);
    when(remote2.disable(any(), any())).thenReturn(unsuccessfulResponse);
    when(localUpdater.getNamespacesLockedWithDifferentLockId(any(), any())).thenReturn(unsuccessfulResponse.lockedNamespaces());
    DisableNamespacesResponse response = updater.disableOnAllNodes(AUTH_HEADER, disableNamespacesRequest(BOTH_NAMESPACES));
    assertThat(response).isEqualTo(consistentlyDisabled(disabledNamespaces));
    // Should not disable locally
    verify(localUpdater, never()).disable(any());
    // No re-enable should take place
    verify(remote1, never()).reenable(any(), any());
    verify(remote2, never()).reenable(any(), any());
    verify(localUpdater, never()).reEnable(any());
}
Also used : SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) Namespace(com.palantir.atlasdb.timelock.api.Namespace) SingleNodeUpdateResponse(com.palantir.atlasdb.timelock.api.SingleNodeUpdateResponse) ImmutableSingleNodeUpdateResponse(com.palantir.atlasdb.timelock.api.ImmutableSingleNodeUpdateResponse) Test(org.junit.Test)

Example 38 with Namespace

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

the class AllNodesDisabledNamespacesUpdaterTest method rollsBackDisableIfInconsistentStateIsFound.

// Case C: If we start with an inconsistent state, we roll back our request
@Test
public void rollsBackDisableIfInconsistentStateIsFound() {
    Set<Namespace> disabledNamespaces = ImmutableSet.of(OTHER_NAMESPACE);
    SingleNodeUpdateResponse unsuccessfulResponse = singleNodeUpdateFailure(disabledNamespaces);
    when(remote1.disable(any(), any())).thenReturn(unsuccessfulResponse);
    when(remote2.disable(any(), any())).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
    when(remote2.reenable(any(), any())).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
    when(localUpdater.getNamespacesLockedWithDifferentLockId(any(), any())).thenReturn(ImmutableMap.of());
    DisableNamespacesResponse response = updater.disableOnAllNodes(AUTH_HEADER, disableNamespacesRequest(ImmutableSet.of(NAMESPACE, OTHER_NAMESPACE)));
    ReenableNamespacesRequest rollbackRequest = ReenableNamespacesRequest.of(BOTH_NAMESPACES, LOCK_ID);
    verify(remote1, never()).reenable(any(), any());
    verify(remote2).reenable(AUTH_HEADER, rollbackRequest);
    verify(localUpdater, never()).reEnable(any());
    assertThat(response).isEqualTo(partiallyDisabled(BOTH_NAMESPACES));
}
Also used : SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) ReenableNamespacesRequest(com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest) Namespace(com.palantir.atlasdb.timelock.api.Namespace) SingleNodeUpdateResponse(com.palantir.atlasdb.timelock.api.SingleNodeUpdateResponse) ImmutableSingleNodeUpdateResponse(com.palantir.atlasdb.timelock.api.ImmutableSingleNodeUpdateResponse) Test(org.junit.Test)

Example 39 with Namespace

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

the class AllNodesDisabledNamespacesUpdaterTest method reEnableDoesNotReportConsistentStateWhenNamespacesAreLockedWithDifferentIds.

@Test
public void reEnableDoesNotReportConsistentStateWhenNamespacesAreLockedWithDifferentIds() {
    Set<Namespace> namespaces = ImmutableSet.of(NAMESPACE);
    String otherLockId = "otherLockId";
    String yetAnotherLockId = "yetAnotherLockId";
    SingleNodeUpdateResponse lockedWithOtherLock = ImmutableSingleNodeUpdateResponse.builder().isSuccessful(false).putLockedNamespaces(NAMESPACE, otherLockId).build();
    SingleNodeUpdateResponse lockedWithYetAnotherLock = ImmutableSingleNodeUpdateResponse.builder().isSuccessful(false).putLockedNamespaces(NAMESPACE, yetAnotherLockId).build();
    when(remote1.reenable(any(), any())).thenReturn(lockedWithOtherLock);
    when(remote2.reenable(any(), any())).thenReturn(SingleNodeUpdateResponse.successful());
    when(localUpdater.reEnable(any())).thenReturn(lockedWithYetAnotherLock);
    ReenableNamespacesResponse reenableResponse = updater.reEnableOnAllNodes(AUTH_HEADER, ReenableNamespacesRequest.of(namespaces, LOCK_ID));
    assertThat(reenableResponse).isEqualTo(partiallyLocked(namespaces));
    verify(remote1, never()).disable(any(), any());
    verify(remote2, never()).disable(any(), any());
}
Also used : UnsuccessfulReenableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulReenableNamespacesResponse) SuccessfulReenableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulReenableNamespacesResponse) ReenableNamespacesResponse(com.palantir.atlasdb.timelock.api.ReenableNamespacesResponse) Namespace(com.palantir.atlasdb.timelock.api.Namespace) SingleNodeUpdateResponse(com.palantir.atlasdb.timelock.api.SingleNodeUpdateResponse) ImmutableSingleNodeUpdateResponse(com.palantir.atlasdb.timelock.api.ImmutableSingleNodeUpdateResponse) Test(org.junit.Test)

Example 40 with Namespace

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

the class AllNodesDisabledNamespacesUpdaterTest method rollsBackDisabledNamespacesAfterPartialFailure.

// Case A: start with no disabled namespaces; disable fails on some node; we should re-enable all
@Test
public void rollsBackDisabledNamespacesAfterPartialFailure() {
    Set<Namespace> failedNamespaces = ImmutableSet.of(OTHER_NAMESPACE);
    when(remote1.disable(any(), any())).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
    when(remote2.disable(any(), any())).thenReturn(singleNodeUpdateFailure(failedNamespaces));
    when(remote1.reenable(any(), any())).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
    when(localUpdater.getNamespacesLockedWithDifferentLockId(any(), any())).thenReturn(ImmutableMap.of());
    DisableNamespacesResponse response = updater.disableOnAllNodes(AUTH_HEADER, disableNamespacesRequest(BOTH_NAMESPACES));
    ReenableNamespacesRequest rollbackRequest = ReenableNamespacesRequest.of(BOTH_NAMESPACES, LOCK_ID);
    verify(remote1).reenable(AUTH_HEADER, rollbackRequest);
    verify(remote2, never()).reenable(AUTH_HEADER, rollbackRequest);
    verify(localUpdater, never()).disable(any());
    assertThat(response).isEqualTo(partiallyDisabled(BOTH_NAMESPACES));
}
Also used : SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) ReenableNamespacesRequest(com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest) 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