Search in sources :

Example 41 with Namespace

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

the class AllNodesDisabledNamespacesUpdaterTest method doesNotReEnableIfSomeNamespaceDisabledWithOtherLock.

// Case B: re-enable with wrong lock -> don't re-enable anywhere
@Test
public void doesNotReEnableIfSomeNamespaceDisabledWithOtherLock() {
    Set<Namespace> disabledNamespaces = ImmutableSet.of(OTHER_NAMESPACE);
    SingleNodeUpdateResponse unsuccessfulResponse = singleNodeUpdateFailure(disabledNamespaces);
    when(remote1.reenable(any(), any())).thenReturn(unsuccessfulResponse);
    when(remote2.reenable(any(), any())).thenReturn(unsuccessfulResponse);
    when(localUpdater.reEnable(any())).thenReturn(unsuccessfulResponse);
    ReenableNamespacesResponse response = updater.reEnableOnAllNodes(AUTH_HEADER, ReenableNamespacesRequest.of(BOTH_NAMESPACES, LOCK_ID));
    assertThat(response).isEqualTo(consistentlyLocked(disabledNamespaces));
}
Also used : UnsuccessfulReenableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulReenableNamespacesResponse) SuccessfulReenableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulReenableNamespacesResponse) ReenableNamespacesResponse(com.palantir.atlasdb.timelock.api.ReenableNamespacesResponse) Namespace(com.palantir.atlasdb.timelock.api.Namespace) SingleNodeUpdateResponse(com.palantir.atlasdb.timelock.api.SingleNodeUpdateResponse) ImmutableSingleNodeUpdateResponse(com.palantir.atlasdb.timelock.api.ImmutableSingleNodeUpdateResponse) Test(org.junit.Test)

Example 42 with Namespace

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

the class AllNodesDisabledNamespacesUpdaterTest method reportsRollbackFailures.

@Test
public void reportsRollbackFailures() {
    Set<Namespace> failedNamespaces = ImmutableSet.of(OTHER_NAMESPACE);
    when(remote1.disable(any(), any())).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
    when(remote2.disable(any(), any())).thenReturn(singleNodeUpdateFailure(failedNamespaces));
    when(localUpdater.getNamespacesLockedWithDifferentLockId(any(), any())).thenReturn(ImmutableMap.of());
    when(remote1.reenable(any(), any())).thenReturn(singleNodeUpdateFailure(failedNamespaces));
    DisableNamespacesResponse response = updater.disableOnAllNodes(AUTH_HEADER, disableNamespacesRequest(BOTH_NAMESPACES));
    verify(remote1).reenable(any(), any());
    verify(remote2, never()).reenable(any(), any());
    verify(localUpdater).getNamespacesLockedWithDifferentLockId(any(), any());
    verifyNoMoreInteractions(localUpdater);
    assertThat(response).isEqualTo(partiallyDisabled(failedNamespaces));
}
Also used : SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

Example 43 with Namespace

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

the class MultiClientConjureTimelockResourceTest method handlesNotCurrentLeaderExceptions.

@Test
public void handlesNotCurrentLeaderExceptions() {
    String throwingClient = "alpha";
    Set<Namespace> namespaces = ImmutableSet.of(Namespace.of(throwingClient), Namespace.of("beta"));
    when(getServiceForClient(throwingClient).leaderTime()).thenThrow(new NotCurrentLeaderException("Not the leader!"));
    assertThatThrownBy(() -> Futures.getUnchecked(resource.leaderTimes(AUTH_HEADER, namespaces))).hasCauseInstanceOf(RetryOther.class).hasRootCauseMessage("Suggesting request retry against: " + REMOTE);
}
Also used : RetryOther(com.palantir.conjure.java.api.errors.QosException.RetryOther) NotCurrentLeaderException(com.palantir.leader.NotCurrentLeaderException) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

Example 44 with Namespace

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

the class TokenRangeFetcher method getTokenRange.

public Map<InetSocketAddress, RangeSet<LightweightOppToken>> getTokenRange(String tableName) {
    KeyspaceMetadata keyspaceMetadata = cqlMetadata.getKeyspaceMetadata(namespace);
    if (keyspaceMetadata == null) {
        log.error("Could not find metadata for a keyspace that is supposed to exist", SafeArg.of("keyspace", namespace));
        return ImmutableMap.of();
    }
    TableMetadata tableMetadata = keyspaceMetadata.getTable(tableName);
    if (tableMetadata == null) {
        log.error("Could not find metadata for table that is supposed to exist", SafeArg.of("keyspace", namespace), SafeArg.of("tableName", tableName));
        return ImmutableMap.of();
    }
    Set<LightweightOppToken> partitionTokens = getPartitionTokens(tableMetadata);
    Map<InetSocketAddress, RangeSet<LightweightOppToken>> tokenRangesByNode = ClusterMetadataUtils.getTokenMapping(CassandraServersConfigs.getCqlHosts(cassandraServersConfig), cqlMetadata, namespace, partitionTokens);
    if (!partitionTokens.isEmpty() && log.isDebugEnabled()) {
        int numTokenRanges = tokenRangesByNode.values().stream().mapToInt(ranges -> ranges.asRanges().size()).sum();
        log.debug("Identified token ranges requiring repair", SafeArg.of("keyspace", namespace), SafeArg.of("table", tableName), SafeArg.of("numPartitionKeys", partitionTokens.size()), SafeArg.of("numTokenRanges", numTokenRanges));
    }
    return tokenRangesByNode;
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) TableMetadata(com.datastax.driver.core.TableMetadata) QueryBuilder(com.datastax.driver.core.querybuilder.QueryBuilder) RangeSet(com.google.common.collect.RangeSet) SafeLoggerFactory(com.palantir.logsafe.logger.SafeLoggerFactory) ImmutableMap(com.google.common.collect.ImmutableMap) CassandraConstants(com.palantir.atlasdb.keyvalue.cassandra.CassandraConstants) Set(java.util.Set) Namespace(com.palantir.atlasdb.timelock.api.Namespace) InetSocketAddress(java.net.InetSocketAddress) ConsistencyLevel(com.datastax.driver.core.ConsistencyLevel) SafeLogger(com.palantir.logsafe.logger.SafeLogger) LightweightOppToken(com.palantir.atlasdb.keyvalue.cassandra.LightweightOppToken) TimeUnit(java.util.concurrent.TimeUnit) SafeArg(com.palantir.logsafe.SafeArg) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata) ImmutableList(com.google.common.collect.ImmutableList) CassandraServersConfigs(com.palantir.atlasdb.cassandra.CassandraServersConfigs) Map(java.util.Map) Statement(com.datastax.driver.core.Statement) CassandraServersConfig(com.palantir.atlasdb.cassandra.CassandraServersConfigs.CassandraServersConfig) LightweightOppToken(com.palantir.atlasdb.keyvalue.cassandra.LightweightOppToken) InetSocketAddress(java.net.InetSocketAddress) RangeSet(com.google.common.collect.RangeSet) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

Example 45 with Namespace

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

the class AtlasBackupServiceTest method completeBackupStoresBackupInfoAndMetadata.

@Test
public void completeBackupStoresBackupInfoAndMetadata() {
    ImmutableSet<Namespace> oneNamespace = ImmutableSet.of(NAMESPACE);
    ImmutableSet<AtlasService> oneService = ImmutableSet.of(ATLAS_SERVICE);
    when(atlasBackupClient.prepareBackup(authHeader, PrepareBackupRequest.of(oneNamespace))).thenReturn(PrepareBackupResponse.of(ImmutableSet.of(IN_PROGRESS)));
    CompletedBackup completedBackup = completedBackup();
    when(atlasBackupClient.completeBackup(authHeader, CompleteBackupRequest.of(ImmutableSet.of(IN_PROGRESS)))).thenReturn(CompleteBackupResponse.of(ImmutableSet.of(completedBackup)));
    atlasBackupService.prepareBackup(oneService);
    atlasBackupService.completeBackup(oneService);
    verify(coordinationServiceRecorder).storeFastForwardState(ATLAS_SERVICE, completedBackup);
    assertThat(backupPersister.getCompletedBackup(ATLAS_SERVICE)).contains(completedBackup);
}
Also used : AtlasService(com.palantir.atlasdb.backup.api.AtlasService) CompletedBackup(com.palantir.atlasdb.backup.api.CompletedBackup) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

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