Search in sources :

Example 1 with CompleteBackupResponse

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

the class AtlasBackupService method completeBackup.

public Set<Namespace> completeBackup(Set<Namespace> namespaces) {
    Set<InProgressBackupToken> tokens = namespaces.stream().map(inProgressBackups::remove).filter(Objects::nonNull).collect(Collectors.toSet());
    CompleteBackupRequest request = CompleteBackupRequest.of(tokens);
    CompleteBackupResponse response = atlasBackupClient.completeBackup(authHeader, request);
    return response.getSuccessfulBackups().stream().peek(coordinationServiceRecorder::storeFastForwardState).peek(backupPersister::storeCompletedBackup).map(CompletedBackup::getNamespace).collect(Collectors.toSet());
}
Also used : CompleteBackupResponse(com.palantir.atlasdb.backup.api.CompleteBackupResponse) CompleteBackupRequest(com.palantir.atlasdb.backup.api.CompleteBackupRequest) InProgressBackupToken(com.palantir.atlasdb.backup.api.InProgressBackupToken)

Example 2 with CompleteBackupResponse

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

the class AtlasBackupService method completeBackup.

/**
 * Completes backup for the given set of atlas services.
 * This will store metadata about the completed backup via the BackupPersister.
 * <p>
 * In order to do this, we must unlock the immutable timestamp for each service. If {@link #prepareBackup(Set)}
 * was not called, we will not have a record of the in-progress backup (and will not have been refreshing
 * its lock anyway). Thus, we attempt to complete backup only for those atlas services where we have the in-progress
 * backup stored.
 *
 * @return the atlas services whose backups were successfully completed
 */
public Set<AtlasService> completeBackup(Set<AtlasService> atlasServices) {
    throwIfClosed(atlasServices);
    AtlasServices.throwIfAtlasServicesCollide(atlasServices);
    Map<AtlasService, InProgressBackupToken> knownBackups = KeyedStream.of(atlasServices).map((Function<AtlasService, InProgressBackupToken>) inProgressBackups::remove).filter(Objects::nonNull).collectToMap();
    Set<InProgressBackupToken> tokens = ImmutableSet.copyOf(knownBackups.values());
    if (tokens.isEmpty()) {
        log.error("Complete backup called, but no in progress backups were found.", SafeArg.of("atlasServices", atlasServices));
        return ImmutableSet.of();
    }
    lockRefresher.unregisterLocks(tokens);
    Set<AtlasService> atlasServicesWithInProgressBackups = knownBackups.keySet();
    if (tokens.size() < atlasServices.size()) {
        Set<AtlasService> atlasServicesWithNoInProgressBackup = Sets.difference(atlasServices, atlasServicesWithInProgressBackups);
        log.error("In progress backups were not found for some atlasServices. We will not complete backup for these.", SafeArg.of("numAtlasServicesWithBackup", tokens.size()), SafeArg.of("numAtlasServicesWithoutBackup", atlasServicesWithNoInProgressBackup.size()), SafeArg.of("atlasServicesWithoutBackup", atlasServicesWithNoInProgressBackup), SafeArg.of("allRequestedAtlasServices", atlasServices));
    }
    Map<Namespace, AtlasService> namespaceToServices = KeyedStream.of(atlasServices).mapKeys(AtlasService::getNamespace).collectToMap();
    CompleteBackupRequest request = CompleteBackupRequest.of(tokens);
    CompleteBackupResponse response = atlasBackupClient.completeBackup(authHeader, request);
    Map<AtlasService, CompletedBackup> successfulBackups = KeyedStream.of(response.getSuccessfulBackups()).mapKeys(token -> namespaceToServices.get(token.getNamespace())).collectToMap();
    Set<AtlasService> successfullyStoredBackups = storeCompletedBackups(successfulBackups);
    if (successfullyStoredBackups.size() < atlasServicesWithInProgressBackups.size()) {
        Set<AtlasService> failedAtlasServices = Sets.difference(atlasServicesWithInProgressBackups, successfullyStoredBackups);
        log.error("Backup did not complete successfully for all atlasServices. Check TimeLock logs to debug.", SafeArg.of("failedAtlasServices", failedAtlasServices), SafeArg.of("successfulAtlasServices", successfullyStoredBackups), SafeArg.of("atlasServicesWithoutBackup", atlasServicesWithInProgressBackups));
    }
    return successfulBackups.keySet();
}
Also used : PrepareBackupResponse(com.palantir.atlasdb.backup.api.PrepareBackupResponse) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) SafeLoggerFactory(com.palantir.logsafe.logger.SafeLoggerFactory) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) AtlasBackupClient(com.palantir.atlasdb.backup.api.AtlasBackupClient) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) AtlasBackupClientBlocking(com.palantir.atlasdb.backup.api.AtlasBackupClientBlocking) AuthHeader(com.palantir.tokens.auth.AuthHeader) CompletedBackup(com.palantir.atlasdb.backup.api.CompletedBackup) Function(java.util.function.Function) SafeLogger(com.palantir.logsafe.logger.SafeLogger) SafeArg(com.palantir.logsafe.SafeArg) CompleteBackupResponse(com.palantir.atlasdb.backup.api.CompleteBackupResponse) PTExecutors(com.palantir.common.concurrent.PTExecutors) UserAgent(com.palantir.conjure.java.api.config.service.UserAgent) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) AtlasFutures(com.palantir.atlasdb.futures.AtlasFutures) Path(java.nio.file.Path) ExecutorService(java.util.concurrent.ExecutorService) Refreshable(com.palantir.refreshable.Refreshable) ImmutableSet(com.google.common.collect.ImmutableSet) NamedThreadFactory(com.palantir.common.concurrent.NamedThreadFactory) CompleteBackupRequest(com.palantir.atlasdb.backup.api.CompleteBackupRequest) KeyedStream(com.palantir.common.streams.KeyedStream) PrepareBackupRequest(com.palantir.atlasdb.backup.api.PrepareBackupRequest) ReloadingFactory(com.palantir.dialogue.clients.DialogueClients.ReloadingFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) InProgressBackupToken(com.palantir.atlasdb.backup.api.InProgressBackupToken) TransactionManager(com.palantir.atlasdb.transaction.api.TransactionManager) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) RefreshBackupRequest(com.palantir.atlasdb.backup.api.RefreshBackupRequest) ServicesConfigBlock(com.palantir.conjure.java.api.config.service.ServicesConfigBlock) Futures(com.google.common.util.concurrent.Futures) LockLeaseRefresher(com.palantir.lock.v2.LockLeaseRefresher) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) AtlasDbRemotingConstants(com.palantir.atlasdb.http.AtlasDbRemotingConstants) Closeable(java.io.Closeable) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AtlasService(com.palantir.atlasdb.backup.api.AtlasService) DialogueClients(com.palantir.dialogue.clients.DialogueClients) LockRefresher(com.palantir.lock.client.LockRefresher) CompleteBackupResponse(com.palantir.atlasdb.backup.api.CompleteBackupResponse) AtlasService(com.palantir.atlasdb.backup.api.AtlasService) CompleteBackupRequest(com.palantir.atlasdb.backup.api.CompleteBackupRequest) CompletedBackup(com.palantir.atlasdb.backup.api.CompletedBackup) InProgressBackupToken(com.palantir.atlasdb.backup.api.InProgressBackupToken) Namespace(com.palantir.atlasdb.timelock.api.Namespace)

Aggregations

CompleteBackupRequest (com.palantir.atlasdb.backup.api.CompleteBackupRequest)2 CompleteBackupResponse (com.palantir.atlasdb.backup.api.CompleteBackupResponse)2 InProgressBackupToken (com.palantir.atlasdb.backup.api.InProgressBackupToken)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Sets (com.google.common.collect.Sets)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 AtlasBackupClient (com.palantir.atlasdb.backup.api.AtlasBackupClient)1 AtlasBackupClientBlocking (com.palantir.atlasdb.backup.api.AtlasBackupClientBlocking)1 AtlasService (com.palantir.atlasdb.backup.api.AtlasService)1 CompletedBackup (com.palantir.atlasdb.backup.api.CompletedBackup)1 PrepareBackupRequest (com.palantir.atlasdb.backup.api.PrepareBackupRequest)1 PrepareBackupResponse (com.palantir.atlasdb.backup.api.PrepareBackupResponse)1 RefreshBackupRequest (com.palantir.atlasdb.backup.api.RefreshBackupRequest)1 AtlasFutures (com.palantir.atlasdb.futures.AtlasFutures)1 AtlasDbRemotingConstants (com.palantir.atlasdb.http.AtlasDbRemotingConstants)1 KeyValueService (com.palantir.atlasdb.keyvalue.api.KeyValueService)1 Namespace (com.palantir.atlasdb.timelock.api.Namespace)1