Search in sources :

Example 6 with DisableNamespacesResponse

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

the class AtlasRestoreService method prepareRestore.

/**
 * Disables TimeLock on all nodes for the given atlasServices.
 * This will fail if any atlasService is already disabled, unless it was disabled with the provided backupId.
 * AtlasServices for which we don't have a recorded backup will be ignored.
 *
 * @param restoreRequests the requests to prepare.
 * @param backupId a unique identifier for this request (uniquely identifies the backup to which we're restoring)
 *
 * @return the atlasServices successfully disabled.
 */
public Set<AtlasService> prepareRestore(Set<RestoreRequest> restoreRequests, String backupId) {
    validateRestoreRequests(restoreRequests);
    Map<RestoreRequest, CompletedBackup> completedBackups = getCompletedBackups(restoreRequests);
    Set<AtlasService> atlasServicesToRestore = getAtlasServicesToRestore(completedBackups);
    Preconditions.checkArgument(atlasServicesToRestore.size() == completedBackups.size(), "Attempting to restore multiple atlasServices into the same atlasService! " + "This will cause severe data corruption.", SafeArg.of("restoreRequests", restoreRequests));
    Set<Namespace> namespacesToRestore = atlasServicesToRestore.stream().map(AtlasService::getNamespace).collect(Collectors.toSet());
    DisableNamespacesRequest request = DisableNamespacesRequest.of(namespacesToRestore, backupId);
    DisableNamespacesResponse response = timeLockManagementService.disableTimelock(authHeader, request);
    return response.accept(new DisableNamespacesResponse.Visitor<>() {

        @Override
        public Set<AtlasService> visitSuccessful(SuccessfulDisableNamespacesResponse value) {
            return atlasServicesToRestore;
        }

        @Override
        public Set<AtlasService> visitUnsuccessful(UnsuccessfulDisableNamespacesResponse value) {
            log.error("Failed to disable namespaces prior to restore", SafeArg.of("requests", restoreRequests), SafeArg.of("response", value));
            return ImmutableSet.of();
        }

        @Override
        public Set<AtlasService> visitUnknown(String unknownType) {
            throw new SafeIllegalStateException("Unknown DisableNamespacesResponse", SafeArg.of("unknownType", unknownType));
        }
    });
}
Also used : AtlasService(com.palantir.atlasdb.backup.api.AtlasService) SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Namespace(com.palantir.atlasdb.timelock.api.Namespace) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) CompletedBackup(com.palantir.atlasdb.backup.api.CompletedBackup) CompleteRestoreRequest(com.palantir.atlasdb.backup.api.CompleteRestoreRequest) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) DisableNamespacesRequest(com.palantir.atlasdb.timelock.api.DisableNamespacesRequest)

Example 7 with DisableNamespacesResponse

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

the class AtlasRestoreServiceTest method prepareReturnsOnlyCompletedBackups.

@Test
public void prepareReturnsOnlyCompletedBackups() {
    DisableNamespacesResponse successfulDisable = DisableNamespacesResponse.successful(SuccessfulDisableNamespacesResponse.of(BACKUP_ID));
    DisableNamespacesRequest request = DisableNamespacesRequest.of(ImmutableSet.of(WITH_BACKUP_NS), BACKUP_ID);
    when(timeLockManagementService.disableTimelock(authHeader, request)).thenReturn(successfulDisable);
    Set<AtlasService> disabledAtlasServices = atlasRestoreService.prepareRestore(ImmutableSet.of(restoreRequest(WITH_BACKUP), restoreRequest(NO_BACKUP)), BACKUP_ID);
    assertThat(disabledAtlasServices).containsExactly(WITH_BACKUP);
}
Also used : SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) AtlasService(com.palantir.atlasdb.backup.api.AtlasService) DisableNamespacesRequest(com.palantir.atlasdb.timelock.api.DisableNamespacesRequest) Test(org.junit.Test)

Example 8 with DisableNamespacesResponse

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

the class AllNodesDisabledNamespacesUpdaterTest method canDisableSingleNamespace.

@Test
public void canDisableSingleNamespace() {
    when(remote1.disable(any(), any())).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
    when(remote2.disable(any(), any())).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
    when(localUpdater.disable(any(DisableNamespacesRequest.class))).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
    DisableNamespacesResponse response = updater.disableOnAllNodes(AUTH_HEADER, disableNamespacesRequest(ImmutableSet.of(NAMESPACE)));
    assertThat(response).isEqualTo(successfulDisableResponse());
}
Also used : SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) DisableNamespacesRequest(com.palantir.atlasdb.timelock.api.DisableNamespacesRequest) Test(org.junit.Test)

Example 9 with DisableNamespacesResponse

use of com.palantir.atlasdb.timelock.api.DisableNamespacesResponse 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 10 with DisableNamespacesResponse

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

Aggregations

DisableNamespacesResponse (com.palantir.atlasdb.timelock.api.DisableNamespacesResponse)15 SuccessfulDisableNamespacesResponse (com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse)15 UnsuccessfulDisableNamespacesResponse (com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse)15 Test (org.junit.Test)14 Namespace (com.palantir.atlasdb.timelock.api.Namespace)10 DisableNamespacesRequest (com.palantir.atlasdb.timelock.api.DisableNamespacesRequest)7 ReenableNamespacesRequest (com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest)5 AtlasService (com.palantir.atlasdb.backup.api.AtlasService)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 CompleteRestoreRequest (com.palantir.atlasdb.backup.api.CompleteRestoreRequest)3 CompletedBackup (com.palantir.atlasdb.backup.api.CompletedBackup)3 ImmutableSingleNodeUpdateResponse (com.palantir.atlasdb.timelock.api.ImmutableSingleNodeUpdateResponse)3 SingleNodeUpdateResponse (com.palantir.atlasdb.timelock.api.SingleNodeUpdateResponse)3 Set (java.util.Set)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 AtlasRestoreClient (com.palantir.atlasdb.backup.api.AtlasRestoreClient)2 CompleteRestoreResponse (com.palantir.atlasdb.backup.api.CompleteRestoreResponse)2 CassandraRepairHelper (com.palantir.atlasdb.cassandra.backup.CassandraRepairHelper)2 RangesForRepair (com.palantir.atlasdb.cassandra.backup.RangesForRepair)2 TimeLockManagementService (com.palantir.atlasdb.timelock.api.management.TimeLockManagementService)2