Search in sources :

Example 1 with Refreshable

use of com.palantir.refreshable.Refreshable in project atlasdb by palantir.

the class CassandraSchemaLockTest method shouldCreateTablesConsistentlyWithMultipleCassandraNodes.

@Test
public void shouldCreateTablesConsistentlyWithMultipleCassandraNodes() throws Exception {
    TableReference table1 = TableReference.createFromFullyQualifiedName("ns.table1");
    CassandraKeyValueServiceConfig config = ThreeNodeCassandraCluster.KVS_CONFIG;
    Refreshable<CassandraKeyValueServiceRuntimeConfig> runtimeConfig = ThreeNodeCassandraCluster.KVS_RUNTIME_CONFIG;
    try {
        CyclicBarrier barrier = new CyclicBarrier(THREAD_COUNT);
        for (int i = 0; i < THREAD_COUNT; i++) {
            async(() -> {
                CassandraKeyValueService keyValueService = CassandraKeyValueServiceImpl.createForTesting(config, runtimeConfig);
                barrier.await();
                keyValueService.createTable(table1, AtlasDbConstants.GENERIC_TABLE_METADATA);
                return null;
            });
        }
    } finally {
        executorService.shutdown();
        assertThat(executorService.awaitTermination(4, TimeUnit.MINUTES)).isTrue();
    }
    CassandraKeyValueService kvs = CassandraKeyValueServiceImpl.createForTesting(config, runtimeConfig);
    assertThat(kvs.getAllTableNames()).contains(table1);
    assertThat(new File(CONTAINERS.getLogDirectory()).listFiles()).allSatisfy(file -> {
        Path path = Paths.get(file.getAbsolutePath());
        try (Stream<String> lines = Files.lines(path, StandardCharsets.ISO_8859_1)) {
            List<String> badLines = lines.filter(line -> line.contains("Column family ID mismatch")).collect(Collectors.toList());
            assertThat(badLines).describedAs("File called %s which contains lines %s", file.getAbsolutePath(), badLines).isEmpty();
        } catch (IOException e) {
            throw Throwables.propagate(e);
        }
    });
}
Also used : Path(java.nio.file.Path) Containers(com.palantir.atlasdb.containers.Containers) CassandraKeyValueServiceConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceConfig) CassandraKeyValueServiceRuntimeConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceRuntimeConfig) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ThreeNodeCassandraCluster(com.palantir.atlasdb.containers.ThreeNodeCassandraCluster) Callable(java.util.concurrent.Callable) CassandraKeyValueServiceImpl(com.palantir.atlasdb.keyvalue.cassandra.CassandraKeyValueServiceImpl) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) CassandraKeyValueService(com.palantir.atlasdb.keyvalue.cassandra.CassandraKeyValueService) ClassRule(org.junit.ClassRule) Path(java.nio.file.Path) ExecutorService(java.util.concurrent.ExecutorService) AtlasDbConstants(com.palantir.atlasdb.AtlasDbConstants) Refreshable(com.palantir.refreshable.Refreshable) CyclicBarrier(java.util.concurrent.CyclicBarrier) Files(java.nio.file.Files) Throwables(com.google.common.base.Throwables) IOException(java.io.IOException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) CassandraKeyValueServiceRuntimeConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceRuntimeConfig) IOException(java.io.IOException) CyclicBarrier(java.util.concurrent.CyclicBarrier) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) CassandraKeyValueService(com.palantir.atlasdb.keyvalue.cassandra.CassandraKeyValueService) File(java.io.File) CassandraKeyValueServiceConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceConfig) Test(org.junit.Test)

Example 2 with Refreshable

use of com.palantir.refreshable.Refreshable 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 3 with Refreshable

use of com.palantir.refreshable.Refreshable in project atlasdb by palantir.

the class TransactionPostMortemRunner method createRpcClient.

private static LockDiagnosticInfoService createRpcClient(AtlasDbConfig config, Refreshable<AtlasDbRuntimeConfig> runtimeConfigSupplier) {
    Refreshable<ServerListConfig> serverListConfigSupplier = getServerListConfigSupplierForTimeLock(config, runtimeConfigSupplier);
    timelockNamespace(config);
    ServiceCreator serviceCreator = ServiceCreator.withPayloadLimiter(new MetricsManager(new MetricRegistry(), new DefaultTaggedMetricRegistry(), _unused -> true), serverListConfigSupplier, UserAgent.of(UserAgent.Agent.of("agent", "0.0.0")), () -> runtimeConfigSupplier.get().remotingClient());
    return serviceCreator.createService(LockDiagnosticInfoService.class);
}
Also used : ServerListConfigs(com.palantir.atlasdb.config.ServerListConfigs) SafeLoggerFactory(com.palantir.logsafe.logger.SafeLoggerFactory) ImmutableTimeLockClientConfig(com.palantir.atlasdb.config.ImmutableTimeLockClientConfig) ConjureLockDescriptor(com.palantir.atlasdb.timelock.api.ConjureLockDescriptor) LockDigest(com.palantir.atlasdb.debug.FullDiagnosticDigest.LockDigest) SafeLogger(com.palantir.logsafe.logger.SafeLogger) SafeArg(com.palantir.logsafe.SafeArg) ClientLockDiagnosticDigest(com.palantir.atlasdb.debug.ClientLockDiagnosticCollector.ClientLockDiagnosticDigest) MetricsManager(com.palantir.atlasdb.util.MetricsManager) UserAgent(com.palantir.conjure.java.api.config.service.UserAgent) Map(java.util.Map) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) OptionalResolver(com.palantir.util.OptionalResolver) Persistable(com.palantir.common.persist.Persistable) Refreshable(com.palantir.refreshable.Refreshable) MetricRegistry(com.codahale.metrics.MetricRegistry) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) KeyedStream(com.palantir.common.streams.KeyedStream) Collection(java.util.Collection) Set(java.util.Set) TransactionManager(com.palantir.atlasdb.transaction.api.TransactionManager) DefaultTaggedMetricRegistry(com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry) UUID(java.util.UUID) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ServerListConfig(com.palantir.atlasdb.config.ServerListConfig) AtlasDbRuntimeConfig(com.palantir.atlasdb.config.AtlasDbRuntimeConfig) List(java.util.List) ServiceCreator(com.palantir.atlasdb.factory.ServiceCreator) Optional(java.util.Optional) TimeLockClientConfig(com.palantir.atlasdb.config.TimeLockClientConfig) AtlasDbConfig(com.palantir.atlasdb.config.AtlasDbConfig) ServerListConfig(com.palantir.atlasdb.config.ServerListConfig) ServiceCreator(com.palantir.atlasdb.factory.ServiceCreator) MetricsManager(com.palantir.atlasdb.util.MetricsManager) MetricRegistry(com.codahale.metrics.MetricRegistry) DefaultTaggedMetricRegistry(com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry) DefaultTaggedMetricRegistry(com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry)

Example 4 with Refreshable

use of com.palantir.refreshable.Refreshable in project atlasdb by palantir.

the class DefaultLockAndTimestampServiceFactory method getLockAndTimestampServices.

private static LockAndTimestampServices getLockAndTimestampServices(MetricsManager metricsManager, Refreshable<ServerListConfig> timelockServerListConfig, UserAgent userAgent, String timelockNamespace, Optional<LockDiagnosticComponents> lockDiagnosticComponents, ReloadingFactory reloadingFactory, Optional<TimeLockFeedbackBackgroundTask> timeLockFeedbackBackgroundTask, Optional<TimeLockRequestBatcherProviders> timelockRequestBatcherProviders, Set<Schema> schemas, LockWatchCachingConfig cachingConfig) {
    AtlasDbDialogueServiceProvider serviceProvider = AtlasDbDialogueServiceProvider.create(timelockServerListConfig, reloadingFactory, userAgent, metricsManager.getTaggedRegistry());
    LockRpcClient lockRpcClient = serviceProvider.getLockRpcClient();
    LockService lockService = AtlasDbMetrics.instrumentTimed(metricsManager.getRegistry(), LockService.class, RemoteLockServiceAdapter.create(lockRpcClient, timelockNamespace));
    ConjureTimelockService conjureTimelockService = serviceProvider.getConjureTimelockService();
    TimelockRpcClient timelockClient = serviceProvider.getTimelockRpcClient();
    // TODO(fdesouza): Remove this once PDS-95791 is resolved.
    ConjureTimelockService withDiagnosticsConjureTimelockService = lockDiagnosticComponents.<ConjureTimelockService>map(components -> new LockDiagnosticConjureTimelockService(conjureTimelockService, components.clientLockDiagnosticCollector(), components.localLockTracker())).orElse(conjureTimelockService);
    NamespacedTimelockRpcClient namespacedTimelockRpcClient = new DefaultNamespacedTimelockRpcClient(timelockClient, timelockNamespace);
    LeaderElectionReportingTimelockService leaderElectionReportingTimelockService = LeaderElectionReportingTimelockService.create(withDiagnosticsConjureTimelockService, timelockNamespace);
    timeLockFeedbackBackgroundTask.ifPresent(task -> task.registerLeaderElectionStatistics(leaderElectionReportingTimelockService));
    NamespacedConjureTimelockService namespacedConjureTimelockService = TimestampCorroboratingTimelockService.create(timelockNamespace, metricsManager.getTaggedRegistry(), leaderElectionReportingTimelockService);
    NamespacedConjureLockWatchingService lockWatchingService = new NamespacedConjureLockWatchingService(serviceProvider.getConjureLockWatchingService(), timelockNamespace);
    Supplier<InternalMultiClientConjureTimelockService> multiClientTimelockServiceSupplier = getMultiClientTimelockServiceSupplier(serviceProvider);
    Supplier<Optional<RequestBatchersFactory.MultiClientRequestBatchers>> requestBatcherProvider = () -> timelockRequestBatcherProviders.map(batcherProviders -> ImmutableMultiClientRequestBatchers.of(batcherProviders.commitTimestamps().getBatcher(multiClientTimelockServiceSupplier), batcherProviders.startTransactions().getBatcher(multiClientTimelockServiceSupplier)));
    TimeLockHelperServices timeLockHelperServices = TimeLockHelperServices.create(timelockNamespace, metricsManager, schemas, lockWatchingService, cachingConfig, requestBatcherProvider);
    LockWatchManagerInternal lockWatchManager = timeLockHelperServices.lockWatchManager();
    RemoteTimelockServiceAdapter remoteTimelockServiceAdapter = RemoteTimelockServiceAdapter.create(namespacedTimelockRpcClient, namespacedConjureTimelockService, getLeaderTimeGetter(timelockNamespace, timelockRequestBatcherProviders, namespacedConjureTimelockService, multiClientTimelockServiceSupplier), timeLockHelperServices.requestBatchersFactory());
    TimestampManagementService timestampManagementService = new RemoteTimestampManagementAdapter(serviceProvider.getTimestampManagementRpcClient(), timelockNamespace);
    return ImmutableLockAndTimestampServices.builder().lock(lockService).timestamp(new TimelockTimestampServiceAdapter(remoteTimelockServiceAdapter)).timestampManagement(timestampManagementService).timelock(remoteTimelockServiceAdapter).lockWatcher(lockWatchManager).addResources(remoteTimelockServiceAdapter::close).addResources(lockWatchManager::close).build();
}
Also used : ServerListConfigs(com.palantir.atlasdb.config.ServerListConfigs) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) AuthenticatedInternalMultiClientConjureTimelockService(com.palantir.lock.client.AuthenticatedInternalMultiClientConjureTimelockService) LeaderConfig(com.palantir.atlasdb.config.LeaderConfig) LockRefreshingLockService(com.palantir.lock.client.LockRefreshingLockService) ClientErrorException(javax.ws.rs.ClientErrorException) NamespacedConjureTimelockService(com.palantir.lock.client.NamespacedConjureTimelockService) TimelockTimestampServiceAdapter(com.palantir.atlasdb.transaction.impl.TimelockTimestampServiceAdapter) MetricsManager(com.palantir.atlasdb.util.MetricsManager) NamespacedTimelockRpcClient(com.palantir.lock.v2.NamespacedTimelockRpcClient) TimeLockRequestBatcherProviders(com.palantir.atlasdb.config.TimeLockRequestBatcherProviders) UserAgent(com.palantir.conjure.java.api.config.service.UserAgent) Duration(java.time.Duration) TimestampService(com.palantir.timestamp.TimestampService) TimelockRpcClient(com.palantir.lock.v2.TimelockRpcClient) Refreshable(com.palantir.refreshable.Refreshable) TimestampManagementService(com.palantir.timestamp.TimestampManagementService) LockDiagnosticComponents(com.palantir.atlasdb.debug.LockDiagnosticComponents) ReloadingFactory(com.palantir.dialogue.clients.DialogueClients.ReloadingFactory) AtlasDbHttpClients(com.palantir.atlasdb.http.AtlasDbHttpClients) TimeLockFeedbackBackgroundTask(com.palantir.lock.client.metrics.TimeLockFeedbackBackgroundTask) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException) Set(java.util.Set) ServerListConfig(com.palantir.atlasdb.config.ServerListConfig) ReferenceTrackingWrapper(com.palantir.lock.client.ReferenceTrackingWrapper) LockRpcClient(com.palantir.lock.LockRpcClient) LeaderTimeCoalescingBatcher(com.palantir.lock.client.LeaderTimeCoalescingBatcher) LockWatchCachingConfig(com.palantir.atlasdb.keyvalue.api.LockWatchCachingConfig) NamespacedConjureLockWatchingService(com.palantir.lock.client.NamespacedConjureLockWatchingService) ImmutableMultiClientRequestBatchers(com.palantir.lock.client.ImmutableMultiClientRequestBatchers) TimestampRange(com.palantir.timestamp.TimestampRange) InternalMultiClientConjureTimelockService(com.palantir.lock.client.InternalMultiClientConjureTimelockService) Optional(java.util.Optional) TimeLockClientConfig(com.palantir.atlasdb.config.TimeLockClientConfig) InstrumentedTimelockService(com.palantir.atlasdb.transaction.impl.InstrumentedTimelockService) LockDiagnosticConjureTimelockService(com.palantir.atlasdb.debug.LockDiagnosticConjureTimelockService) RemotingClientConfigs(com.palantir.atlasdb.config.RemotingClientConfigs) ImmutableServerListConfig(com.palantir.atlasdb.config.ImmutableServerListConfig) LeadershipCoordinator(com.palantir.leader.proxy.LeadershipCoordinator) Iterables(com.google.common.collect.Iterables) SafeLoggerFactory(com.palantir.logsafe.logger.SafeLoggerFactory) ProfilingTimelockService(com.palantir.lock.client.ProfilingTimelockService) AtlasDbMetrics(com.palantir.atlasdb.util.AtlasDbMetrics) ConjureTimelockService(com.palantir.atlasdb.timelock.api.ConjureTimelockService) RequestBatchersFactory(com.palantir.lock.client.RequestBatchersFactory) RemoteTimestampManagementAdapter(com.palantir.timestamp.RemoteTimestampManagementAdapter) TimestampStoreInvalidator(com.palantir.timestamp.TimestampStoreInvalidator) CompletableFuture(java.util.concurrent.CompletableFuture) Supplier(java.util.function.Supplier) LeaderTimeGetter(com.palantir.lock.client.LeaderTimeGetter) SafeLogger(com.palantir.logsafe.logger.SafeLogger) RemoteTimelockServiceAdapter(com.palantir.lock.client.RemoteTimelockServiceAdapter) LegacyTimelockService(com.palantir.lock.impl.LegacyTimelockService) AuxiliaryRemotingParameters(com.palantir.atlasdb.config.AuxiliaryRemotingParameters) Suppliers(com.google.common.base.Suppliers) RemoteLockServiceAdapter(com.palantir.lock.client.RemoteLockServiceAdapter) OptionalResolver(com.palantir.util.OptionalResolver) TimestampCorroboratingTimelockService(com.palantir.lock.client.TimestampCorroboratingTimelockService) AwaitingLeadershipProxy(com.palantir.leader.proxy.AwaitingLeadershipProxy) NamespaceAgnosticLockRpcClient(com.palantir.lock.NamespaceAgnosticLockRpcClient) UnknownRemoteException(com.palantir.conjure.java.api.errors.UnknownRemoteException) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) LockWatchManagerInternal(com.palantir.atlasdb.keyvalue.api.watch.LockWatchManagerInternal) TimelockService(com.palantir.lock.v2.TimelockService) Consumer(java.util.function.Consumer) AtlasDbRuntimeConfig(com.palantir.atlasdb.config.AtlasDbRuntimeConfig) TimeLockMigrator(com.palantir.atlasdb.factory.startup.TimeLockMigrator) LockService(com.palantir.lock.LockService) NamespacedCoalescingLeaderTimeGetter(com.palantir.lock.client.NamespacedCoalescingLeaderTimeGetter) TimeLockClient(com.palantir.lock.client.TimeLockClient) ManagedTimestampService(com.palantir.timestamp.ManagedTimestampService) DefaultNamespacedTimelockRpcClient(com.palantir.lock.v2.DefaultNamespacedTimelockRpcClient) LocalPaxosServices(com.palantir.atlasdb.factory.Leaders.LocalPaxosServices) LegacyLeaderTimeGetter(com.palantir.lock.client.LegacyLeaderTimeGetter) Schema(com.palantir.atlasdb.table.description.Schema) PingableLeader(com.palantir.leader.PingableLeader) LeaderElectionReportingTimelockService(com.palantir.lock.client.LeaderElectionReportingTimelockService) AtlasDbConfig(com.palantir.atlasdb.config.AtlasDbConfig) TimelockTimestampServiceAdapter(com.palantir.atlasdb.transaction.impl.TimelockTimestampServiceAdapter) AuthenticatedInternalMultiClientConjureTimelockService(com.palantir.lock.client.AuthenticatedInternalMultiClientConjureTimelockService) InternalMultiClientConjureTimelockService(com.palantir.lock.client.InternalMultiClientConjureTimelockService) RemoteTimestampManagementAdapter(com.palantir.timestamp.RemoteTimestampManagementAdapter) LockRefreshingLockService(com.palantir.lock.client.LockRefreshingLockService) LockService(com.palantir.lock.LockService) Optional(java.util.Optional) LockRpcClient(com.palantir.lock.LockRpcClient) NamespaceAgnosticLockRpcClient(com.palantir.lock.NamespaceAgnosticLockRpcClient) NamespacedTimelockRpcClient(com.palantir.lock.v2.NamespacedTimelockRpcClient) TimelockRpcClient(com.palantir.lock.v2.TimelockRpcClient) DefaultNamespacedTimelockRpcClient(com.palantir.lock.v2.DefaultNamespacedTimelockRpcClient) LockWatchManagerInternal(com.palantir.atlasdb.keyvalue.api.watch.LockWatchManagerInternal) RemoteTimelockServiceAdapter(com.palantir.lock.client.RemoteTimelockServiceAdapter) RequestBatchersFactory(com.palantir.lock.client.RequestBatchersFactory) NamespacedConjureLockWatchingService(com.palantir.lock.client.NamespacedConjureLockWatchingService) NamespacedTimelockRpcClient(com.palantir.lock.v2.NamespacedTimelockRpcClient) DefaultNamespacedTimelockRpcClient(com.palantir.lock.v2.DefaultNamespacedTimelockRpcClient) LockDiagnosticConjureTimelockService(com.palantir.atlasdb.debug.LockDiagnosticConjureTimelockService) NamespacedConjureTimelockService(com.palantir.lock.client.NamespacedConjureTimelockService) TimestampManagementService(com.palantir.timestamp.TimestampManagementService) AuthenticatedInternalMultiClientConjureTimelockService(com.palantir.lock.client.AuthenticatedInternalMultiClientConjureTimelockService) NamespacedConjureTimelockService(com.palantir.lock.client.NamespacedConjureTimelockService) InternalMultiClientConjureTimelockService(com.palantir.lock.client.InternalMultiClientConjureTimelockService) LockDiagnosticConjureTimelockService(com.palantir.atlasdb.debug.LockDiagnosticConjureTimelockService) ConjureTimelockService(com.palantir.atlasdb.timelock.api.ConjureTimelockService) DefaultNamespacedTimelockRpcClient(com.palantir.lock.v2.DefaultNamespacedTimelockRpcClient) LeaderElectionReportingTimelockService(com.palantir.lock.client.LeaderElectionReportingTimelockService)

Example 5 with Refreshable

use of com.palantir.refreshable.Refreshable in project atlasdb by palantir.

the class CassandraKvsAsyncFallbackMechanismsTests method getConfigWithAsyncFactoryUsingClosedSession.

private CassandraKeyValueServiceConfig getConfigWithAsyncFactoryUsingClosedSession(boolean useSpyPreparedStatement) {
    CassandraKeyValueServiceConfig config = CASSANDRA_RESOURCE.getConfig();
    Refreshable<CassandraKeyValueServiceRuntimeConfig> runtimeConfig = CASSANDRA_RESOURCE.getRuntimeConfig();
    Cluster cluster = spy(new ClusterFactory(CASSANDRA_RESOURCE.getClusterBuilderWithProxy()).constructCluster(CassandraClusterConfig.of(config, runtimeConfig.get()), runtimeConfig.get().servers()));
    Session session = spy(cluster.connect());
    doReturn(session).when(cluster).connect();
    if (useSpyPreparedStatement) {
        // Need a real query that uses namespace and table that already exist, irrespective of what the test may
        // create
        PreparedStatement preparedStatement = spy(session.prepare("SELECT COUNT(*) FROM system.schema_columns;"));
        BoundStatement boundStatement = spy(preparedStatement.bind());
        // The prepared statement doesn't use any of the bindings that a normal query would use, so we ignore them.
        doReturn(boundStatement).when(boundStatement).setBytes(any(), any());
        doReturn(boundStatement).when(boundStatement).setLong(anyString(), anyLong());
        doReturn(boundStatement).when(preparedStatement).bind();
        doReturn(preparedStatement).when(session).prepare(anyString());
    }
    session.close();
    CqlClient cqlClient = spy(CqlClientImpl.create(new DefaultTaggedMetricRegistry(), cluster, mock(CqlCapableConfigTuning.class), false));
    doReturn(true).when(cqlClient).isValid();
    CassandraAsyncKeyValueServiceFactory cassandraAsyncKeyValueServiceFactory = new DefaultCassandraAsyncKeyValueServiceFactory((_ignored1, _ignored2, _ignored3, _ignored4) -> ReloadingCloseableContainerImpl.of(Refreshable.only(0), _ignored -> cqlClient));
    return ImmutableCassandraKeyValueServiceConfig.builder().from(CASSANDRA_RESOURCE.getConfig()).asyncKeyValueServiceFactory(cassandraAsyncKeyValueServiceFactory).build();
}
Also used : ClusterFactory(com.palantir.atlasdb.keyvalue.cassandra.async.client.creation.ClusterFactory) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) AsyncKeyValueService(com.palantir.atlasdb.keyvalue.api.AsyncKeyValueService) CassandraKeyValueServiceConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceConfig) CqlCapableConfigTuning(com.palantir.atlasdb.cassandra.CassandraServersConfigs.CqlCapableConfigTuning) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) CassandraKeyValueServiceRuntimeConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceRuntimeConfig) ClusterFactory(com.palantir.atlasdb.keyvalue.cassandra.async.client.creation.ClusterFactory) CqlClient(com.palantir.atlasdb.keyvalue.cassandra.async.CqlClient) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Mockito.spy(org.mockito.Mockito.spy) ReloadingCloseableContainerImpl(com.palantir.atlasdb.cassandra.ReloadingCloseableContainerImpl) PtBytes(com.palantir.atlasdb.encoding.PtBytes) ImmutableCassandraKeyValueServiceConfig(com.palantir.atlasdb.cassandra.ImmutableCassandraKeyValueServiceConfig) PreparedStatement(com.datastax.driver.core.PreparedStatement) BoundStatement(com.datastax.driver.core.BoundStatement) CassandraAsyncKeyValueServiceFactory(com.palantir.atlasdb.keyvalue.cassandra.async.CassandraAsyncKeyValueServiceFactory) Session(com.datastax.driver.core.Session) Map(java.util.Map) After(org.junit.After) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) ClassRule(org.junit.ClassRule) Mockito.doReturn(org.mockito.Mockito.doReturn) AtlasDbConstants(com.palantir.atlasdb.AtlasDbConstants) Refreshable(com.palantir.refreshable.Refreshable) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Cell(com.palantir.atlasdb.keyvalue.api.Cell) CassandraClusterConfig(com.palantir.atlasdb.keyvalue.cassandra.async.client.creation.ClusterFactory.CassandraClusterConfig) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) DefaultCassandraAsyncKeyValueServiceFactory(com.palantir.atlasdb.keyvalue.cassandra.async.DefaultCassandraAsyncKeyValueServiceFactory) DefaultTaggedMetricRegistry(com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) Mockito.never(org.mockito.Mockito.never) Futures(com.google.common.util.concurrent.Futures) CassandraResource(com.palantir.atlasdb.containers.CassandraResource) Cluster(com.datastax.driver.core.Cluster) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) CqlClientImpl(com.palantir.atlasdb.keyvalue.cassandra.async.CqlClientImpl) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) CassandraKeyValueServiceRuntimeConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceRuntimeConfig) Cluster(com.datastax.driver.core.Cluster) DefaultCassandraAsyncKeyValueServiceFactory(com.palantir.atlasdb.keyvalue.cassandra.async.DefaultCassandraAsyncKeyValueServiceFactory) PreparedStatement(com.datastax.driver.core.PreparedStatement) CqlClient(com.palantir.atlasdb.keyvalue.cassandra.async.CqlClient) DefaultTaggedMetricRegistry(com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry) BoundStatement(com.datastax.driver.core.BoundStatement) CassandraKeyValueServiceConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceConfig) ImmutableCassandraKeyValueServiceConfig(com.palantir.atlasdb.cassandra.ImmutableCassandraKeyValueServiceConfig) CassandraAsyncKeyValueServiceFactory(com.palantir.atlasdb.keyvalue.cassandra.async.CassandraAsyncKeyValueServiceFactory) DefaultCassandraAsyncKeyValueServiceFactory(com.palantir.atlasdb.keyvalue.cassandra.async.DefaultCassandraAsyncKeyValueServiceFactory) Session(com.datastax.driver.core.Session)

Aggregations

Refreshable (com.palantir.refreshable.Refreshable)7 CassandraKeyValueServiceConfig (com.palantir.atlasdb.cassandra.CassandraKeyValueServiceConfig)4 CassandraKeyValueServiceRuntimeConfig (com.palantir.atlasdb.cassandra.CassandraKeyValueServiceRuntimeConfig)4 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)4 UserAgent (com.palantir.conjure.java.api.config.service.UserAgent)4 List (java.util.List)4 Optional (java.util.Optional)4 Suppliers (com.google.common.base.Suppliers)3 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 AtlasDbConfig (com.palantir.atlasdb.config.AtlasDbConfig)3 AtlasDbRuntimeConfig (com.palantir.atlasdb.config.AtlasDbRuntimeConfig)3 ServerListConfig (com.palantir.atlasdb.config.ServerListConfig)3 ServerListConfigs (com.palantir.atlasdb.config.ServerListConfigs)3 CassandraClusterConfig (com.palantir.atlasdb.keyvalue.cassandra.async.client.creation.ClusterFactory.CassandraClusterConfig)3 SafeIllegalStateException (com.palantir.logsafe.exceptions.SafeIllegalStateException)3 SafeLogger (com.palantir.logsafe.logger.SafeLogger)3 SafeLoggerFactory (com.palantir.logsafe.logger.SafeLoggerFactory)3 Map (java.util.Map)3