Re: is there a good pattern for leases ?

2010-02-25 Thread Martin Waite
Hi Usually, this would hold about 2k items, pushing to 10k peaks. My current understanding is that I cannot lock a node while I consider its contents, and so only the garbage remover would be allowed to remove locks (currently lock-clients can claim expired locks). The clients would simply do

Re: is there a good pattern for leases ?

2010-02-25 Thread Martin Waite
Hi, Another possible approach: 1. client generates hash code to be locked. use the first N hex digits (eg. first 2 digits) as a filename FN. 2. attempt to create (ephemeral) node FN.lock. loop until this succeeds, or abort when time budget exhausted. 3. read node FN containing

Re: is there a good pattern for leases ?

2010-02-25 Thread Martin Waite
Hmm, Thanks Ted. I am going to have to do some more reading. regards, Martin On 25 February 2010 19:11, Ted Dunning ted.dunn...@gmail.com wrote: Not really. You have ordering guarantees and you can avoid the whole mess by using the version numbers when you update the file. See my other

Re: is there a good pattern for leases ?

2010-02-25 Thread Ted Dunning
Not really. You have ordering guarantees and you can avoid the whole mess by using the version numbers when you update the file. See my other email. On Thu, Feb 25, 2010 at 2:50 AM, Martin Waite waite@googlemail.comwrote: But to do this, would I need to call sync between steps 2 and 3 to

Re: is there a good pattern for leases ?

2010-02-25 Thread Ted Dunning
That is one of the strengths of ZK. Your client would do this: 1) create node, if success client has lock 2) get current node (you get the current version when you do this), if lease is current and ours, we have the lock, if lease is current and not ours, we have failed to get the lock 3) try to

Re: is there a good pattern for leases ?

2010-02-24 Thread Henry Robinson
A cautionary note with this problem - who says when 2 minutes is up? Clocks will go forward at different rates and with different offsets. You cannot rely on two machines having the same perception of what 2 minutes means. In general, in distributed systems, it's a good design principle to

Re: is there a good pattern for leases ?

2010-02-24 Thread Martin Waite
Hi Mahadev, That is interesting. All I need to do is hold the connection for the required time of a session that created an ephemeral node. Zookeeper is an interesting tool. Thanks again, Martin On 24 February 2010 17:00, Mahadev Konar maha...@yahoo-inc.com wrote: Hi Martin, There isnt an

Re: is there a good pattern for leases ?

2010-02-24 Thread Mahadev Konar
I am not sure if I was clear enoguh in my last message. What is suggested was this: Create a client with a timeout of lets say 10 seconds! Zookeeper zk = new ZooKeeper(1); (for brevity ignoring other parameters) Zk.create(/parent/ephemeral, data, EPEMERAL); //create a another thread that

Re: is there a good pattern for leases ?

2010-02-24 Thread Ted Dunning
You can simply implement the current system if you like by keeping a file per card in ZK that contains your lock expiration time. The garbage collector would work the same way. In order to make the getchildren operation in the garbage collector work well, I would recommend a hierarchical naming