use of com.palantir.atlasdb.transaction.TransactionConfig in project atlasdb by palantir.
the class SnapshotTransaction method acquireLocksForCommit.
// /////////////////////////////////////////////////////////////////////////
// / Locking
// /////////////////////////////////////////////////////////////////////////
/**
* This method should acquire any locks needed to do proper concurrency control at commit time.
*/
protected LockToken acquireLocksForCommit() {
Set<LockDescriptor> lockDescriptors = getLocksForWrites();
TransactionConfig currentTransactionConfig = transactionConfig.get();
// TODO(fdesouza): Revert this once PDS-95791 is resolved.
long lockAcquireTimeoutMillis = currentTransactionConfig.getLockAcquireTimeoutMillis();
LockRequest request = ImmutableLockRequest.of(lockDescriptors, lockAcquireTimeoutMillis, Optional.ofNullable(getStartTimestampAsClientDescription(currentTransactionConfig)));
RuntimeException stackTraceSnapshot = new SafeRuntimeException("I exist to show you the stack trace");
LockResponse lockResponse = timelockService.lock(request, ClientLockingOptions.builder().maximumLockTenure(currentTransactionConfig.commitLockTenure().toJavaDuration()).tenureExpirationCallback(() -> logCommitLockTenureExceeded(lockDescriptors, currentTransactionConfig, stackTraceSnapshot)).build());
if (!lockResponse.wasSuccessful()) {
log.error("Timed out waiting while acquiring commit locks. Timeout was {} ms. " + "First ten required locks were {}.", SafeArg.of("acquireTimeoutMs", lockAcquireTimeoutMillis), SafeArg.of("numberOfDescriptors", lockDescriptors.size()), UnsafeArg.of("firstTenLockDescriptors", Iterables.limit(lockDescriptors, 10)));
throw new TransactionLockAcquisitionTimeoutException("Timed out while acquiring commit locks.");
}
return lockResponse.getToken();
}
use of com.palantir.atlasdb.transaction.TransactionConfig in project atlasdb by palantir.
the class SnapshotTransaction method waitFor.
private void waitFor(Set<LockDescriptor> lockDescriptors) {
TransactionConfig currentTransactionConfig = transactionConfig.get();
String startTimestampAsDescription = getStartTimestampAsClientDescription(currentTransactionConfig);
// TODO(fdesouza): Revert this once PDS-95791 is resolved.
long lockAcquireTimeoutMillis = currentTransactionConfig.getLockAcquireTimeoutMillis();
WaitForLocksRequest request = WaitForLocksRequest.of(lockDescriptors, lockAcquireTimeoutMillis, startTimestampAsDescription);
WaitForLocksResponse response = timelockService.waitForLocks(request);
if (!response.wasSuccessful()) {
log.error("Timed out waiting for commits to complete. Timeout was {} ms. First ten locks were {}.", SafeArg.of("requestId", request.getRequestId()), SafeArg.of("acquireTimeoutMs", lockAcquireTimeoutMillis), SafeArg.of("numberOfDescriptors", lockDescriptors.size()), UnsafeArg.of("firstTenLockDescriptors", Iterables.limit(lockDescriptors, 10)));
throw new TransactionLockAcquisitionTimeoutException("Timed out waiting for commits to complete.");
}
}
use of com.palantir.atlasdb.transaction.TransactionConfig in project atlasdb by palantir.
the class TransactionManagersTest method useRuntimeConfigFlagIfBuilderOptionIsSetToFalse.
@Test
public void useRuntimeConfigFlagIfBuilderOptionIsSetToFalse() {
TransactionConfig transactionConfigLocking = ImmutableTransactionConfig.builder().lockImmutableTsOnReadOnlyTransactions(true).build();
TransactionConfig transactionConfigNotLocking = ImmutableTransactionConfig.builder().lockImmutableTsOnReadOnlyTransactions(false).build();
assertThat(withLockImmutableTsOnReadOnlyTransaction(false).withConsolidatedGrabImmutableTsLockFlag(transactionConfigLocking).lockImmutableTsOnReadOnlyTransactions()).isTrue();
assertThat(withLockImmutableTsOnReadOnlyTransaction(false).withConsolidatedGrabImmutableTsLockFlag(transactionConfigNotLocking).lockImmutableTsOnReadOnlyTransactions()).isFalse();
}
use of com.palantir.atlasdb.transaction.TransactionConfig 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;
}
use of com.palantir.atlasdb.transaction.TransactionConfig in project atlasdb by palantir.
the class TransactionManagersTest method grabImmutableTsLockIsConfiguredWithBuilderOption.
@Test
public void grabImmutableTsLockIsConfiguredWithBuilderOption() {
TransactionConfig transactionConfig = ImmutableTransactionConfig.builder().build();
assertThat(withLockImmutableTsOnReadOnlyTransaction(true).withConsolidatedGrabImmutableTsLockFlag(transactionConfig).lockImmutableTsOnReadOnlyTransactions()).isTrue();
assertThat(withLockImmutableTsOnReadOnlyTransaction(false).withConsolidatedGrabImmutableTsLockFlag(transactionConfig).lockImmutableTsOnReadOnlyTransactions()).isFalse();
}
Aggregations