Thanks for your quick reply, Ted.

we are implementing a distributed system, using zookeeper for master metedata 
persistence. There's DISK object and DISK-PAIR object. when creating a 
DISK-PAIR, we need to first create a znode indicating DISK-PAIR object and 
updating the corresponding two DISK's state from DISK_OFFLINE to DISK_ONLINE, 
these operations need to be done as a whole.



发件人: Ted Dunning <>
发送时间: 2010-03-30 10:11
主 题: Re: How to ensure trasaction create-and-update

This is not a good thing.  ZK gains lots of its power and reliability by not 
trying to do atomic updates to multiple znodes at once. 

Can you say more about the update that you want to do?  It is common for 
updates like to be such that you can order the updates and do without a 
truly atomic transaction.  For instance if one file is a list of other files 
(say for a queue) and you need to create a file and add a reference in the 
list of files, you can generally be safe creating the new file first and 
then doing an atomic update on the list of files secondly.  If your process 
fails between the two operations, then you may generate a small number of 
garbage files (this number can be substantially decreased by careful use of 
try/finally) which might require a cleanup process to run occasionally to 
find unreferenced and old files. 

On Mon, Mar 29, 2010 at 6:54 PM, zd.wbh <> wrote: 

>   we'd like to store some metadata in zookeeper in our upcoming project, 
> here is a special but common case: we need to create a new znode, in the 
> mean while, update another znode data. These manipulation(a create and a 
> update) need to be done as atom. We don't want to see a successful creation 
> and a failure updating. Is there a convenient way to ensure this operation? 
> Can you give me some tips? 
>    I've looked into the src code, there is a tedious way to do. Extend 
> zookeeper instruction, struct a "createAndUpdate" interface and a txn 
> request, let DataTree to ensure the integrity. Will this do and the only 
> way? 

Reply via email to