Search in sources :

Example 1 with Namespace

use of com.palantir.atlasdb.timelock.api.Namespace in project atlasdb by palantir.

the class CoordinationServiceRecorder method storeFastForwardState.

public void storeFastForwardState(CompletedBackup completedBackup) {
    Namespace namespace = completedBackup.getNamespace();
    Optional<InternalSchemaMetadataState> maybeMetadata = fetchSchemaMetadata(namespace, completedBackup.getBackupEndTimestamp());
    maybeMetadata.ifPresentOrElse(metadata -> backupPersister.storeSchemaMetadata(namespace, metadata), () -> logEmptyMetadata(namespace));
}
Also used : InternalSchemaMetadataState(com.palantir.atlasdb.internalschema.InternalSchemaMetadataState) Namespace(com.palantir.atlasdb.timelock.api.Namespace)

Example 2 with Namespace

use of com.palantir.atlasdb.timelock.api.Namespace in project atlasdb by palantir.

the class AtlasRestoreServiceTest method prepareBackupFailsIfDisableFails.

@Test
public void prepareBackupFailsIfDisableFails() {
    DisableNamespacesResponse failedDisable = DisableNamespacesResponse.unsuccessful(UnsuccessfulDisableNamespacesResponse.of(ImmutableSet.of(WITH_BACKUP), ImmutableSet.of()));
    DisableNamespacesRequest request = DisableNamespacesRequest.of(ImmutableSet.of(WITH_BACKUP), BACKUP_ID);
    when(timeLockManagementService.disableTimelock(authHeader, request)).thenReturn(failedDisable);
    Set<Namespace> disabledNamespaces = atlasRestoreService.prepareRestore(ImmutableSet.of(restoreRequest(WITH_BACKUP), restoreRequest(NO_BACKUP)), BACKUP_ID);
    assertThat(disabledNamespaces).isEmpty();
}
Also used : SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) DisableNamespacesRequest(com.palantir.atlasdb.timelock.api.DisableNamespacesRequest) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

Example 3 with Namespace

use of com.palantir.atlasdb.timelock.api.Namespace in project atlasdb by palantir.

the class AtlasRestoreServiceTest method restoresToNewNamespaceCorrectly.

@Test
public void restoresToNewNamespaceCorrectly() {
    RestoreRequest restoreRequest = RestoreRequest.builder().oldNamespace(WITH_BACKUP).newNamespace(NO_BACKUP).build();
    // prepare
    DisableNamespacesResponse successfulDisable = DisableNamespacesResponse.successful(SuccessfulDisableNamespacesResponse.of(BACKUP_ID));
    DisableNamespacesRequest request = DisableNamespacesRequest.of(ImmutableSet.of(NO_BACKUP), BACKUP_ID);
    when(timeLockManagementService.disableTimelock(authHeader, request)).thenReturn(successfulDisable);
    Set<Namespace> disabledNamespaces = atlasRestoreService.prepareRestore(ImmutableSet.of(restoreRequest), BACKUP_ID);
    assertThat(disabledNamespaces).containsExactly(NO_BACKUP);
    // repair
    BiConsumer<String, RangesForRepair> doNothingConsumer = (_unused1, _unused2) -> {
    };
    Set<Namespace> repairedNamespaces = atlasRestoreService.repairInternalTables(ImmutableSet.of(restoreRequest), doNothingConsumer);
    assertThat(repairedNamespaces).containsExactly(NO_BACKUP);
    verify(cassandraRepairHelper).repairInternalTables(NO_BACKUP, doNothingConsumer);
    verify(cassandraRepairHelper).repairTransactionsTables(eq(NO_BACKUP), anyList(), eq(doNothingConsumer));
    verify(cassandraRepairHelper).cleanTransactionsTables(eq(NO_BACKUP), eq(BACKUP_START_TIMESTAMP), anyList());
    verifyNoMoreInteractions(cassandraRepairHelper);
    // complete
    CompletedBackup completedBackup = backupPersister.getCompletedBackup(WITH_BACKUP).orElseThrow();
    CompleteRestoreRequest completeRestoreRequest = CompleteRestoreRequest.of(ImmutableMap.of(NO_BACKUP, completedBackup));
    when(atlasRestoreClient.completeRestore(authHeader, completeRestoreRequest)).thenReturn(CompleteRestoreResponse.of(ImmutableSet.of(NO_BACKUP)));
    ReenableNamespacesRequest reenableRequest = ReenableNamespacesRequest.of(ImmutableSet.of(NO_BACKUP), BACKUP_ID);
    Set<Namespace> completedNamespaces = atlasRestoreService.completeRestore(ImmutableSet.of(restoreRequest), BACKUP_ID);
    assertThat(completedNamespaces).containsExactly(NO_BACKUP);
    verify(atlasRestoreClient).completeRestore(authHeader, completeRestoreRequest);
    verify(timeLockManagementService).reenableTimelock(authHeader, reenableRequest);
}
Also used : RangesForRepair(com.palantir.atlasdb.cassandra.backup.RangesForRepair) CassandraRepairHelper(com.palantir.atlasdb.cassandra.backup.CassandraRepairHelper) CompleteRestoreResponse(com.palantir.atlasdb.backup.api.CompleteRestoreResponse) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtlasRestoreClient(com.palantir.atlasdb.backup.api.AtlasRestoreClient) RunWith(org.junit.runner.RunWith) AuthHeader(com.palantir.tokens.auth.AuthHeader) CompleteRestoreRequest(com.palantir.atlasdb.backup.api.CompleteRestoreRequest) CompletedBackup(com.palantir.atlasdb.backup.api.CompletedBackup) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) ReenableNamespacesRequest(com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest) SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) TimeLockManagementService(com.palantir.atlasdb.timelock.api.management.TimeLockManagementService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) Before(org.junit.Before) ImmutableSet(com.google.common.collect.ImmutableSet) InOrder(org.mockito.InOrder) ImmutableMap(com.google.common.collect.ImmutableMap) KeyedStream(com.palantir.common.streams.KeyedStream) DisableNamespacesRequest(com.palantir.atlasdb.timelock.api.DisableNamespacesRequest) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException) Set(java.util.Set) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) RangesForRepair(com.palantir.atlasdb.cassandra.backup.RangesForRepair) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) Optional(java.util.Optional) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) CompleteRestoreRequest(com.palantir.atlasdb.backup.api.CompleteRestoreRequest) CompletedBackup(com.palantir.atlasdb.backup.api.CompletedBackup) CompleteRestoreRequest(com.palantir.atlasdb.backup.api.CompleteRestoreRequest) ReenableNamespacesRequest(com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest) DisableNamespacesRequest(com.palantir.atlasdb.timelock.api.DisableNamespacesRequest) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

Example 4 with Namespace

use of com.palantir.atlasdb.timelock.api.Namespace in project atlasdb by palantir.

the class BackupAndRestoreEteTest method canPrepareAndCompleteRestore.

@Test
public void canPrepareAndCompleteRestore() {
    addTodo();
    backupResource.prepareBackup(NAMESPACES);
    backupResource.completeBackup(NAMESPACES);
    assertThat(timestampClient.getFreshTimestamp()).isGreaterThan(0L);
    String backupId = "backupId";
    RestoreRequest restoreRequest = RestoreRequest.builder().oldNamespace(NAMESPACE).newNamespace(NAMESPACE).build();
    Set<Namespace> preparedNamespaces = backupResource.prepareRestore(RestoreRequestWithId.of(restoreRequest, backupId));
    assertThat(preparedNamespaces).containsExactly(NAMESPACE);
    // verify TimeLock is disabled
    assertThatRemoteExceptionThrownBy(timestampClient::getFreshTimestamp).isGeneratedFromErrorType(ErrorType.INTERNAL);
    Set<Namespace> completedNamespaces = backupResource.completeRestore(RestoreRequestWithId.of(restoreRequest, backupId));
    assertThat(completedNamespaces).containsExactly(NAMESPACE);
    // verify TimeLock is re-enabled
    assertThat(timestampClient.getFreshTimestamp()).isGreaterThan(0L);
}
Also used : RestoreRequest(com.palantir.atlasdb.backup.RestoreRequest) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

Example 5 with Namespace

use of com.palantir.atlasdb.timelock.api.Namespace in project atlasdb by palantir.

the class ClusterMetadataUtils method getTableMetadata.

public static TableMetadata getTableMetadata(CqlMetadata metadata, Namespace namespace, String table) {
    KeyspaceMetadata keyspaceMetadata = metadata.getKeyspaceMetadata(namespace);
    Optional<TableMetadata> maybeTable = keyspaceMetadata.getTables().stream().filter(tableMetadata -> tableMetadata.getName().equals(table)).collect(MoreCollectors.toOptional());
    return maybeTable.orElseThrow(() -> new SafeIllegalArgumentException("Can't find table", SafeArg.of("keyspace", namespace), LoggingArgs.tableRef("table", TableReference.fromString(table))));
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) RangeSet(com.google.common.collect.RangeSet) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) HashMap(java.util.HashMap) ImmutableRangeSet.toImmutableRangeSet(com.google.common.collect.ImmutableRangeSet.toImmutableRangeSet) Multimap(com.google.common.collect.Multimap) LightweightOppToken(com.palantir.atlasdb.keyvalue.cassandra.LightweightOppToken) SafeArg(com.palantir.logsafe.SafeArg) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) LoggingArgs(com.palantir.atlasdb.logging.LoggingArgs) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) TableMetadata(com.datastax.driver.core.TableMetadata) ImmutableSet(com.google.common.collect.ImmutableSet) KeyedStream(com.palantir.common.streams.KeyedStream) Predicate(java.util.function.Predicate) MoreCollectors(com.google.common.collect.MoreCollectors) Collection(java.util.Collection) Range(com.google.common.collect.Range) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException) Set(java.util.Set) Namespace(com.palantir.atlasdb.timelock.api.Namespace) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) List(java.util.List) Stream(java.util.stream.Stream) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata) TreeMap(java.util.TreeMap) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Preconditions(com.palantir.logsafe.Preconditions) SortedMap(java.util.SortedMap) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException)

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