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));
}
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));
}
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();
}
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();
}
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());
}
Aggregations