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: how to lock one-of-many ?

2010-02-24 Thread Ted Dunning
I do believe that it is relatively easy to set up high latency/high error network interface clones in Linux. I haven't looked into that for several years, but it used to be pretty easy. You can also build a delegater that wraps a real ZK connection. That would be more compatible with a mocked

Re: how to lock one-of-many ?

2010-02-24 Thread Ted Dunning
Random back-off like this is unlikely to succeed (seems to me). Better to use the watch on the locks directory to make the wait as long as possible AND as short as possible. On Wed, Feb 24, 2010 at 8:53 AM, Patrick Hunt ph...@apache.org wrote: Anyone interested in locking an explicit resource

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: how to lock one-of-many ?

2010-02-24 Thread Martin Waite
Hi, I take the point that the watch is useful for stopping clients unnecessarily pestering the zk nodes. I think that this is something I will have to experiment with and see how it goes. I only need to place about 10k locks per minute, so I am hoping that whatever approach I take is well

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: how to lock one-of-many ?

2010-02-24 Thread Martin Waite
Hi Patrick, Thanks for the info - the Fallacies link especially. As you might have guessed, I am one the programmers new to distributed computing who is very much in danger of messing things up. I am going to have to knuckle down and do some experiments. Thankfully, I don't think my

Re: how to lock one-of-many ?

2010-02-24 Thread Mahadev Konar
Hi martin, Currently you cannot access the server that the client is connected to. This was fixed in this jira http://issues.apache.org/jira/browse/ZOOKEEPER-544 But again this does not tell you if you are connected to the primary or the other followers. So you will anyway have to do some

Re: how to lock one-of-many ?

2010-02-24 Thread Patrick Hunt
Actually you can do it today, but not as easily. Look at the patch for 544 - in your test you need to create your own subclass of ZooKeeper, then you can use the cnxn in a similar way as the patch does in order to access the data. Not particularly hard, but we've wrapped it up in a nice

Re: how to lock one-of-many ?

2010-02-24 Thread Ted Dunning
I was thinking of adding it on the client. You can sub-class the client connection and add any desired additional behaviors such as delays. I am fond of mocking the client connection as well in order to simulate severe malfunctions or failure scenarios. On Wed, Feb 24, 2010 at 11:18 AM, Martin

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