how to lock one-of-many ?

2010-02-23 Thread Martin Waite
Hi, I have a set of resources each of which has a unique identifier. Each resource element must be locked before it is used, and unlocked afterwards. The logic of the application is something like: lock any one element; if (none locked) then exit with error; else get resource-id from

Re: how to lock one-of-many ?

2010-02-23 Thread Mahadev Konar
Hi Martin, How about this- you have resources in the a directory (say /locks) each process which needs to lock, lists all the children of this directory and then creates an ephemeral node called /locks/resource1/lock depending on which resource it wants to lock. This ephemeral node will

Re: how to lock one-of-many ?

2010-02-23 Thread Ted Dunning
I think that the crux of Mahadev's suggestion is that you do as you say, but you should try the resources in randomized order. That will have very robust properties, especially with more than a handful of resources and is easy to code and to analyze. It won't work if you really mean lock first

Re: Bit of help debugging a TIMED OUT session please

2010-02-23 Thread Patrick Hunt
Stack you might look at the following: 1) why does server 14 have such a low recv count? Received: 194 while the other servers are at 3.7k + received. Did server 14 fail at some point? Or it's network? This may have caused the timeout seen by the client: --snippet-

Re: how to lock one-of-many ?

2010-02-23 Thread Martin Waite
Thanks Mahadev. Randomising the look-up is a good fit for what I am trying to do, and should minimise the number of look-ups performed. I guess another optimisation might be to count the number of locks held first: if the count equals the number of resources, try again later. But I suppose