Search in sources :

Example 1 with LockStoreImpl

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

the class LockReplicationOperation method run.

@Override
public void run() {
    LockSupportServiceImpl lockService = getService();
    LockStoreContainer container = lockService.getLockContainer(getPartitionId());
    for (LockStoreImpl ls : locks) {
        container.put(ls);
    }
}
Also used : LockStoreImpl(com.hazelcast.internal.locksupport.LockStoreImpl) LockSupportServiceImpl(com.hazelcast.internal.locksupport.LockSupportServiceImpl) LockStoreContainer(com.hazelcast.internal.locksupport.LockStoreContainer)

Example 2 with LockStoreImpl

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

the class LockReplicationOperation method writeInternal.

@Override
protected void writeInternal(final ObjectDataOutput out) throws IOException {
    super.writeInternal(out);
    int len = locks.size();
    out.writeInt(len);
    if (len > 0) {
        for (LockStoreImpl ls : locks) {
            out.writeObject(ls);
        }
    }
}
Also used : LockStoreImpl(com.hazelcast.internal.locksupport.LockStoreImpl)

Example 3 with LockStoreImpl

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

the class UnlockIfLeaseExpiredOperation method run.

@Override
public void run() {
    LockStoreImpl lockStore = getLockStore();
    int lockVersion = lockStore.getVersion(key);
    ILogger logger = getLogger();
    if (version == lockVersion) {
        if (logger.isFinestEnabled()) {
            logger.finest("Releasing a lock owned by " + lockStore.getOwnerInfo(key) + " after lease timeout!");
        }
        forceUnlock();
    } else {
        if (logger.isFinestEnabled()) {
            logger.finest("Won't unlock since lock version is not matching expiration version: " + lockVersion + " vs " + version);
        }
    }
}
Also used : LockStoreImpl(com.hazelcast.internal.locksupport.LockStoreImpl) ILogger(com.hazelcast.logging.ILogger)

Example 4 with LockStoreImpl

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

the class UnlockOperation method forceUnlock.

protected final void forceUnlock() {
    LockStoreImpl lockStore = getLockStore();
    boolean unlocked = lockStore.forceUnlock(key);
    this.response = unlocked;
    ILogger logger = getLogger();
    if (logger.isFinestEnabled()) {
        if (unlocked) {
            logger.finest("Released lock " + namespace.getObjectName());
        } else {
            logger.finest("Could not release lock " + namespace.getObjectName() + " as it is not locked");
        }
    }
}
Also used : LockStoreImpl(com.hazelcast.internal.locksupport.LockStoreImpl) ILogger(com.hazelcast.logging.ILogger)

Example 5 with LockStoreImpl

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

the class MapLockTest method lockStoreShouldBeRemoved_whenMapIsDestroyed.

/**
 * See issue #4888
 */
@Test
public void lockStoreShouldBeRemoved_whenMapIsDestroyed() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<Integer, Integer> map = instance.getMap(randomName());
    for (int i = 0; i < 1000; i++) {
        map.lock(i);
    }
    map.destroy();
    NodeEngineImpl nodeEngine = getNodeEngineImpl(instance);
    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", 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) Random(java.util.Random) TransactionException(com.hazelcast.transaction.TransactionException) 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) NightlyTest(com.hazelcast.test.annotation.NightlyTest) 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.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) NightlyTest(com.hazelcast.test.annotation.NightlyTest) 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