use of com.palantir.atlasdb.timelock.api.Namespace in project atlasdb by palantir.
the class AtlasRestoreServiceTest method completeRestoreReturnsSuccessfulNamespaces.
@Test
public void completeRestoreReturnsSuccessfulNamespaces() {
Set<AtlasService> atlasServices = ImmutableSet.of(WITH_BACKUP, FAILING_NAMESPACE);
Map<Namespace, CompletedBackup> completedBackups = KeyedStream.of(atlasServices).map(backupPersister::getCompletedBackup).flatMap(Optional::stream).mapKeys(AtlasService::getNamespace).collectToMap();
CompleteRestoreRequest request = CompleteRestoreRequest.of(completedBackups);
when(atlasRestoreClient.completeRestore(authHeader, request)).thenReturn(CompleteRestoreResponse.of(ImmutableSet.of(WITH_BACKUP_NS)));
ReenableNamespacesRequest reenableRequest = ReenableNamespacesRequest.of(ImmutableSet.of(WITH_BACKUP_NS), BACKUP_ID);
Set<RestoreRequest> requests = atlasServices.stream().map(this::restoreRequest).collect(Collectors.toSet());
Set<AtlasService> successfulAtlasServices = atlasRestoreService.completeRestore(requests, BACKUP_ID);
assertThat(successfulAtlasServices).containsExactly(WITH_BACKUP);
verify(atlasRestoreClient).completeRestore(authHeader, request);
verify(timeLockManagementService).reenableTimelock(authHeader, reenableRequest);
}
use of com.palantir.atlasdb.timelock.api.Namespace in project atlasdb by palantir.
the class AtlasRestoreServiceTest method completesRestoreAfterFastForwardingTimestamp.
@Test
public void completesRestoreAfterFastForwardingTimestamp() {
Map<Namespace, CompletedBackup> completedBackups = ImmutableMap.of(WITH_BACKUP_NS, backupPersister.getCompletedBackup(WITH_BACKUP).orElseThrow());
CompleteRestoreRequest completeRequest = CompleteRestoreRequest.of(completedBackups);
when(atlasRestoreClient.completeRestore(authHeader, completeRequest)).thenReturn(CompleteRestoreResponse.of(ImmutableSet.of(WITH_BACKUP_NS)));
ReenableNamespacesRequest reenableRequest = ReenableNamespacesRequest.of(ImmutableSet.of(WITH_BACKUP_NS), BACKUP_ID);
Set<AtlasService> successfulAtlasServices = atlasRestoreService.completeRestore(ImmutableSet.of(restoreRequest(WITH_BACKUP)), BACKUP_ID);
assertThat(successfulAtlasServices).containsExactly(WITH_BACKUP);
InOrder inOrder = Mockito.inOrder(atlasRestoreClient, timeLockManagementService);
inOrder.verify(atlasRestoreClient).completeRestore(authHeader, completeRequest);
inOrder.verify(timeLockManagementService).reenableTimelock(authHeader, reenableRequest);
}
use of com.palantir.atlasdb.timelock.api.Namespace in project atlasdb by palantir.
the class AtlasBackupService method prepareBackup.
public Set<AtlasService> prepareBackup(Set<AtlasService> atlasServices) {
throwIfClosed(atlasServices);
Set<AtlasService> inProgressAndProposedBackups = Sets.union(atlasServices, inProgressBackups.keySet());
AtlasServices.throwIfAtlasServicesCollide(inProgressAndProposedBackups);
Map<Namespace, AtlasService> namespaceToServices = KeyedStream.of(atlasServices).mapKeys(AtlasService::getNamespace).collectToMap();
PrepareBackupRequest request = PrepareBackupRequest.of(namespaceToServices.keySet());
PrepareBackupResponse response = atlasBackupClient.prepareBackup(authHeader, request);
Map<AtlasService, InProgressBackupToken> tokensPerService = KeyedStream.of(response.getSuccessful()).mapKeys(token -> namespaceToServices.get(token.getNamespace())).collectToMap();
KeyedStream.stream(tokensPerService).forEach(this::storeBackupToken);
return tokensPerService.keySet();
}
use of com.palantir.atlasdb.timelock.api.Namespace 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;
}
use of com.palantir.atlasdb.timelock.api.Namespace in project atlasdb by palantir.
the class MultiNodePaxosTimeLockServerIntegrationTest method assertSanityAndStartTransactions.
private Map<Namespace, ConjureStartTransactionsResponse> assertSanityAndStartTransactions(TestableTimelockServer leader, List<String> expectedNamespaces) {
MultiClientConjureTimelockService multiClientConjureTimelockService = leader.multiClientService();
int numTransactions = 5;
Map<Namespace, ConjureStartTransactionsRequest> namespaceToRequestMap = defaultStartTransactionsRequests(expectedNamespaces, numTransactions);
Map<Namespace, ConjureStartTransactionsResponse> startedTransactions = multiClientConjureTimelockService.startTransactionsForClients(AUTH_HEADER, namespaceToRequestMap);
Set<String> namespaces = startedTransactions.keySet().stream().map(Namespace::get).collect(Collectors.toSet());
assertThat(namespaces).hasSameElementsAs(expectedNamespaces);
assertThat(startedTransactions.values().stream().map(ConjureStartTransactionsResponse::getTimestamps).mapToLong(partitionedTimestamps -> partitionedTimestamps.stream().count()).sum()).isEqualTo(namespaces.size() * numTransactions);
return startedTransactions;
}
Aggregations