Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
Zookeeper >> mail # user >> Re: need for more conditional write support


Copy link to this message
-
Re: need for more conditional write support
On 21 December 2010 13:48, Ted Dunning <[EMAIL PROTECTED]> wrote:

> On Tue, Dec 21, 2010 at 1:30 PM, Henry Robinson <[EMAIL PROTECTED]>
> wrote:
>
> > This is a more complicated requirement, and not something that can be
> done
> > right now with Zookeeper even in a single operation on a single znode.
> The
> > only conditional operations are updates.
>
>

> Actually, creates and deletes are conditional also.  Creates are
> conditional
> on the file
> not existing previously and deletes can accept a version number.
>
>
Thanks Ted - yes, I misspoke. I was thinking of conditional creates (on
inspection of some znode's version) and extrapolated to deletes.
>
> > Designing an API to support three
> > different kinds of operation would also be more complicated, and the
> > implementation would be trickier.
> >
>
> This is definitely true.  Conceptually it is the same thing, but
> practically
> building a usable API is
> a bit tricky.  Using a builder style would work, though.  For example:
>
>       Zookeeper zk = ...;
>
>
>       zk.transaction()
>                .create("/foobar")
>                .update("/pig", data, version)
>                .delete("/dog"", otherVersion)
>                .commit()
>
> Another option would be to pass a list of operations which can be one of
> Create, Update or delete.
>

A builder API is a bit of a departure from the core ZK API as it stands. I'd
rather see something like:

zk_multi_op(List<String> create_paths, List<String> delete_paths,
List<Version> delete_versions, List<String> update_paths, List<String>
update_versions, List<String> update_data);

or

struct op {
  int type; // OP_CREATE, OP_DELETE, OP_UPDATE
  String path;
  long version; // ignored for OP_CREATE, must be -1 to be ignored for
OP_DELETE | OP_UPDATE
  char *data; // null for OP_DELETE
}

int zk_multi_op(List<op> operations);

in the core API, wrapped with a builder in the Java client.

Henry
--
Henry Robinson
Software Engineer
Cloudera
415-994-6679