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