Search in sources :

Example 16 with Namespace

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

the class AtlasBackupServiceTest method completeBackupUnregistersLocks.

@Test
public void completeBackupUnregistersLocks() {
    Set<AtlasService> oneService = ImmutableSet.of(ATLAS_SERVICE);
    Set<Namespace> oneNamespace = ImmutableSet.of(NAMESPACE);
    Set<InProgressBackupToken> tokens = ImmutableSet.of(IN_PROGRESS);
    when(atlasBackupClient.prepareBackup(authHeader, PrepareBackupRequest.of(oneNamespace))).thenReturn(PrepareBackupResponse.of(tokens));
    CompletedBackup completedBackup = completedBackup();
    when(atlasBackupClient.completeBackup(authHeader, CompleteBackupRequest.of(tokens))).thenReturn(CompleteBackupResponse.of(ImmutableSet.of(completedBackup)));
    atlasBackupService.prepareBackup(oneService);
    atlasBackupService.completeBackup(oneService);
    verify(lockRefresher).unregisterLocks(tokens);
}
Also used : AtlasService(com.palantir.atlasdb.backup.api.AtlasService) CompletedBackup(com.palantir.atlasdb.backup.api.CompletedBackup) InProgressBackupToken(com.palantir.atlasdb.backup.api.InProgressBackupToken) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

Example 17 with Namespace

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

the class CassandraRepairEteTest method setUp.

@Before
public void setUp() {
    int replicationFactor = 2;
    config = ThreeNodeCassandraCluster.getKvsConfig();
    runtimeConfig = ThreeNodeCassandraCluster.getRuntimeConfig(replicationFactor);
    kvs = CassandraKeyValueServiceImpl.createForTesting(config, runtimeConfig);
    TransactionTables.createTables(kvs);
    kvs.createTable(TABLE_REF, AtlasDbConstants.GENERIC_TABLE_METADATA);
    kvs.putUnlessExists(TABLE_REF, ImmutableMap.of(NONEMPTY_CELL, CONTENTS));
    KvsRunner kvsRunner = KvsRunner.create(_unused -> kvs);
    Function<AtlasService, CassandraKeyValueServiceConfig> configFactory = _unused -> config;
    Function<AtlasService, Refreshable<CassandraKeyValueServiceRuntimeConfig>> runtimeConfigFactory = _unused -> runtimeConfig;
    Function<AtlasService, CassandraClusterConfig> cassandraClusterConfigFunction = atlasService -> CassandraClusterConfig.of(configFactory.apply(atlasService), runtimeConfigFactory.apply(atlasService).get());
    Function<AtlasService, Refreshable<CassandraServersConfig>> cassandraServersConfigFactory = runtimeConfigFactory.andThen(runtimeConfig -> runtimeConfig.map(CassandraKeyValueServiceRuntimeConfig::servers));
    cassandraRepairHelper = new CassandraRepairHelper(kvsRunner, cassandraClusterConfigFunction, cassandraServersConfigFactory);
    cluster = new ClusterFactory(Cluster::builder).constructCluster(cassandraClusterConfigFunction.apply(ATLAS_SERVICE), cassandraServersConfigFactory.apply(ATLAS_SERVICE).get());
    cqlCluster = new CqlCluster(cluster, cassandraServersConfigFactory.apply(ATLAS_SERVICE).get(), NAMESPACE);
}
Also used : RangeSet(com.google.common.collect.RangeSet) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ServiceId(com.palantir.atlasdb.backup.api.ServiceId) ThreeNodeCassandraCluster(com.palantir.atlasdb.containers.ThreeNodeCassandraCluster) Blacklist(com.palantir.atlasdb.keyvalue.cassandra.Blacklist) ImmutableRangeSet.toImmutableRangeSet(com.google.common.collect.ImmutableRangeSet.toImmutableRangeSet) CqlMetadata(com.palantir.atlasdb.cassandra.backup.CqlMetadata) FullyBoundedTimestampRange(com.palantir.timestamp.FullyBoundedTimestampRange) LightweightOppToken(com.palantir.atlasdb.keyvalue.cassandra.LightweightOppToken) CassandraClientPoolMetrics(com.palantir.atlasdb.keyvalue.cassandra.pool.CassandraClientPoolMetrics) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CassandraKeyValueServiceImpl(com.palantir.atlasdb.keyvalue.cassandra.CassandraKeyValueServiceImpl) Map(java.util.Map) After(org.junit.After) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) CassandraKeyValueService(com.palantir.atlasdb.keyvalue.cassandra.CassandraKeyValueService) DefaultRetryPolicy(com.datastax.driver.core.policies.DefaultRetryPolicy) AtlasDbConstants(com.palantir.atlasdb.AtlasDbConstants) CassandraServersConfig(com.palantir.atlasdb.cassandra.CassandraServersConfigs.CassandraServersConfig) Refreshable(com.palantir.refreshable.Refreshable) CassandraServer(com.palantir.atlasdb.keyvalue.cassandra.pool.CassandraServer) ImmutableMap(com.google.common.collect.ImmutableMap) Cell(com.palantir.atlasdb.keyvalue.api.Cell) KeyedStream(com.palantir.common.streams.KeyedStream) Predicate(java.util.function.Predicate) Range(com.google.common.collect.Range) Set(java.util.Set) RangesForRepair(com.palantir.atlasdb.cassandra.backup.RangesForRepair) InetSocketAddress(java.net.InetSocketAddress) MetricsManagers(com.palantir.atlasdb.util.MetricsManagers) List(java.util.List) Cluster(com.datastax.driver.core.Cluster) Optional(java.util.Optional) Transactions3TableInteraction(com.palantir.atlasdb.cassandra.backup.transaction.Transactions3TableInteraction) CassandraKeyValueServiceConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceConfig) CassandraRepairHelper(com.palantir.atlasdb.cassandra.backup.CassandraRepairHelper) CassandraKeyValueServiceRuntimeConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceRuntimeConfig) TransactionsTableInteraction(com.palantir.atlasdb.cassandra.backup.transaction.TransactionsTableInteraction) ClusterFactory(com.palantir.atlasdb.keyvalue.cassandra.async.client.creation.ClusterFactory) KvsRunner(com.palantir.atlasdb.backup.KvsRunner) CqlCluster(com.palantir.atlasdb.cassandra.backup.CqlCluster) HashMap(java.util.HashMap) Function(java.util.function.Function) PtBytes(com.palantir.atlasdb.encoding.PtBytes) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) Transactions1TableInteraction(com.palantir.atlasdb.cassandra.backup.transaction.Transactions1TableInteraction) TransactionTables(com.palantir.atlasdb.transaction.impl.TransactionTables) BiConsumer(java.util.function.BiConsumer) Before(org.junit.Before) CassandraService(com.palantir.atlasdb.keyvalue.cassandra.pool.CassandraService) Transactions2TableInteraction(com.palantir.atlasdb.cassandra.backup.transaction.Transactions2TableInteraction) CassandraClusterConfig(com.palantir.atlasdb.keyvalue.cassandra.async.client.creation.ClusterFactory.CassandraClusterConfig) Test(org.junit.Test) Namespace(com.palantir.atlasdb.timelock.api.Namespace) TransactionConstants(com.palantir.atlasdb.transaction.impl.TransactionConstants) RangeMap(com.google.common.collect.RangeMap) AtlasService(com.palantir.atlasdb.backup.api.AtlasService) ClusterFactory(com.palantir.atlasdb.keyvalue.cassandra.async.client.creation.ClusterFactory) AtlasService(com.palantir.atlasdb.backup.api.AtlasService) CassandraRepairHelper(com.palantir.atlasdb.cassandra.backup.CassandraRepairHelper) CassandraClusterConfig(com.palantir.atlasdb.keyvalue.cassandra.async.client.creation.ClusterFactory.CassandraClusterConfig) ThreeNodeCassandraCluster(com.palantir.atlasdb.containers.ThreeNodeCassandraCluster) Cluster(com.datastax.driver.core.Cluster) CqlCluster(com.palantir.atlasdb.cassandra.backup.CqlCluster) Refreshable(com.palantir.refreshable.Refreshable) KvsRunner(com.palantir.atlasdb.backup.KvsRunner) CqlCluster(com.palantir.atlasdb.cassandra.backup.CqlCluster) CassandraKeyValueServiceConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceConfig) Before(org.junit.Before)

Example 18 with Namespace

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

the class MultiClientCommitTimestampGetterTest method updatesCacheWhileProcessingResponse.

@Test
public void updatesCacheWhileProcessingResponse() {
    Namespace client = Namespace.of("Kitty");
    List<BatchElement<NamespacedRequest, Long>> batchElements = IntStream.range(0, COMMIT_TS_LIMIT_PER_REQUEST * 2).mapToObj(ind -> batchElementForNamespace(client)).collect(toList());
    setupServiceAndAssertSanityOfResponse(batchElements);
    LockWatchCache cache = lockWatchCacheMap.get(client);
    verify(cache, times(2)).processCommitTimestampsUpdate(any(), any());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DisruptorFuture(com.palantir.atlasdb.autobatch.DisruptorAutobatcher.DisruptorFuture) IntStream(java.util.stream.IntStream) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) LockWatchStateUpdate(com.palantir.lock.watch.LockWatchStateUpdate) HashMap(java.util.HashMap) GetCommitTimestampsRequest(com.palantir.atlasdb.timelock.api.GetCommitTimestampsRequest) Mockito.spy(org.mockito.Mockito.spy) BatchElement(com.palantir.atlasdb.autobatch.BatchElement) ArrayList(java.util.ArrayList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) GetCommitTimestampsResponse(com.palantir.atlasdb.timelock.api.GetCommitTimestampsResponse) LockWatchCache(com.palantir.lock.watch.LockWatchCache) NamespacedRequest(com.palantir.lock.client.MultiClientCommitTimestampGetter.NamespacedRequest) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) KeyedStream(com.palantir.common.streams.KeyedStream) LockToken(com.palantir.lock.v2.LockToken) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) UUID(java.util.UUID) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) Collectors.toList(java.util.stream.Collectors.toList) Mockito.never(org.mockito.Mockito.never) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) StreamEx(one.util.streamex.StreamEx) LockWatchCacheImpl(com.palantir.lock.watch.LockWatchCacheImpl) Mockito.mock(org.mockito.Mockito.mock) LockWatchCache(com.palantir.lock.watch.LockWatchCache) BatchElement(com.palantir.atlasdb.autobatch.BatchElement) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

Example 19 with Namespace

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

the class MultiClientCommitTimestampGetterTest method doesNotUpdateCacheIfClientNotServed.

@Test
public void doesNotUpdateCacheIfClientNotServed() {
    Namespace alpha = Namespace.of("alpha" + UUID.randomUUID());
    Namespace beta = Namespace.of("beta" + UUID.randomUUID());
    BatchElement<NamespacedRequest, Long> requestForAlpha = batchElementForNamespace(alpha);
    BatchElement<NamespacedRequest, Long> requestForBeta = batchElementForNamespace(beta);
    List<BatchElement<NamespacedRequest, Long>> allRequests = ImmutableList.of(requestForAlpha, requestForBeta);
    List<BatchElement<NamespacedRequest, Long>> alphaRequestList = ImmutableList.of(requestForAlpha);
    Map<Namespace, GetCommitTimestampsResponse> responseMap = getCommitTimestamps(alphaRequestList);
    when(timelockService.getCommitTimestamps(any())).thenReturn(responseMap).thenThrow(EXCEPTION);
    assertThatThrownBy(() -> consumer.accept(allRequests)).isEqualTo(EXCEPTION);
    // assert requests made by client alpha are served
    assertSanityOfResponse(alphaRequestList, ImmutableMap.of(alpha, ImmutableList.of(responseMap.get(alpha))));
    LockWatchCache alphaCache = lockWatchCacheMap.get(alpha);
    verify(alphaCache).processCommitTimestampsUpdate(any(), any());
    assertThat(requestForBeta.result().isDone()).as("No requests made by client - beta were successful").isFalse();
    LockWatchCache betaCache = lockWatchCacheMap.get(beta);
    verify(betaCache, never()).processCommitTimestampsUpdate(any(), any());
}
Also used : NamespacedRequest(com.palantir.lock.client.MultiClientCommitTimestampGetter.NamespacedRequest) LockWatchCache(com.palantir.lock.watch.LockWatchCache) BatchElement(com.palantir.atlasdb.autobatch.BatchElement) Namespace(com.palantir.atlasdb.timelock.api.Namespace) GetCommitTimestampsResponse(com.palantir.atlasdb.timelock.api.GetCommitTimestampsResponse) Test(org.junit.Test)

Example 20 with Namespace

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

the class MultiClientTransactionStarterTest method servesRequestsAsSoonAsResponseIsReceived.

@Test
public void servesRequestsAsSoonAsResponseIsReceived() {
    Namespace namespace = Namespace.of("Test" + UUID.randomUUID());
    UUID requestorId = UUID.randomUUID();
    BatchElement<NamespaceAndRequestParams, List<StartIdentifiedAtlasDbTransactionResponse>> requestToBeServed = batchElementForNamespace(namespace, 1);
    BatchElement<NamespaceAndRequestParams, List<StartIdentifiedAtlasDbTransactionResponse>> requestNotToBeServed = batchElementForNamespace(namespace, PARTITIONED_TIMESTAMPS_LIMIT_PER_SERVER_CALL * 5);
    ImmutableList<BatchElement<NamespaceAndRequestParams, List<StartIdentifiedAtlasDbTransactionResponse>>> requests = ImmutableList.of(requestToBeServed, requestNotToBeServed);
    Map<Namespace, ConjureStartTransactionsResponse> responseMap = startTransactionsResponse(requests, requestorId);
    when(timelockService.startTransactions(any())).thenReturn(responseMap).thenThrow(EXCEPTION);
    assertThatThrownBy(() -> processBatch(timelockService, requestorId, requests)).isEqualTo(EXCEPTION);
    // assert first request is served even if server throws on next request
    assertSanityOfRequestBatch(ImmutableList.of(requestToBeServed), ImmutableMap.of(namespace, ImmutableList.of(responseMap.get(namespace))));
    assertThat(requestNotToBeServed.result().isDone()).isFalse();
    LockCleanupService relevantLockCleanupService = LOCK_CLEANUP_SERVICE_MAP.get(namespace);
    verify(relevantLockCleanupService).refreshLockLeases(any());
    verify(relevantLockCleanupService).unlock(any());
    /*
         * For one space, all requests are accumulated, and we attempt to fetch as many respones as possible from the
         * server. Concretely, the queue here contains 25 demands for a response. The first one succeeds, but the
         * next four fail (and each batch size is five), and thus we get four calls to clean up.
         */
    verify(NAMESPACE_CACHE_MAP.get(namespace), times(4)).removeTransactionStateFromCache(anyLong());
}
Also used : StartIdentifiedAtlasDbTransactionResponse(com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse) ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse) NamespaceAndRequestParams(com.palantir.lock.client.MultiClientTransactionStarter.NamespaceAndRequestParams) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) BatchElement(com.palantir.atlasdb.autobatch.BatchElement) UUID(java.util.UUID) 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