Return-Path: Delivered-To: apmail-hadoop-zookeeper-user-archive@minotaur.apache.org Received: (qmail 70685 invoked from network); 1 Feb 2010 10:22:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 1 Feb 2010 10:22:16 -0000 Received: (qmail 63821 invoked by uid 500); 1 Feb 2010 10:22:16 -0000 Delivered-To: apmail-hadoop-zookeeper-user-archive@hadoop.apache.org Received: (qmail 63772 invoked by uid 500); 1 Feb 2010 10:22:15 -0000 Mailing-List: contact zookeeper-user-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: zookeeper-user@hadoop.apache.org Delivered-To: mailing list zookeeper-user@hadoop.apache.org Received: (qmail 63760 invoked by uid 99); 1 Feb 2010 10:22:14 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Feb 2010 10:22:14 +0000 X-ASF-Spam-Status: No, hits=-1.0 required=10.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [66.111.4.26] (HELO out2.smtp.messagingengine.com) (66.111.4.26) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Feb 2010 10:22:04 +0000 Received: from compute2.internal (compute2.internal [10.202.2.42]) by gateway1.messagingengine.com (Postfix) with ESMTP id 3F3DDCF7F2 for ; Mon, 1 Feb 2010 05:21:43 -0500 (EST) Received: from heartbeat1.messagingengine.com ([10.202.2.160]) by compute2.internal (MEProxy); Mon, 01 Feb 2010 05:21:43 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=messagingengine.com; h=message-id:date:from:mime-version:to:subject:references:in-reply-to:content-type:content-transfer-encoding; s=smtpout; bh=ePM+9icQNw7Rp8F8q29aI0vJwKc=; b=o8qmNq5AFIlEWJP8asvXHXJixoQLsdS0ZsRcE0cDpN8DiM/4fvfGVekFwf80G4X2e+Wzvkzt3TG7ZzZ4DM3UTm4/wn7SmgeUgndD6OtTVrNSMOhbsgavnVkWwC71Xdhaw+S8v83oczFwBgGCnh7P6eVhRTZHr0ExCyoGLUBGRg0= X-Sasl-enc: mFQB+RdO9zCtEImHJySBop/wPDqCsOGcaYyh1oQr+orD 1265019702 Received: from [192.168.123.210] (unknown [86.43.104.130]) by mail.messagingengine.com (Postfix) with ESMTPSA id AC0474CAA54 for ; Mon, 1 Feb 2010 05:21:42 -0500 (EST) Message-ID: <4B66AB35.9090506@boboco.ie> Date: Mon, 01 Feb 2010 10:21:41 +0000 From: Eric Bowman User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.5) Gecko/20100103 Thunderbird/3.0 MIME-Version: 1.0 To: zookeeper-user@hadoop.apache.org Subject: Re: how to handle re-add watch fails References: <4B5D971B.4070201@boboco.ie> In-Reply-To: <4B5D971B.4070201@boboco.ie> X-Enigmail-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org I was surprised to not get a response to this ... is this a no-brainer? Too hard to solve? Did I not express it clearly? Am I doing something dumb? :) Thanks, Eric On 01/25/2010 01:05 PM, Eric Bowman wrote: > I'm curious, what is the "best practice" for how to handle the case > where re-adding a watch inside a Watcher.process callback fails? > > I keep stumbling upon the same kind of thing, and the possibility of > race conditions or undefined behavior keep troubling me. Maybe I'm > missing something. > > Suppose I have a callback like: > > public void process( WatchedEvent watchedEvent ) > { > if ( watchedEvent.getType() == > Event.EventType.NodeChildrenChanged ) { > try { > ... do stuff ... > } > catch ( Throwable e ) { > log.error( "Could not do stuff!", e ); > } > try { > zooKeeperManager.watchChildren( zPath, this ); > } > catch ( InterruptedException e ) { > log.info( "Interrupted adding watch -- shutting down?" ); > return; > } > catch ( KeeperException e ) { > // oh crap, now what? > } > } > } > > (In this cases, watchChildren is just calling getChildren and passing > the watcher in.) > > It occurs to me I could get more and more complicated here: I could > wrap watchChildren in a while loop until it succeeds, but that seems > kind of rude to the caller. Plus what if I get a > KeeperException.SessionExpiredException or a > KeeperException.ConnectionLossException? How to handle that in this > loop? Or I could send some other thread a message that it needs to keep > trying until the watch has been re-added ... but ... yuck. > > I would very much like to just setup this watch once, and have ZooKeeper > make sure it keeps firing until I tear down ZooKeeper -- this logic > seems tricky for clients, and quite error prone and full of race conditions. > > Any thoughts? > > Thanks, > Eric > > -- Eric Bowman Boboco Ltd ebowman@boboco.ie http://www.boboco.ie/ebowman/pubkey.pgp +35318394189/+353872801532