Search in sources :

Example 1 with SingleNodeUpdateResponse

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

the class AllNodesDisabledNamespacesUpdaterTest method disableDoesNotReportConsistentStateWhenNamespacesAreLockedWithDifferentIds.

@Test
public void disableDoesNotReportConsistentStateWhenNamespacesAreLockedWithDifferentIds() {
    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.disable(any(), any())).thenReturn(lockedWithOtherLock);
    when(remote2.disable(any(), any())).thenReturn(SingleNodeUpdateResponse.successful());
    when(remote2.reenable(any(), any())).thenReturn(SingleNodeUpdateResponse.successful());
    when(localUpdater.getNamespacesLockedWithDifferentLockId(any(), any())).thenReturn(lockedWithYetAnotherLock.lockedNamespaces());
    DisableNamespacesResponse response = updater.disableOnAllNodes(AUTH_HEADER, disableNamespacesRequest(namespaces));
    verify(remote1, never()).reenable(any(), any());
    verify(remote2).reenable(any(), any());
    assertThat(response).isEqualTo(partiallyDisabled(namespaces));
}
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 2 with SingleNodeUpdateResponse

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

the class DisabledNamespacesTest method disableFailsIfPartiallyDisabledWithOtherLockId.

@Test
public void disableFailsIfPartiallyDisabledWithOtherLockId() {
    String otherLockId = "otherLockId";
    SingleNodeUpdateResponse firstResponse = disabledNamespaces.disable(DisableNamespacesRequest.of(ImmutableSet.of(FIRST), otherLockId));
    assertThat(firstResponse).isEqualTo(successfulResponse());
    SingleNodeUpdateResponse secondResponse = disabledNamespaces.disable(disableNamespacesRequest(SECOND, FIRST));
    assertThat(disabledNamespaces.isDisabled(SECOND)).isFalse();
    assertThat(secondResponse).isEqualTo(unsuccessfulResponse(otherLockId));
    SingleNodeUpdateResponse thirdResponse = disabledNamespaces.disable(disableNamespacesRequest(FIRST, SECOND));
    assertThat(disabledNamespaces.isDisabled(SECOND)).isFalse();
    assertThat(thirdResponse).isEqualTo(unsuccessfulResponse(otherLockId));
}
Also used : SingleNodeUpdateResponse(com.palantir.atlasdb.timelock.api.SingleNodeUpdateResponse) Test(org.junit.Test)

Example 3 with SingleNodeUpdateResponse

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

the class AllNodesDisabledNamespacesUpdater method attemptOnAllNodes.

// Update and analysis
private AllNodesUpdateResponse attemptOnAllNodes(Set<Namespace> namespaces, String lockId, Function<DisabledNamespacesUpdaterService, SingleNodeUpdateResponse> update, Supplier<SingleNodeUpdateResponse> localUpdate, boolean alwaysAttemptOnLocalNode) {
    Map<DisabledNamespacesUpdaterService, SingleNodeUpdateResponse> remoteResponses = attemptOnAllRemoteNodes(update);
    SingleNodeUpdateResponse localResponse = updateLocallyOrCheckState(remoteResponses.values(), namespaces, lockId, localUpdate, alwaysAttemptOnLocalNode);
    return AllNodesUpdateResponse.builder().remoteResponses(remoteResponses).localResponse(localResponse).build();
}
Also used : DisabledNamespacesUpdaterService(com.palantir.atlasdb.timelock.api.DisabledNamespacesUpdaterService) SingleNodeUpdateResponse(com.palantir.atlasdb.timelock.api.SingleNodeUpdateResponse)

Example 4 with SingleNodeUpdateResponse

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

the class AllNodesDisabledNamespacesUpdater method attemptReEnableOnNodes.

// ReEnable
private boolean attemptReEnableOnNodes(AuthHeader authHeader, Set<Namespace> namespaces, String lockId, List<DisabledNamespacesUpdaterService> successfulNodes) {
    ReenableNamespacesRequest request = ReenableNamespacesRequest.builder().namespaces(namespaces).lockId(lockId).build();
    Collection<SingleNodeUpdateResponse> responses = reEnableNamespacesOnRemoteNodes(authHeader, request, successfulNodes);
    return responses.stream().filter(SingleNodeUpdateResponse::isSuccessful).count() == successfulNodes.size();
}
Also used : ReenableNamespacesRequest(com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest) SingleNodeUpdateResponse(com.palantir.atlasdb.timelock.api.SingleNodeUpdateResponse)

Example 5 with SingleNodeUpdateResponse

use of com.palantir.atlasdb.timelock.api.SingleNodeUpdateResponse 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)

Aggregations

SingleNodeUpdateResponse (com.palantir.atlasdb.timelock.api.SingleNodeUpdateResponse)11 Test (org.junit.Test)9 ImmutableSingleNodeUpdateResponse (com.palantir.atlasdb.timelock.api.ImmutableSingleNodeUpdateResponse)5 Namespace (com.palantir.atlasdb.timelock.api.Namespace)5 DisableNamespacesResponse (com.palantir.atlasdb.timelock.api.DisableNamespacesResponse)3 SuccessfulDisableNamespacesResponse (com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse)3 UnsuccessfulDisableNamespacesResponse (com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse)3 ReenableNamespacesRequest (com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest)2 ReenableNamespacesResponse (com.palantir.atlasdb.timelock.api.ReenableNamespacesResponse)2 SuccessfulReenableNamespacesResponse (com.palantir.atlasdb.timelock.api.SuccessfulReenableNamespacesResponse)2 UnsuccessfulReenableNamespacesResponse (com.palantir.atlasdb.timelock.api.UnsuccessfulReenableNamespacesResponse)2 DisableNamespacesRequest (com.palantir.atlasdb.timelock.api.DisableNamespacesRequest)1 DisabledNamespacesUpdaterService (com.palantir.atlasdb.timelock.api.DisabledNamespacesUpdaterService)1