Search in sources :

Example 1 with TransactionConfig

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();
}
Also used : AtlasCellLockDescriptor(com.palantir.lock.AtlasCellLockDescriptor) AtlasRowLockDescriptor(com.palantir.lock.AtlasRowLockDescriptor) LockDescriptor(com.palantir.lock.LockDescriptor) SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) LockResponse(com.palantir.lock.v2.LockResponse) TransactionLockAcquisitionTimeoutException(com.palantir.atlasdb.transaction.api.TransactionLockAcquisitionTimeoutException) TransactionConfig(com.palantir.atlasdb.transaction.TransactionConfig) LockRequest(com.palantir.lock.v2.LockRequest) ImmutableLockRequest(com.palantir.lock.v2.ImmutableLockRequest)

Example 2 with TransactionConfig

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.");
    }
}
Also used : WaitForLocksRequest(com.palantir.lock.v2.WaitForLocksRequest) WaitForLocksResponse(com.palantir.lock.v2.WaitForLocksResponse) TransactionLockAcquisitionTimeoutException(com.palantir.atlasdb.transaction.api.TransactionLockAcquisitionTimeoutException) TransactionConfig(com.palantir.atlasdb.transaction.TransactionConfig)

Example 3 with TransactionConfig

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();
}
Also used : TransactionConfig(com.palantir.atlasdb.transaction.TransactionConfig) ImmutableTransactionConfig(com.palantir.atlasdb.transaction.ImmutableTransactionConfig) Test(org.junit.Test)

Example 4 with TransactionConfig

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;
}
Also used : KeyValueServiceConfig(com.palantir.atlasdb.spi.KeyValueServiceConfig) SafeTableClearerKeyValueService(com.palantir.atlasdb.sweep.queue.clear.SafeTableClearerKeyValueService) SweepStatsKeyValueService(com.palantir.atlasdb.keyvalue.impl.SweepStatsKeyValueService) ValidatingQueryRewritingKeyValueService(com.palantir.atlasdb.keyvalue.impl.ValidatingQueryRewritingKeyValueService) ProfilingKeyValueService(com.palantir.atlasdb.keyvalue.impl.ProfilingKeyValueService) TracingKeyValueService(com.palantir.atlasdb.keyvalue.impl.TracingKeyValueService) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) TimelockTimestampServiceAdapter(com.palantir.atlasdb.transaction.impl.TimelockTimestampServiceAdapter) SweepConfig(com.palantir.atlasdb.config.SweepConfig) ConflictTracer(com.palantir.atlasdb.debug.ConflictTracer) DefaultCleanerBuilder(com.palantir.atlasdb.cleaner.DefaultCleanerBuilder) TimestampCache(com.palantir.atlasdb.cache.TimestampCache) DefaultTimestampCache(com.palantir.atlasdb.cache.DefaultTimestampCache) SharedResourcesConfig(com.palantir.atlasdb.spi.SharedResourcesConfig) CleanupFollower(com.palantir.atlasdb.cleaner.CleanupFollower) Cleaner(com.palantir.atlasdb.cleaner.api.Cleaner) SweepStrategyManager(com.palantir.atlasdb.transaction.impl.SweepStrategyManager) TransactionService(com.palantir.atlasdb.transaction.service.TransactionService) TimeLockFeedbackBackgroundTask(com.palantir.lock.client.metrics.TimeLockFeedbackBackgroundTask) NamedThreadFactory(com.palantir.common.concurrent.NamedThreadFactory) MultiTableSweepQueueWriter(com.palantir.atlasdb.sweep.queue.MultiTableSweepQueueWriter) LockDiagnosticComponents(com.palantir.atlasdb.debug.LockDiagnosticComponents) FreshTimestampSupplierAdapter(com.palantir.atlasdb.factory.timestamp.FreshTimestampSupplierAdapter) TransactionConfig(com.palantir.atlasdb.transaction.TransactionConfig) ImmutableTransactionConfig(com.palantir.atlasdb.transaction.ImmutableTransactionConfig) DerivedSnapshotConfig(com.palantir.atlasdb.spi.DerivedSnapshotConfig) MetricsManager(com.palantir.atlasdb.util.MetricsManager) SerializableTransactionManager(com.palantir.atlasdb.transaction.impl.SerializableTransactionManager) TransactionManager(com.palantir.atlasdb.transaction.api.TransactionManager) SafeTableClearerKeyValueService(com.palantir.atlasdb.sweep.queue.clear.SafeTableClearerKeyValueService) DefaultTimestampCache(com.palantir.atlasdb.cache.DefaultTimestampCache) ConflictDetectionManager(com.palantir.atlasdb.transaction.impl.ConflictDetectionManager) AtlasDbRuntimeConfig(com.palantir.atlasdb.config.AtlasDbRuntimeConfig)

Example 5 with TransactionConfig

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();
}
Also used : TransactionConfig(com.palantir.atlasdb.transaction.TransactionConfig) ImmutableTransactionConfig(com.palantir.atlasdb.transaction.ImmutableTransactionConfig) Test(org.junit.Test)

Aggregations

TransactionConfig (com.palantir.atlasdb.transaction.TransactionConfig)5 ImmutableTransactionConfig (com.palantir.atlasdb.transaction.ImmutableTransactionConfig)3 TransactionLockAcquisitionTimeoutException (com.palantir.atlasdb.transaction.api.TransactionLockAcquisitionTimeoutException)2 Test (org.junit.Test)2 DefaultTimestampCache (com.palantir.atlasdb.cache.DefaultTimestampCache)1 TimestampCache (com.palantir.atlasdb.cache.TimestampCache)1 CleanupFollower (com.palantir.atlasdb.cleaner.CleanupFollower)1 DefaultCleanerBuilder (com.palantir.atlasdb.cleaner.DefaultCleanerBuilder)1 Cleaner (com.palantir.atlasdb.cleaner.api.Cleaner)1 AtlasDbRuntimeConfig (com.palantir.atlasdb.config.AtlasDbRuntimeConfig)1 SweepConfig (com.palantir.atlasdb.config.SweepConfig)1 ConflictTracer (com.palantir.atlasdb.debug.ConflictTracer)1 LockDiagnosticComponents (com.palantir.atlasdb.debug.LockDiagnosticComponents)1 FreshTimestampSupplierAdapter (com.palantir.atlasdb.factory.timestamp.FreshTimestampSupplierAdapter)1 KeyValueService (com.palantir.atlasdb.keyvalue.api.KeyValueService)1 ProfilingKeyValueService (com.palantir.atlasdb.keyvalue.impl.ProfilingKeyValueService)1 SweepStatsKeyValueService (com.palantir.atlasdb.keyvalue.impl.SweepStatsKeyValueService)1 TracingKeyValueService (com.palantir.atlasdb.keyvalue.impl.TracingKeyValueService)1 ValidatingQueryRewritingKeyValueService (com.palantir.atlasdb.keyvalue.impl.ValidatingQueryRewritingKeyValueService)1 DerivedSnapshotConfig (com.palantir.atlasdb.spi.DerivedSnapshotConfig)1