Search in sources :

Example 46 with Namespace

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);
}
Also used : CompleteRestoreRequest(com.palantir.atlasdb.backup.api.CompleteRestoreRequest) AtlasService(com.palantir.atlasdb.backup.api.AtlasService) Optional(java.util.Optional) CompletedBackup(com.palantir.atlasdb.backup.api.CompletedBackup) ReenableNamespacesRequest(com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest) CompleteRestoreRequest(com.palantir.atlasdb.backup.api.CompleteRestoreRequest) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

Example 47 with Namespace

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);
}
Also used : CompleteRestoreRequest(com.palantir.atlasdb.backup.api.CompleteRestoreRequest) AtlasService(com.palantir.atlasdb.backup.api.AtlasService) InOrder(org.mockito.InOrder) CompletedBackup(com.palantir.atlasdb.backup.api.CompletedBackup) ReenableNamespacesRequest(com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

Example 48 with Namespace

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();
}
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) AtlasService(com.palantir.atlasdb.backup.api.AtlasService) PrepareBackupResponse(com.palantir.atlasdb.backup.api.PrepareBackupResponse) InProgressBackupToken(com.palantir.atlasdb.backup.api.InProgressBackupToken) Namespace(com.palantir.atlasdb.timelock.api.Namespace) PrepareBackupRequest(com.palantir.atlasdb.backup.api.PrepareBackupRequest)

Example 49 with Namespace

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

Example 50 with Namespace

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;
}
Also used : MethodSorters(org.junit.runners.MethodSorters) LeadershipId(com.palantir.lock.v2.LeadershipId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) AuthHeader(com.palantir.tokens.auth.AuthHeader) ConjureLockDescriptor(com.palantir.atlasdb.timelock.api.ConjureLockDescriptor) MultiLeaderPaxosSuite(com.palantir.atlasdb.timelock.suite.MultiLeaderPaxosSuite) LockWatchStateUpdate(com.palantir.lock.watch.LockWatchStateUpdate) Bytes(com.palantir.conjure.java.lib.Bytes) ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse) ConjureStartTransactionsRequest(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest) LeaderTime(com.palantir.lock.v2.LeaderTime) ConjureLockRequest(com.palantir.atlasdb.timelock.api.ConjureLockRequest) Duration(java.time.Duration) Map(java.util.Map) GetCommitTimestampsResponse(com.palantir.atlasdb.timelock.api.GetCommitTimestampsResponse) SuccessfulLockResponse(com.palantir.atlasdb.timelock.api.SuccessfulLockResponse) ConjureLockResponse(com.palantir.atlasdb.timelock.api.ConjureLockResponse) ClassRule(org.junit.ClassRule) Parameterized(org.junit.runners.Parameterized) LockDescriptor(com.palantir.lock.LockDescriptor) ConjureLockToken(com.palantir.atlasdb.timelock.api.ConjureLockToken) ImmutableSet(com.google.common.collect.ImmutableSet) KeyedStream(com.palantir.common.streams.KeyedStream) ConjureLockRequests(com.palantir.lock.client.ConjureLockRequests) Set(java.util.Set) ConjureUnlockRequest(com.palantir.atlasdb.timelock.api.ConjureUnlockRequest) UUID(java.util.UUID) ConjureLockRefreshToken(com.palantir.lock.ConjureLockRefreshToken) LockMode(com.palantir.lock.LockMode) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) Stream(java.util.stream.Stream) ClientOptionsConstants(com.palantir.atlasdb.http.v2.ClientOptionsConstants) PartitionedTimestamps(com.palantir.lock.v2.PartitionedTimestamps) Optional(java.util.Optional) ConjureLockV1Request(com.palantir.lock.ConjureLockV1Request) FixMethodOrder(org.junit.FixMethodOrder) WaitForLocksRequest(com.palantir.lock.v2.WaitForLocksRequest) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) MultiClientConjureTimelockService(com.palantir.atlasdb.timelock.api.MultiClientConjureTimelockService) ExceptionMatchers(com.palantir.atlasdb.timelock.util.ExceptionMatchers) Iterables(com.google.common.collect.Iterables) HeldLocksToken(com.palantir.lock.HeldLocksToken) RunWith(org.junit.runner.RunWith) GetCommitTimestampsRequest(com.palantir.atlasdb.timelock.api.GetCommitTimestampsRequest) UnsuccessfulLockResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulLockResponse) SimpleHeldLocksToken(com.palantir.lock.SimpleHeldLocksToken) LockRefreshToken(com.palantir.lock.LockRefreshToken) PtBytes(com.palantir.atlasdb.encoding.PtBytes) HashSet(java.util.HashSet) ConjureSimpleHeldLocksToken(com.palantir.lock.ConjureSimpleHeldLocksToken) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ImmutableList(com.google.common.collect.ImmutableList) WaitForLocksResponse(com.palantir.lock.v2.WaitForLocksResponse) Assume(org.junit.Assume) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Before(org.junit.Before) LockResponse(com.palantir.lock.v2.LockResponse) LockToken(com.palantir.lock.v2.LockToken) Test(org.junit.Test) ConjureRefreshLocksRequest(com.palantir.atlasdb.timelock.api.ConjureRefreshLocksRequest) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Ints(com.google.common.primitives.Ints) ExecutionException(java.util.concurrent.ExecutionException) LockRequest(com.palantir.lock.v2.LockRequest) LockClient(com.palantir.lock.LockClient) StringLockDescriptor(com.palantir.lock.StringLockDescriptor) LeaderTimes(com.palantir.atlasdb.timelock.api.LeaderTimes) ParameterInjector(com.palantir.atlasdb.timelock.util.ParameterInjector) ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse) MultiClientConjureTimelockService(com.palantir.atlasdb.timelock.api.MultiClientConjureTimelockService) ConjureStartTransactionsRequest(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest) Namespace(com.palantir.atlasdb.timelock.api.Namespace)

Aggregations

Namespace (com.palantir.atlasdb.timelock.api.Namespace)53 Test (org.junit.Test)39 ImmutableList (com.google.common.collect.ImmutableList)12 List (java.util.List)11 Map (java.util.Map)11 Set (java.util.Set)11 UUID (java.util.UUID)11 AtlasService (com.palantir.atlasdb.backup.api.AtlasService)10 CompletedBackup (com.palantir.atlasdb.backup.api.CompletedBackup)10 ConjureStartTransactionsResponse (com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse)10 DisableNamespacesResponse (com.palantir.atlasdb.timelock.api.DisableNamespacesResponse)9 SuccessfulDisableNamespacesResponse (com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse)9 UnsuccessfulDisableNamespacesResponse (com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse)9 KeyedStream (com.palantir.common.streams.KeyedStream)9 ImmutableSet (com.google.common.collect.ImmutableSet)8 SafeIllegalStateException (com.palantir.logsafe.exceptions.SafeIllegalStateException)8 Collectors (java.util.stream.Collectors)8 BatchElement (com.palantir.atlasdb.autobatch.BatchElement)7 ReenableNamespacesRequest (com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest)7 ArrayList (java.util.ArrayList)7