Benjamin Reed commented on ZOOKEEPER-78:

There is a bug in this block of code:

       while (!closed.get() && id == null) {
           try {
               id = zookeeper.create(dir + "/x-", data, acl, EPHEMERAL | 
               idName = new ZNodeName(id);
               if (LOG.isDebugEnabled()) {
                   LOG.debug("Created id: " + id);
           } catch (KeeperException e) {
               LOG.warn("Caught: " + e, e);
           } catch (InterruptedException e) {
               LOG.warn("Caught: " + e, e);

zookeeper.create is not idempotent, so blindly retrying will land you into 

1) You start the create, a connection error happens, the create completes but 
you don't get a response
2) You retry your create
3) You may end up waiting on the znode from step 1) which will not go away

I've been thinking of easy ways of getting around this problem and the easiest 
seems to be constructing the name as x-identifier-sequenceNumber. You could use 
the hostname or the sessionid as the identifier. When you do the retry you have 
to do a getChildren() to see if there are any znodes with your identifier and 
then use that znode if it exists.

> added a high level protocol/feature - for easy Leader Election or exclusive 
> Write Lock creation
> -----------------------------------------------------------------------------------------------
>                 Key: ZOOKEEPER-78
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-78
>             Project: Zookeeper
>          Issue Type: New Feature
>          Components: java client
>    Affects Versions: 3.0.0
>            Reporter: james strachan
>            Assignee: james strachan
>         Attachments: writeLock_protocol_version3.patch
> Here's a patch which adds a little WriteLock helper class for performing 
> leader elections or creating exclusive locks in some directory znode. Note 
> its an early cut; am sure we can improve it over time. The aim is to avoid 
> folks having to use the low level ZK stuff but provide a simpler high level 
> abstraction.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

Reply via email to