Re: DistributedLock logistics

106 views
Skip to first unread message

Fuad Malikov

unread,
Mar 12, 2013, 12:31:00 PM3/12/13
to haze...@googlegroups.com
Hi Gisella,
(Welcome back:))

My answers are inlined

On Fri, Mar 8, 2013 at 9:02 AM, <gise...@yachay.net> wrote:
Hello,

On using ILock, 
. hazelcast confifguration: I do not see any specific entries for this type of object. E.g., locks being destroyed after not being locked for a certain time (idle?)
. let's say, I choose String as the object to lock.


. If I somehow use the lock to lock on a key for some time, but then I do not want to have this object stay in the hazelcast cache, how do I get rid of it?
   call ILock.destroy()???

Yes, you need to destroy it. Otherwise it will remain in the memory. However if you use lock on IMap and not use the entry for any other purpose, after the unlock, it will be destroyed automatically. 

Imap.lock("mylock");
Imap.unlock("mylock");

 
. I created a JMX class function to view the locks that are being used, when they are in locked state,

Collection<Instance> instances = hazelcastInstance.getInstances();
        Set<LockInfo<String>> locks = new HashSet<LockInfo<String>>();
        for (Instance inst : instances) {
            if (inst.getInstanceType().equals(Instance.InstanceType.LOCK)) {
                ILock lock = (ILock) inst;
                if (lock.isLocked()) {
                    LockInfo<String> lockInfo = getLockInfo(lock);
                    locks.add(lockInfo);
                }
            }
        }


   1. The code above I believe will only get the locks that my local instance is seeing,or that the code has invoked by calling hazelcastInstance.getLock(lockName), correct?

It will get all the locks that are locked in the system. Doesn't matter where they are created. Actually there is no way of getting the locks that are created in specific member. Actually it want tell you the locks on the IMap. It will return only the locks that are created as hazelcastInstance.getLock("");
 
    2. If I want to see all the locks in the system, I might have to use Hazelcast.getAllInstances(), and then apply the loop above, ??
Yes, except the locks on the IMap. 
 
  3. The class LocalLockStats, as the name says, would only have information about locks used in the local node?
It will show you the statistics that is gathered from local node. But you can apply it to any Lock. That is the lock can be anywhere, but the statistics is just about the local node. Ex: How many locks per second is this local node is doing on this distributed ILock.
 
 4. periodStart and PeriodEnd, are these related to lock creation or last time being locked?

These are related only to the statistics. The information on LocalLockStat is relevant to that timeframe. 
 
5. Is it a good idea to hold on an ILock once I create a lock in a node, or should it be better to just call hazelcastInstance.getLock(lockName) all the time and the apply the desired lock
   operation?
It doesn't matter. It is the same proxy and you can save from one CHM lookup by just holding the ILock.  
 
    The reason I am asking this, is that if another node, e.g., node2,  is later locking the same lock that node1 create, locked, and unlocked.
     Then node2 after it finishes de3cides to destroy the lock.
      Will node1, which has got a hold of the ILock, when it first created the lock, if it tries to lock again, get an exception, since the lock was destroyed??
Even if it is destroyed, when node1 does an operation on it, Hazelcast will silently create that lock.  

I would appreciate any feedback regarding these questions.

Thanks.

--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at http://groups.google.com/group/hazelcast?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Fuad Malikov

unread,
Mar 21, 2013, 10:47:00 PM3/21/13
to haze...@googlegroups.com
Hi Gisella,


On Wed, Mar 13, 2013 at 4:35 PM, <gise...@yachay.net> wrote:

thanks a lot, Fuad.
I did some local testing, and it is as you say. I just ran into some issue that I have not retried again (destroying a locked lock without unlocking first...)

I decided to use the map instead, as a lock.


Nice choice. 
 
Regarding this approach, this type of object allows me to lock a key that does not exist in the map.  This means that if my purpose is just to have a distributed lock, and my different nodes call
lock, trylock on a KEY, it will work as the distributed lock, but the keys will not be added to the map (and not seen thru JMX).
If this approach is safe, calling map.isLocked(KEY)  will return true from any node when KEY is locked.

Right.  

 map.forceUnlock(KEY) seems to be missing the communication of the KEY being UNLOCKED to the other nodes,  
only the node that calls  forceUnlocked() on the KEY (either it is the one that locked it or not) sees its status as UNLOCKED, the other node(s)  (only tested two nodes) still see the KEY as LOCKED.
E.g.,
. Node 1  
   . (optional): put KEY
   . lock KEY
. Node 2
   . forceUnlock (KEY)

Node 2 sees that the KEY isLocked() = false
Node 1, who created the lock (it does not matter who created the lock), still sees isLocked() = true

 So, it appears that only the node that forced the unlock, sees the real status of the key as NOT being locked; the other guys (I have only tried two nodes) still sees the key as locked.
This seems to be a bug? 

I tried it and yes, the original locker, sees it as locked, even though it has been forcedUnlock.Any other cluster member will see it as unlocked. 
 
Is there something I need to do so that the real KEY status is reflected across the cluster?

So it is already distributed but the one who did the lock, sees it as locked. This should be fixed but in practice this shouldn't cause much problem. Because the one who locked, should already unlock it and forcingUnlock should be done very rarely and only for hanging locks. Somehow the lock was taken but never unlocked. Otherwise you are breaking all the purpose of locking. 
 
 

Thanks.

On Friday, March 8, 2013 9:02:05 AM UTC-8, gise...@yachay.net wrote:
Hello,

On using ILock, 
. hazelcast confifguration: I do not see any specific entries for this type of object. E.g., locks being destroyed after not being locked for a certain time (idle?)
. let's say, I choose String as the object to lock.


. If I somehow use the lock to lock on a key for some time, but then I do not want to have this object stay in the hazelcast cache, how do I get rid of it?
   call ILock.destroy()???

. I created a JMX class function to view the locks that are being used, when they are in locked state,

Collection<Instance> instances = hazelcastInstance.getInstances();
        Set<LockInfo<String>> locks = new HashSet<LockInfo<String>>();
        for (Instance inst : instances) {
            if (inst.getInstanceType().equals(Instance.InstanceType.LOCK)) {
                ILock lock = (ILock) inst;
                if (lock.isLocked()) {
                    LockInfo<String> lockInfo = getLockInfo(lock);
                    locks.add(lockInfo);
                }
            }
        }


   1. The code above I believe will only get the locks that my local instance is seeing,or that the code has invoked by calling hazelcastInstance.getLock(lockName), correct?
    2. If I want to see all the locks in the system, I might have to use Hazelcast.getAllInstances(), and then apply the loop above, ??
  3. The class LocalLockStats, as the name says, would only have information about locks used in the local node?
 4. periodStart and PeriodEnd, are these related to lock creation or last time being locked?
5. Is it a good idea to hold on an ILock once I create a lock in a node, or should it be better to just call hazelcastInstance.getLock(lockName) all the time and the apply the desired lock
   operation?
    The reason I am asking this, is that if another node, e.g., node2,  is later locking the same lock that node1 create, locked, and unlocked.
     Then node2 after it finishes de3cides to destroy the lock.
      Will node1, which has got a hold of the ILock, when it first created the lock, if it tries to lock again, get an exception, since the lock was destroyed??

I would appreciate any feedback regarding these questions.

Thanks.

Reply all
Reply to author
Forward
0 new messages