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