zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Benjamin Reed (JIRA)" <j...@apache.org>
Subject [jira] Commented: (ZOOKEEPER-78) added a high level protocol/feature - for easy Leader Election or exclusive Write Lock creation
Date Mon, 21 Jul 2008 16:53:31 GMT

    [ https://issues.apache.org/jira/browse/ZOOKEEPER-78?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12615305#action_12615305
] 

Benjamin Reed commented on ZOOKEEPER-78:
----------------------------------------

There is a bug in this block of code:

{code:java}
       while (!closed.get() && id == null) {
           retryDelay(attempt++);
           try {
               id = zookeeper.create(dir + "/x-", data, acl, EPHEMERAL | SEQUENCE);
               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);
           }
       }
{code}

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

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.


Mime
View raw message