Return-Path: X-Original-To: apmail-zookeeper-user-archive@www.apache.org Delivered-To: apmail-zookeeper-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A4E989ED8 for ; Thu, 1 Mar 2012 23:28:15 +0000 (UTC) Received: (qmail 8998 invoked by uid 500); 1 Mar 2012 23:28:15 -0000 Delivered-To: apmail-zookeeper-user-archive@zookeeper.apache.org Received: (qmail 8964 invoked by uid 500); 1 Mar 2012 23:28:15 -0000 Mailing-List: contact user-help@zookeeper.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@zookeeper.apache.org Delivered-To: mailing list user@zookeeper.apache.org Received: (qmail 8956 invoked by uid 99); 1 Mar 2012 23:28:15 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Mar 2012 23:28:15 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of marshall.mcmullen@gmail.com designates 209.85.212.170 as permitted sender) Received: from [209.85.212.170] (HELO mail-wi0-f170.google.com) (209.85.212.170) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Mar 2012 23:28:05 +0000 Received: by wibhj13 with SMTP id hj13so325680wib.15 for ; Thu, 01 Mar 2012 15:27:45 -0800 (PST) Received: by 10.180.76.175 with SMTP id l15mr312583wiw.2.1330644465697; Thu, 01 Mar 2012 15:27:45 -0800 (PST) Received: from mail-bk0-f42.google.com (mail-bk0-f42.google.com [209.85.214.42]) by mx.google.com with ESMTPS id s4sm17269556wiy.5.2012.03.01.15.27.44 (version=SSLv3 cipher=OTHER); Thu, 01 Mar 2012 15:27:44 -0800 (PST) Received: by bkcje9 with SMTP id je9so1098851bkc.15 for ; Thu, 01 Mar 2012 15:27:43 -0800 (PST) Received-SPF: pass (google.com: domain of marshall.mcmullen@gmail.com designates 10.204.154.20 as permitted sender) client-ip=10.204.154.20; Received: from mr.google.com ([10.204.154.20]) by 10.204.154.20 with SMTP id m20mr3836957bkw.90.1330644463572 (num_hops = 1); Thu, 01 Mar 2012 15:27:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-originating-ip:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=KDriaz1QQRjA6SVkMHOYD8hkXMCYrFuDgoKrv2UHiF0=; b=XPosKe7XtrKwqOcwe1MLYg2q4hpevdTlbX5xx7XC8Qtjd1Jdy6k2fEsRWL5OIu3VI4 LAIMZDUKEvMUx41uljlOXHV9O09llazTW+P10ro/Mqf5wqIJamaUcKIU2gKi/T1g1zG/ Zl7RvYb4NoQPjfkonhcBz43PtS6DFiI6Sg8YngEVo9P+jZ0zSjHIDdN54d59fCnTd3Wp R8cu5MIwS5LIX26XbslN9rY6mTff/Skh/4HPHEuT5HMuY/rgCPNf9rM/IIl9838sMnYz Fu3OV9MRugzkoLcDA1SB5TlhMfV8aiO4CsfvJ51l2iYH90JGojH6oPsPHJCuN9z1eSSK rYaw== MIME-Version: 1.0 Received: by 10.204.154.20 with SMTP id m20mr3074824bkw.90.1330644463538; Thu, 01 Mar 2012 15:27:43 -0800 (PST) Received: by 10.204.75.194 with HTTP; Thu, 1 Mar 2012 15:27:43 -0800 (PST) X-Originating-IP: [173.164.43.53] In-Reply-To: References: Date: Thu, 1 Mar 2012 23:27:43 +0000 Message-ID: Subject: Re: Create nested paths From: Marshall McMullen To: user@zookeeper.apache.org Content-Type: multipart/alternative; boundary=0015175dda1492534404ba36ce41 X-Gm-Message-State: ALoCoQm18iIRUKOVkZekVUgUolJxGvlsIDPrbfvmGosE1ZzjnNYhyObr93iRzCgVpo0wt7Xr7AhQ X-Virus-Checked: Checked by ClamAV on apache.org --0015175dda1492534404ba36ce41 Content-Type: text/plain; charset=ISO-8859-1 Yes, the results are guaranteed to be the same order of the requests. However, the first one that fails will cause the entire multi to be aborted. So, if say the first one fails, then you won't know if the others after that would have failed. I'd suggest doing something entire different, such as (pseudo-code): List ops for(path in paths) if (!Exists(path)) { ops.add(Op.Create(path)); } Does that make sense? I'm suggesting you use the non-multi code to check if it exists or not. If not, you can append any ops related to that path into your ops list. On Thu, Mar 1, 2012 at 11:14 PM, Shelley, Ryan wrote: > Right, I did this: > > (psuedo-code) > List ops > For(path in paths) > ops.add( Op.check(path, -1) ) > EndFor > > List Results = Zk.multi(ops) > > This causes an exception to be thrown on the first path that doesn't > exist. It doesn't return back a list with one OpResult flagged with an > error. I was under the impression I'd get back a bunch of OpResult objects > with flags of error, or otherwise, and then I could build another list of > operations to create what's needed (which, even if it did work, the > CheckResult object doesn't include the path, so I'm just hoping the > results are in the same order as the operations were listed in, as I have > to infer the path I'll need to build from the position of the OpResult in > the list). > > > > On 3/1/12 3:05 PM, "Ted Dunning" wrote: > > >No. I meant one call full of checks and a second call with any necessary > >creates. > > > >Sent from my iPhone > > > >On Mar 1, 2012, at 11:17 AM, "Shelley, Ryan" > >wrote: > > > >> Ok, I tried this with the Op.create and found that it will throw a > >> KeeperException on the first path that doesn't exist. It doesn't return > >> back an OpResult with an "error" type. I can still use this, and just > >> catch the exception and create the node in the exception, but I was > >>under > >> the impression that I could do this in two trips. One trip to get back a > >> list of OpResults from the check that would inform me if the path > >>existed > >> or not, and a second trip to create all the paths that don't exist (and > >>as > >> a note, the CheckResult object doesn't include the path, so I have to > >> infer it from the order of my original list of paths used to create the > >> multi-check). > >> > >> -Ryan > >> > >> On 2/29/12 7:16 PM, "Ted Dunning" wrote: > >> > >>> On Wed, Feb 29, 2012 at 7:04 PM, Marshall McMullen < > >>> marshall.mcmullen@gmail.com> wrote: > >>> > >>>> 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. > >>>> > >>> > >>> Another approach is to compose one multi with Op.exists() for each > >>>level > >>> so > >>> that you find everything you need, then create another with the correct > >>> Op.create() operations. That gets the problem down to two server > >>> round-trips but still has the race condition. > >> > > --0015175dda1492534404ba36ce41--