Search in sources :

Example 1 with CompleteRestoreResponse

use of com.palantir.atlasdb.backup.api.CompleteRestoreResponse in project atlasdb by palantir.

the class AtlasRestoreResourceTest method completesRestoreSuccessfully.

@Test
public void completesRestoreSuccessfully() {
    Namespace newNamespace = Namespace.of("newNamespace");
    CompletedBackup completedBackup = completedBackup();
    CompleteRestoreResponse response = AtlasFutures.getUnchecked(atlasRestoreResource.completeRestore(AUTH_HEADER, CompleteRestoreRequest.of(ImmutableMap.of(newNamespace, completedBackup))));
    assertThat(response.getSuccessfulNamespaces()).containsExactly(newNamespace);
    verify(otherTimelock).fastForwardTimestamp(completedBackup.getBackupEndTimestamp());
}
Also used : CompletedBackup(com.palantir.atlasdb.backup.api.CompletedBackup) CompleteRestoreResponse(com.palantir.atlasdb.backup.api.CompleteRestoreResponse) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

Example 2 with CompleteRestoreResponse

use of com.palantir.atlasdb.backup.api.CompleteRestoreResponse in project atlasdb by palantir.

the class AtlasRestoreService method completeRestore.

/**
 * Completes the restore process for the requested atlasServices.
 * This includes fast-forwarding the timestamp, and then re-enabling the TimeLock namespaces.
 *
 * @param restoreRequests the requests to complete.
 * @param backupId the backup identifier, which must match the one given to {@link #prepareRestore(Set, String)}
 * @return the set of atlasServices that were successfully fast-forwarded and re-enabled.
 */
public Set<AtlasService> completeRestore(Set<RestoreRequest> restoreRequests, String backupId) {
    validateRestoreRequests(restoreRequests);
    Map<RestoreRequest, CompletedBackup> completedBackups = getCompletedBackups(restoreRequests);
    Set<AtlasService> atlasServicesToRestore = getAtlasServicesToRestore(completedBackups);
    if (completedBackups.isEmpty()) {
        log.info("Attempted to complete restore, but no completed backups were found", SafeArg.of("restoreRequests", restoreRequests));
        return ImmutableSet.of();
    } else if (completedBackups.size() < restoreRequests.size()) {
        Set<AtlasService> atlasServicesWithBackup = completedBackups.keySet().stream().map(RestoreRequest::oldAtlasService).collect(Collectors.toSet());
        Set<AtlasService> allOldAtlasServices = restoreRequests.stream().map(RestoreRequest::oldAtlasService).collect(Collectors.toSet());
        Set<AtlasService> atlasServicesWithoutBackup = Sets.difference(allOldAtlasServices, atlasServicesWithBackup);
        log.warn("Completed backups were not found for some atlasServices", SafeArg.of("atlasServicesWithBackup", atlasServicesWithBackup), SafeArg.of("atlasServicesWithoutBackup", atlasServicesWithoutBackup));
    }
    // Fast forward timestamps
    Map<Namespace, CompletedBackup> completeRequest = KeyedStream.stream(completedBackups).mapKeys(RestoreRequest::newAtlasService).mapKeys(AtlasService::getNamespace).collectToMap();
    Map<Namespace, AtlasService> namespaceToServices = KeyedStream.of(atlasServicesToRestore).mapKeys(AtlasService::getNamespace).collectToMap();
    CompleteRestoreResponse response = atlasRestoreClient.completeRestore(authHeader, CompleteRestoreRequest.of(completeRequest));
    Set<AtlasService> successfulAtlasServices = response.getSuccessfulNamespaces().stream().map(namespaceToServices::get).collect(Collectors.toSet());
    Set<AtlasService> failedAtlasServices = Sets.difference(atlasServicesToRestore, successfulAtlasServices);
    if (failedAtlasServices.isEmpty()) {
        log.info("Successfully completed restore for all atlasServices", SafeArg.of("atlasServices", successfulAtlasServices));
    } else {
        log.error("Failed to fast-forward timestamp for some atlasServices. These will not be re-enabled.", SafeArg.of("failedAtlasServices", failedAtlasServices), SafeArg.of("fastForwardedAtlasServices", successfulAtlasServices));
    }
    // Re-enable timelock
    timeLockManagementService.reenableTimelock(authHeader, ReenableNamespacesRequest.of(response.getSuccessfulNamespaces(), backupId));
    return successfulAtlasServices;
}
Also used : AtlasService(com.palantir.atlasdb.backup.api.AtlasService) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) CompletedBackup(com.palantir.atlasdb.backup.api.CompletedBackup) CompleteRestoreResponse(com.palantir.atlasdb.backup.api.CompleteRestoreResponse) CompleteRestoreRequest(com.palantir.atlasdb.backup.api.CompleteRestoreRequest) Namespace(com.palantir.atlasdb.timelock.api.Namespace)

Aggregations

CompleteRestoreResponse (com.palantir.atlasdb.backup.api.CompleteRestoreResponse)2 CompletedBackup (com.palantir.atlasdb.backup.api.CompletedBackup)2 Namespace (com.palantir.atlasdb.timelock.api.Namespace)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 AtlasService (com.palantir.atlasdb.backup.api.AtlasService)1 CompleteRestoreRequest (com.palantir.atlasdb.backup.api.CompleteRestoreRequest)1 Set (java.util.Set)1 Test (org.junit.Test)1