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