Search in sources :

Example 6 with LockStoreImpl

use of com.hazelcast.internal.locksupport.LockStoreImpl in project hazelcast by hazelcast.

the class UnlockBackupOperation method run.

@Override
public void run() throws Exception {
    LockStoreImpl lockStore = getLockStore();
    boolean unlocked;
    if (force) {
        unlocked = lockStore.forceUnlock(key);
    } else {
        unlocked = lockStore.unlock(key, originalCallerUuid, threadId, getReferenceCallId());
    }
    response = unlocked;
}
Also used : LockStoreImpl(com.hazelcast.internal.locksupport.LockStoreImpl)

Example 7 with LockStoreImpl

use of com.hazelcast.internal.locksupport.LockStoreImpl in project hazelcast by hazelcast.

the class UnlockOperation method unlock.

protected final void unlock() {
    LockStoreImpl lockStore = getLockStore();
    boolean unlocked = lockStore.unlock(key, getCallerUuid(), threadId, getReferenceCallId());
    response = unlocked;
    if (!unlocked) {
        // we can not check for retry here, hence just throw the exception
        String ownerInfo = lockStore.getOwnerInfo(key);
        throw new IllegalMonitorStateException("Current thread is not owner of the lock! -> " + ownerInfo);
    } else {
        ILogger logger = getLogger();
        if (logger.isFinestEnabled()) {
            logger.finest("Released lock " + namespace.getObjectName());
        }
    }
}
Also used : LockStoreImpl(com.hazelcast.internal.locksupport.LockStoreImpl) ILogger(com.hazelcast.logging.ILogger)

Example 8 with LockStoreImpl

use of com.hazelcast.internal.locksupport.LockStoreImpl in project hazelcast by hazelcast.

the class LockBackupOperation method run.

@Override
public void run() throws Exception {
    if (isClient) {
        ClientEngine clientEngine = getNodeEngine().getService(ClientEngineImpl.SERVICE_NAME);
        clientEngine.onClientAcquiredResource(originalCallerUuid);
    }
    interceptLockOperation();
    LockStoreImpl lockStore = getLockStore();
    response = lockStore.lock(key, originalCallerUuid, threadId, getReferenceCallId(), leaseTime);
}
Also used : LockStoreImpl(com.hazelcast.internal.locksupport.LockStoreImpl) ClientEngine(com.hazelcast.client.impl.ClientEngine)

Example 9 with LockStoreImpl

use of com.hazelcast.internal.locksupport.LockStoreImpl in project hazelcast by hazelcast.

the class LocalLockCleanupOperation method run.

@Override
public void run() throws Exception {
    LockStoreImpl lockStore = getLockStore();
    LockResource lock = lockStore.getLock(key);
    if (uuid.equals(lock.getOwner())) {
        ILogger logger = getLogger();
        if (logger.isFinestEnabled()) {
            logger.finest("Unlocking lock owned by UUID: " + uuid + ", thread ID: " + lock.getThreadId() + ", count: " + lock.getLockCount());
        }
        response = lockStore.forceUnlock(key);
    }
}
Also used : LockStoreImpl(com.hazelcast.internal.locksupport.LockStoreImpl) LockResource(com.hazelcast.internal.locksupport.LockResource) ILogger(com.hazelcast.logging.ILogger)

Example 10 with LockStoreImpl

use of com.hazelcast.internal.locksupport.LockStoreImpl in project hazelcast by hazelcast.

the class MultiMapLockTest method lockStoreShouldBeRemoved_whenMultimapIsDestroyed.

/**
 * See issue #4888
 */
@Test
public void lockStoreShouldBeRemoved_whenMultimapIsDestroyed() {
    HazelcastInstance hz = createHazelcastInstance();
    MultiMap<String, Integer> multiMap = hz.getMultiMap(randomName());
    for (int i = 0; i < 1000; i++) {
        multiMap.lock("" + i);
    }
    multiMap.destroy();
    NodeEngineImpl nodeEngine = getNodeEngineImpl(hz);
    LockSupportServiceImpl lockService = nodeEngine.getService(LockSupportService.SERVICE_NAME);
    int partitionCount = nodeEngine.getPartitionService().getPartitionCount();
    for (int i = 0; i < partitionCount; i++) {
        LockStoreContainer lockContainer = lockService.getLockContainer(i);
        Collection<LockStoreImpl> lockStores = lockContainer.getLockStores().stream().filter(s -> !s.getNamespace().getObjectName().startsWith(JobRepository.INTERNAL_JET_OBJECTS_PREFIX)).collect(Collectors.toList());
        assertEquals("LockStores should be empty: " + lockStores, 0, lockStores.size());
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) LockStoreImpl(com.hazelcast.internal.locksupport.LockStoreImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) RunWith(org.junit.runner.RunWith) MultiMapConfig(com.hazelcast.config.MultiMapConfig) LockSupportService(com.hazelcast.internal.locksupport.LockSupportService) LockSupportServiceImpl(com.hazelcast.internal.locksupport.LockSupportServiceImpl) JobRepository(com.hazelcast.jet.impl.JobRepository) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) LockStoreContainer(com.hazelcast.internal.locksupport.LockStoreContainer) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) LockStoreImpl(com.hazelcast.internal.locksupport.LockStoreImpl) HazelcastTestSupport(com.hazelcast.test.HazelcastTestSupport) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) Assert.assertFalse(org.junit.Assert.assertFalse) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) AssertTask(com.hazelcast.test.AssertTask) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) HazelcastInstance(com.hazelcast.core.HazelcastInstance) LockSupportServiceImpl(com.hazelcast.internal.locksupport.LockSupportServiceImpl) LockStoreContainer(com.hazelcast.internal.locksupport.LockStoreContainer) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

LockStoreImpl (com.hazelcast.internal.locksupport.LockStoreImpl)10 ILogger (com.hazelcast.logging.ILogger)4 LockStoreContainer (com.hazelcast.internal.locksupport.LockStoreContainer)3 LockSupportServiceImpl (com.hazelcast.internal.locksupport.LockSupportServiceImpl)3 Config (com.hazelcast.config.Config)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 LockSupportService (com.hazelcast.internal.locksupport.LockSupportService)2 JobRepository (com.hazelcast.jet.impl.JobRepository)2 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)2 Accessors.getNodeEngineImpl (com.hazelcast.test.Accessors.getNodeEngineImpl)2 AssertTask (com.hazelcast.test.AssertTask)2 HazelcastParallelClassRunner (com.hazelcast.test.HazelcastParallelClassRunner)2 HazelcastTestSupport (com.hazelcast.test.HazelcastTestSupport)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 Collection (java.util.Collection)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 TimeUnit (java.util.concurrent.TimeUnit)2 Collectors (java.util.stream.Collectors)2