Yes, Ted's right. The multi has to fail as that's part of the contract it
guarantees.

The only thing you could do, which will significantly narrow the race
condition, is as you're *building *the multi, check if the path already
exists. If so, then don't add the create op for that path into the multi.
Of course this may not work in every situation, but we use that approach in
many code paths and it works well.

On Wed, Feb 29, 2012 at 7:59 PM, Ted Dunning <ted.dunn...@gmail.com> wrote:

> Yes.  I don't know of a good race-free solution involving a single
> multi-request.
>
> On Wed, Feb 29, 2012 at 4:52 PM, Shelley, Ryan <ryan.shel...@disney.com
> >wrote:
>
> > Thanks for that. Out of curiosity, in my prior example of creating a node
> > at /lorem/ipsum/foo/bar, if I'm building the multi operation list and at
> > the same time some other client creates /lorem before I execute the multi
> > operation, will the entire multi fail because /lorem already exists?
> >
> > On 2/29/12 4:46 PM, "Ted Dunning" <ted.dunn...@gmail.com> wrote:
> >
> > >
> http://zookeeper.apache.org/doc/r3.4.2/api/org/apache/zookeeper/ZooKeeper
> > .
> > >html#multi(java.lang.Iterable)
> > >
> > >The javadoc for Op does not appear for an unknown (to me) reason.  Here
> it
> > >is from org.apache.zookeeper.Op:
> > >
> > >/**
> > > * Represents a single operation in a multi-operation transaction.  Each
> > >operation can be a create, update
> > > * or delete or can just be a version check.
> > > *
> > > * Sub-classes of Op each represent each detailed type but should not
> > >normally be referenced except via
> > > * the provided factory methods.
> > > *
> > > * @see ZooKeeper#create(String, byte[], java.util.List, CreateMode)
> > > * @see ZooKeeper#create(String, byte[], java.util.List, CreateMode,
> > >org.apache.zookeeper.AsyncCallback.StringCallback, Object)
> > > * @see ZooKeeper#delete(String, int)
> > > * @see ZooKeeper#setData(String, byte[], int)
> > > */
> > >
> > >Sample usage can be found in
> > >org.apache.zookeeper.test.MultiTransactionTest
> > >
> > >On Wed, Feb 29, 2012 at 4:26 PM, Shelley, Ryan
> > ><ryan.shel...@disney.com>wrote:
> > >
> > >> Can you reference some docs? I looked but couldn't find anything
> > >>regarding
> > >> multi.
> > >>
> > >> On 2/29/12 4:23 PM, "Ted Dunning" <ted.dunn...@gmail.com> wrote:
> > >>
> > >> >Well, in 3.4, you can use multi to do this.
> > >> >
> > >> >On Wed, Feb 29, 2012 at 4:08 PM, Shelley, Ryan
> > >> ><ryan.shel...@disney.com>wrote:
> > >> >
> > >> >> Is it possible to create all nodes in a path in one step?
> > >> >>
> > >> >> For example, my ZK is empty of any nodes. I want to create:
> > >> >> /lorem/ipsum/foo/bar
> > >> >>
> > >> >> Do I have to create each segment with iterative calls to ZK, or is
> > >>there
> > >> >> an easier way to build this?
> > >> >>
> > >>
> > >>
> >
> >
>

Reply via email to