Search in sources :

Example 1 with CloseableLockService

use of com.palantir.lock.CloseableLockService in project atlasdb by palantir.

the class LockCreator method createThreadPoolingLockService.

public CloseableLockService createThreadPoolingLockService() {
    // TODO (jkong): Live reload slow lock timeout, plus clients (issue #2342)
    // TODO (?????): Rewrite ThreadPooled to cope with live reload, and/or remove ThreadPooled (if using Async)
    TimeLockRuntimeConfiguration timeLockRuntimeConfiguration = runtime.get();
    CloseableLockService lockServiceNotUsingThreadPooling = createTimeLimitedLockService(timeLockRuntimeConfiguration.slowLockLogTriggerMillis());
    if (!deprecated.useClientRequestLimit()) {
        return lockServiceNotUsingThreadPooling;
    }
    int availableThreads = deprecated.availableThreads();
    // TODO(nziebart): Since the number of clients can grow dynamically, we can't compute a correct and useful
    // value for the local threadpool size at this point. Given that async lock service exists, and doesn't need
    // a thread pool, it's likely we won't fix this and will eventually remove the thread pooled lock service.
    // However, for the time being, it's still useful to have global limiting for services that need to use the
    // legacy lock service.
    int localThreadPoolSize = -1;
    int sharedThreadPoolSize = availableThreads;
    synchronized (this) {
        if (sharedThreadPool.availablePermits() == -1) {
            sharedThreadPool.release(sharedThreadPoolSize + 1);
        }
    }
    return new ThreadPooledLockService(lockServiceNotUsingThreadPooling, localThreadPoolSize, sharedThreadPool);
}
Also used : CloseableLockService(com.palantir.lock.CloseableLockService) ThreadPooledLockService(com.palantir.lock.impl.ThreadPooledLockService) TimeLockRuntimeConfiguration(com.palantir.timelock.config.TimeLockRuntimeConfiguration)

Example 2 with CloseableLockService

use of com.palantir.lock.CloseableLockService in project atlasdb by palantir.

the class ThreadPooledLockServiceTest method closesDelegate.

@Test
public void closesDelegate() throws IOException {
    CloseableLockService delegate = mock(CloseableLockService.class);
    ThreadPooledLockService pooledService = new ThreadPooledLockService(delegate, 1, new Semaphore(1));
    pooledService.close();
    verify(delegate).close();
}
Also used : CloseableLockService(com.palantir.lock.CloseableLockService) Semaphore(java.util.concurrent.Semaphore) ThreadPooledLockService(com.palantir.lock.impl.ThreadPooledLockService) Test(org.junit.Test)

Example 3 with CloseableLockService

use of com.palantir.lock.CloseableLockService in project atlasdb by palantir.

the class SnapshotTransactionManagerTest method canCloseTransactionManagerWithNonCloseableLockService.

@Test
public void canCloseTransactionManagerWithNonCloseableLockService() {
    SnapshotTransactionManager newTransactionManager = new SnapshotTransactionManager(keyValueService, new LegacyTimelockService(new InMemoryTimestampService(), closeableLockService, LockClient.of("lock")), // not closeable
    mock(LockService.class), null, null, null, null, cleaner, false, () -> AtlasDbConstants.DEFAULT_TRANSACTION_LOCK_ACQUIRE_TIMEOUT_MS, TimestampTrackerImpl.createNoOpTracker(), TransactionTestConstants.GET_RANGES_THREAD_POOL_SIZE, TransactionTestConstants.DEFAULT_GET_RANGES_CONCURRENCY, () -> AtlasDbConstants.DEFAULT_TIMESTAMP_CACHE_SIZE, MultiTableSweepQueueWriter.NO_OP);
    // should not throw
    newTransactionManager.close();
}
Also used : LegacyTimelockService(com.palantir.lock.impl.LegacyTimelockService) CloseableLockService(com.palantir.lock.CloseableLockService) LockService(com.palantir.lock.LockService) InMemoryTimestampService(com.palantir.timestamp.InMemoryTimestampService) Test(org.junit.Test)

Aggregations

CloseableLockService (com.palantir.lock.CloseableLockService)3 ThreadPooledLockService (com.palantir.lock.impl.ThreadPooledLockService)2 Test (org.junit.Test)2 LockService (com.palantir.lock.LockService)1 LegacyTimelockService (com.palantir.lock.impl.LegacyTimelockService)1 TimeLockRuntimeConfiguration (com.palantir.timelock.config.TimeLockRuntimeConfiguration)1 InMemoryTimestampService (com.palantir.timestamp.InMemoryTimestampService)1 Semaphore (java.util.concurrent.Semaphore)1