You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@zookeeper.apache.org by Erik Hetzner <er...@ucop.edu> on 2011/03/10 00:14:26 UTC
Problem with WriteLock
Hi,
I am attempting to use the WriteLock recipe provided with ZK 3.3.2.
Unfortunately, I seem to be deadlocking when I try to lock from
multiple threads. If I lock sequentially, I have no trouble. Can
somebody let me know what I am doing wrong here? I am attaching some
sample code; I can also provide a complete maven project to test if
necessary. (For the record, I have increased maxClientCnxns in my
zoo.cfg to 100.)
Here we see the results without threading:
$ time java -cp "lib/*" Test nothread
[…]
finished 9
real 0m1.361s
user 0m0.380s
sys 0m0.050s
And here is the threaded version:
$ time java -cp "lib/*" Test thread
finished 9
finished 8
finished 1
^C
real 3m4.627s
user 0m4.600s
sys 0m2.060s
On the other hand, it does not always deadlock:
$ time java -cp "lib/*" Test thread
finished 4
finished 0
finished 3
finished 5
finished 6
finished 7
finished 2
finished 1
finished 8
finished 9
real 0m7.824s
user 0m1.030s
sys 0m0.170s
Thanks for any help you can provide!
best, Erik Hetzner
Re: Problem with WriteLock
Posted by Ted Dunning <te...@gmail.com>.
That java api looks like it strongly encourages the caller to implement a
race condition. If a call to lock fails
then the user must register a call-back or check if the lock has been
granted. Unfortunately, the registration
of the call-back may happen after the lock has been granted in which case
the locker never knows. If the locker
checks after registering the callback, they may wind up with double
notification.
Registering the callback before asking for the lock seems kind of scary as
well, though it might well work.
Why not do it like a real java lock and have a timeout? If you don't get
the lock, you block until your timeout.
Then later you can call lock again and if you got it in the meantime it
should just succeed.
On Wed, Mar 9, 2011 at 4:54 PM, Erik Hetzner <er...@ucop.edu> wrote:
> At Wed, 9 Mar 2011 18:48:11 -0600,
> Scott Fines wrote:
> >
> > Could you send on a link to your WriteLock implementation?
>
> This is the recipe distributed with ZK.
>
>
> http://svn.apache.org/repos/asf/zookeeper/tags/release-3.3.2/src/recipes/lock/
>
> > Also, have you considered using the locks provided in
> > menagerie<https://github.com/openUtility/menagerie>
> > or KeptCollections <https://github.com/anthonyu/KeptCollections>? They
> may
> > or may not provide the features that you are interested in, but still
> worth
> > checking out.
>
> I hadn’t seen those. Thank you for the links!
>
> best, Erik
>
> Sent from my free software system <http://fsf.org/>.
>
>
Re: Problem with WriteLock
Posted by Erik Hetzner <er...@ucop.edu>.
At Wed, 9 Mar 2011 18:48:11 -0600,
Scott Fines wrote:
>
> Could you send on a link to your WriteLock implementation?
This is the recipe distributed with ZK.
http://svn.apache.org/repos/asf/zookeeper/tags/release-3.3.2/src/recipes/lock/
> Also, have you considered using the locks provided in
> menagerie<https://github.com/openUtility/menagerie>
> or KeptCollections <https://github.com/anthonyu/KeptCollections>? They may
> or may not provide the features that you are interested in, but still worth
> checking out.
I hadn’t seen those. Thank you for the links!
best, Erik
Re: Problem with WriteLock
Posted by Scott Fines <sc...@gmail.com>.
Could you send on a link to your WriteLock implementation?
Also, have you considered using the locks provided in
menagerie<https://github.com/openUtility/menagerie>
or KeptCollections <https://github.com/anthonyu/KeptCollections>? They may
or may not provide the features that you are interested in, but still worth
checking out.
Scott
On Wed, Mar 9, 2011 at 5:14 PM, Erik Hetzner <er...@ucop.edu> wrote:
> Hi,
>
> I am attempting to use the WriteLock recipe provided with ZK 3.3.2.
> Unfortunately, I seem to be deadlocking when I try to lock from
> multiple threads. If I lock sequentially, I have no trouble. Can
> somebody let me know what I am doing wrong here? I am attaching some
> sample code; I can also provide a complete maven project to test if
> necessary. (For the record, I have increased maxClientCnxns in my
> zoo.cfg to 100.)
>
> Here we see the results without threading:
>
> $ time java -cp "lib/*" Test nothread
> […]
> finished 9
>
> real 0m1.361s
> user 0m0.380s
> sys 0m0.050s
>
> And here is the threaded version:
>
> $ time java -cp "lib/*" Test thread
> finished 9
> finished 8
> finished 1
> ^C
> real 3m4.627s
> user 0m4.600s
> sys 0m2.060s
>
> On the other hand, it does not always deadlock:
>
> $ time java -cp "lib/*" Test thread
> finished 4
> finished 0
> finished 3
> finished 5
> finished 6
> finished 7
> finished 2
> finished 1
> finished 8
> finished 9
>
> real 0m7.824s
> user 0m1.030s
> sys 0m0.170s
>
> Thanks for any help you can provide!
>
> best, Erik Hetzner
>
>
> Sent from my free software system <http://fsf.org/>.
>
>
Re: Problem with WriteLock
Posted by andre <an...@gmail.com>.
Hi,
there's a bug on this lock recipe implementation. I don't know if it's
related with your issue, but you could give it a try.
https://issues.apache.org/jira/browse/ZOOKEEPER-645
If those patches don't solve your issue, please, let me know.
[]'s
--
View this message in context: http://zookeeper-user.578899.n2.nabble.com/Problem-with-WriteLock-tp6155922p6287856.html
Sent from the zookeeper-user mailing list archive at Nabble.com.