use of com.palantir.atlasdb.cache.DefaultTimestampCache in project atlasdb by palantir.
the class ComparingTimestampCache method comparingOffHeapForTests.
public static TimestampCache comparingOffHeapForTests(MetricsManager metricRegistry, PersistentStore persistentStore) {
TimestampCache first = new DefaultTimestampCache(metricRegistry.getRegistry(), () -> AtlasDbConstants.DEFAULT_TIMESTAMP_CACHE_SIZE);
TimestampCache second = OffHeapTimestampCache.create(persistentStore, metricRegistry.getTaggedRegistry(), () -> AtlasDbConstants.DEFAULT_TIMESTAMP_CACHE_SIZE);
return new ComparingTimestampCache(first, second);
}
use of com.palantir.atlasdb.cache.DefaultTimestampCache in project atlasdb by palantir.
the class TransactionManagers method serializableInternal.
@SuppressWarnings("MethodLength")
private TransactionManager serializableInternal(@Output List<AutoCloseable> closeables) {
MetricsManager metricsManager = setUpMetricsAndGetMetricsManager();
AtlasDbRuntimeConfigRefreshable runtimeConfigRefreshable = initializeCloseable(() -> AtlasDbRuntimeConfigRefreshable.create(this), closeables);
Refreshable<AtlasDbRuntimeConfig> runtime = runtimeConfigRefreshable.config();
Optional<TimeLockFeedbackBackgroundTask> timeLockFeedbackBackgroundTask = getTimeLockFeedbackBackgroundTask(metricsManager, closeables, config(), runtime);
FreshTimestampSupplierAdapter adapter = new FreshTimestampSupplierAdapter();
KeyValueServiceConfig installConfig = config().keyValueService();
ServiceDiscoveringAtlasSupplier atlasFactory = new ServiceDiscoveringAtlasSupplier(metricsManager, installConfig, runtime.map(AtlasDbRuntimeConfig::keyValueService), config().leader(), config().namespace(), Optional.empty(), config().initializeAsync(), adapter);
DerivedSnapshotConfig derivedSnapshotConfig = atlasFactory.getDerivedSnapshotConfig();
LockRequest.setDefaultLockTimeout(SimpleTimeDuration.of(config().getDefaultLockTimeoutSeconds(), TimeUnit.SECONDS));
LockAndTimestampServiceFactory factory = lockAndTimestampServiceFactory().orElseGet(() -> new DefaultLockAndTimestampServiceFactory(metricsManager, config(), runtime, registrar(), () -> LockServiceImpl.create(lockServerOptions()), atlasFactory::getManagedTimestampService, atlasFactory.getTimestampStoreInvalidator(), userAgent(), lockDiagnosticComponents(), reloadingFactory(), timeLockFeedbackBackgroundTask, timelockRequestBatcherProviders(), schemas()));
LockAndTimestampServices lockAndTimestampServices = factory.createLockAndTimestampServices();
adapter.setTimestampService(lockAndTimestampServices.managedTimestampService());
KvsProfilingLogger.setSlowLogThresholdMillis(config().getKvsSlowLogThresholdMillis());
Refreshable<SweepConfig> sweepConfig = runtime.map(AtlasDbRuntimeConfig::sweep);
KeyValueService keyValueService = initializeCloseable(() -> {
KeyValueService kvs = atlasFactory.getKeyValueService();
kvs = ProfilingKeyValueService.create(kvs);
kvs = new SafeTableClearerKeyValueService(lockAndTimestampServices.timelock()::getImmutableTimestamp, kvs);
// table.
if (!targetedSweepIsFullyEnabled(config(), runtime)) {
kvs = SweepStatsKeyValueService.create(kvs, new TimelockTimestampServiceAdapter(lockAndTimestampServices.timelock()), sweepConfig.map(SweepConfig::writeThreshold), sweepConfig.map(SweepConfig::writeSizeThreshold), () -> true);
}
kvs = TracingKeyValueService.create(kvs);
kvs = AtlasDbMetrics.instrumentTimed(metricsManager.getRegistry(), KeyValueService.class, kvs, MetricRegistry.name(KeyValueService.class));
return ValidatingQueryRewritingKeyValueService.create(kvs);
}, closeables);
if (config().targetedSweep().enableSweepQueueWrites()) {
initializeCloseable(() -> OldestTargetedSweepTrackedTimestamp.createStarted(keyValueService, lockAndTimestampServices.timestamp(), PTExecutors.newSingleThreadScheduledExecutor(new NamedThreadFactory("OldestTargetedSweepTrackedTimestamp", true))), closeables);
}
TransactionManagersInitializer initializer = TransactionManagersInitializer.createInitialTables(keyValueService, schemas(), config().initializeAsync(), allSafeForLogging());
TransactionComponents components = createTransactionComponents(closeables, metricsManager, lockAndTimestampServices, keyValueService, runtime);
TransactionService transactionService = components.transactionService();
ConflictDetectionManager conflictManager = ConflictDetectionManagers.create(keyValueService);
SweepStrategyManager sweepStrategyManager = SweepStrategyManagers.createDefault(keyValueService);
CleanupFollower follower = CleanupFollower.create(schemas());
Cleaner cleaner = initializeCloseable(() -> new DefaultCleanerBuilder(keyValueService, lockAndTimestampServices.timelock(), ImmutableList.of(follower), transactionService, metricsManager).setBackgroundScrubAggressively(config().backgroundScrubAggressively()).setBackgroundScrubBatchSize(config().getBackgroundScrubBatchSize()).setBackgroundScrubFrequencyMillis(config().getBackgroundScrubFrequencyMillis()).setBackgroundScrubThreads(config().getBackgroundScrubThreads()).setPunchIntervalMillis(config().getPunchIntervalMillis()).setTransactionReadTimeout(config().getTransactionReadTimeoutMillis()).setInitializeAsync(config().initializeAsync()).buildCleaner(), closeables);
MultiTableSweepQueueWriter targetedSweep = initializeCloseable(() -> uninitializedTargetedSweeper(metricsManager, config().targetedSweep(), follower, runtime.map(AtlasDbRuntimeConfig::targetedSweep)), closeables);
Supplier<TransactionConfig> transactionConfigSupplier = runtime.map(AtlasDbRuntimeConfig::transaction).map(this::withConsolidatedGrabImmutableTsLockFlag);
TimestampCache timestampCache = config().timestampCache().orElseGet(() -> new DefaultTimestampCache(metricsManager.getRegistry(), () -> runtime.get().getTimestampCacheSize()));
ConflictTracer conflictTracer = lockDiagnosticComponents().map(LockDiagnosticComponents::clientLockDiagnosticCollector).<ConflictTracer>map(Function.identity()).orElse(ConflictTracer.NO_OP);
Callback<TransactionManager> callbacks = new Callback.CallChain<>(timelockConsistencyCheckCallback(config(), runtime.get(), lockAndTimestampServices), targetedSweep.singleAttemptCallback(), asyncInitializationCallback(), createClearsTable());
TransactionManager transactionManager = initializeCloseable(() -> SerializableTransactionManager.createInstrumented(metricsManager, keyValueService, lockAndTimestampServices.timelock(), lockAndTimestampServices.lockWatcher(), lockAndTimestampServices.managedTimestampService(), lockAndTimestampServices.lock(), transactionService, () -> AtlasDbConstraintCheckingMode.FULL_CONSTRAINT_CHECKING_THROWS_EXCEPTIONS, conflictManager, sweepStrategyManager, cleaner, () -> areTransactionManagerInitializationPrerequisitesSatisfied(initializer, lockAndTimestampServices), allowHiddenTableAccess(), derivedSnapshotConfig.concurrentGetRangesThreadPoolSize(), derivedSnapshotConfig.defaultGetRangesConcurrency(), config().initializeAsync(), timestampCache, targetedSweep, callbacks, validateLocksOnReads(), transactionConfigSupplier, conflictTracer, metricsFilterEvaluationContext(), installConfig.sharedResourcesConfig().map(SharedResourcesConfig::sharedGetRangesPoolSize)), closeables);
transactionManager.registerClosingCallback(runtimeConfigRefreshable::close);
timeLockFeedbackBackgroundTask.ifPresent(task -> transactionManager.registerClosingCallback(task::close));
lockAndTimestampServices.resources().forEach(transactionManager::registerClosingCallback);
transactionManager.registerClosingCallback(transactionService::close);
components.schemaInstaller().ifPresent(installer -> transactionManager.registerClosingCallback(installer::close));
transactionManager.registerClosingCallback(targetedSweep::close);
initializeCloseable(() -> initializeSweepEndpointAndBackgroundProcess(metricsManager, config(), runtime, registrar(), keyValueService, transactionService, follower, transactionManager, runBackgroundSweepProcess()), closeables);
initializeCloseable(initializeCompactBackgroundProcess(metricsManager, lockAndTimestampServices, keyValueService, transactionManager, runtime.map(AtlasDbRuntimeConfig::compact)), closeables);
log.info("Successfully created, and now returning a transaction manager: this may not be fully initialised.");
return transactionManager;
}
Aggregations