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 D7DAE1853C for ; Mon, 27 Jul 2015 18:25:32 +0000 (UTC) Received: (qmail 61653 invoked by uid 500); 27 Jul 2015 18:25:31 -0000 Delivered-To: apmail-zookeeper-user-archive@zookeeper.apache.org Received: (qmail 61599 invoked by uid 500); 27 Jul 2015 18:25:31 -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 61588 invoked by uid 99); 27 Jul 2015 18:25:31 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Jul 2015 18:25:31 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 2CF0C1911E2 for ; Mon, 27 Jul 2015 18:25:31 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.99 X-Spam-Level: ** X-Spam-Status: No, score=2.99 tagged_above=-999 required=6.31 tests=[HTML_MESSAGE=3, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id J2emuHkoUonu for ; Mon, 27 Jul 2015 18:25:17 +0000 (UTC) Received: from e35.co.us.ibm.com (e35.co.us.ibm.com [32.97.110.153]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with ESMTPS id EE26543CD4 for ; Mon, 27 Jul 2015 18:25:16 +0000 (UTC) Received: from /spool/local by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 27 Jul 2015 12:25:16 -0600 Received: from d03dlp03.boulder.ibm.com (9.17.202.179) by e35.co.us.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 27 Jul 2015 12:25:13 -0600 X-Helo: d03dlp03.boulder.ibm.com X-MailFrom: barlock@us.ibm.com X-RcptTo: user@zookeeper.apache.org Received: from b03cxnp08028.gho.boulder.ibm.com (b03cxnp08028.gho.boulder.ibm.com [9.17.130.20]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id AAB2219D803F for ; Mon, 27 Jul 2015 12:16:11 -0600 (MDT) Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t6RIOON041615556 for ; Mon, 27 Jul 2015 11:24:24 -0700 Received: from d03av04.boulder.ibm.com (loopback [127.0.0.1]) by d03av04.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t6RIPC5m028356 for ; Mon, 27 Jul 2015 12:25:12 -0600 Received: from d03nm119.boulder.ibm.com (d03nm119.boulder.ibm.com [9.63.40.225]) by d03av04.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t6RIPClw028353 for ; Mon, 27 Jul 2015 12:25:12 -0600 In-Reply-To: References: To: user@zookeeper.apache.org MIME-Version: 1.0 Subject: Re: ZooKeeper Class Will Not Connect X-KeepSent: E60B683C:016AEEE2-85257E8F:0064CB79; type=4; name=$KeepSent X-Mailer: IBM Notes Release 9.0.1FP2 SHF37 August 25, 2014 From: Chris Barlock Message-ID: Date: Mon, 27 Jul 2015 14:25:10 -0400 X-MIMETrack: Serialize by Router on D03NM119/03/M/IBM(Release 9.0.1FP3HF144 | February 25, 2015) at 07/27/2015 12:25:12, Serialize complete at 07/27/2015 12:25:12 Content-Type: multipart/alternative; boundary="=_alternative 0065254B85257E8F_=" X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15072718-0013-0000-0000-000015555259 --=_alternative 0065254B85257E8F_= Content-Type: text/plain; charset="US-ASCII" Chris: Your sample code works for me and I should be able to adapt it, but I still think there is a bug. I made the following change to your sample to test my method: private Main(String hostPort) throws Exception { this.connectLatch = new CountDownLatch(1); waitTime = System.currentTimeMillis(); this.zk = new ZooKeeper(hostPort, 3000, this); States state = zk.getState(); while (state != States.CONNECTED) { System.out.println("State " + state); try { Thread.sleep(100); } catch (InterruptedException e) { System.out.println("Interrupted!"); } } } This outputs: State CONNECTING Received event: WatchedEvent state:SyncConnected type:None path:null State CONNECTING State CONNECTING ... and zk.getState never returns anything but CONNECTING. It seems that this started with ZK 3.4.3 as 3.4.2 works for me, but 3.4.3, 4, 5 and 6 all have this behavior in which the state is always CONNECTING. Chris From: Chris Nauroth To: "user@zookeeper.apache.org" Date: 07/24/2015 07:28 PM Subject: Re: ZooKeeper Class Will Not Connect ZooKeeper writes INFO-level logging about connection and session establishment. On the client side, these messages would come from the ZooKeeper and ClientCnxn classes. On the server side, these messages would come from the ZooKeeperServer, NIOServerCnxn and NettyServerCnxn classes. It's possible that you could get more detail by turning up to DEBUG level logging by adding these lines to log4j.properties for the client and server respectively: log4j.logger.org.apache.zookeeper=DEBUG log4j.logger.org.apache.zookeeper.server=DEBUG --Chris Nauroth On 7/24/15, 3:42 PM, "Chris Barlock" wrote: >Chris: > >I have defined: > > private static final int MAX_ZK_CONNECT_ATTEMPTS = 400; > > private static final long ZK_CONNECT_WAIT = 5; // Milliseconds > >so, two seconds, but I have also tried with ZK_CONNECT_WAIT = 500 (two >hundred seconds). getState always returned CONNECTING. I can play with >the async notification, but it really doesn't fit my application very >well. Is there any additional server or client tracing that can be >enabled to get a better sense of what is going on? > >Chris > >IBM Tivoli Systems >Research Triangle Park, NC >(919) 224-2240 >Internet: barlock@us.ibm.com > > > >From: Chris Nauroth >To: "user@zookeeper.apache.org" >Date: 07/24/2015 06:19 PM >Subject: Re: ZooKeeper Class Will Not Connect > > > >Hello Chris, > >Thank you for the detailed repro steps describing which versions work and >which versions don't work. I tested your code sample against a 3.4.6 >build, and it worked consistently for me. My only thought is that perhaps >the MAX_ZK_CONNECT_ATTEMPTS and ZK_CONNECT_WAIT constants are set such >that the polling loop exits before the connection completes. Perhaps a >subtle timing difference in the newer versions is just now exposing this. > >The typical pattern for connection establishment is to rely on the >ZooKeeper client's asynchronous event notification instead of a polling >loop. See below for a code sample that initiates the connection and then >waits for the SyncConnected event. The ZooKeeper programmer's guide and >example program docs have a more detailed discussion of this. > >http://zookeeper.apache.org/doc/r3.4.6/zookeeperProgrammers.html > > >http://zookeeper.apache.org/doc/r3.4.6/javaExample.html > > >Could you please try running this against your 3.4.6 cluster? I'd be >curious to see if the connection completes for you. This would also give >you a sense for how long connection establishment is taking and whether or >not that's in line with your definitions of MAX_ZK_CONNECT_ATTEMPTS and >ZK_CONNECT_WAIT. > >I hope this helps. > > > >class Main implements Watcher { > > private final CountDownLatch connectLatch; > private final ZooKeeper zk; > > public static void main(final String[] args) throws Exception { > String hostPort = args[0]; > Main main = new Main(hostPort); > main.awaitConnection(); > System.out.println("Exiting."); > } > > private Main(String hostPort) throws Exception { > this.connectLatch = new CountDownLatch(1); > this.zk = new ZooKeeper(hostPort, 3000, this); > } > > private void awaitConnection() throws InterruptedException { > this.connectLatch.await(); > System.out.println("Connection has completed."); > } > > @Override > public void process(WatchedEvent event) { > System.out.println("Received event: " + event); > if (event.getType() == Event.EventType.None) { > switch (event.getState()) { > case SyncConnected: > this.connectLatch.countDown(); > break; > } > } > } >} > > >--Chris Nauroth > > > > >On 7/24/15, 9:16 AM, "Chris Barlock" wrote: > >>Ran some more tests. My code works fine up through ZK 3.4.2, but then >>fails with 3.4.3. I did have to add the following to the Import-Package >>list in the ZK MANIFEST.MF: >> >>org.slf4 j,javax.security.auth.login,javax.security.sasl >> >>I could really use some help here, ZK folks! Is my code incorrect with >>newer versions of ZK, or is ZK broken? >> >>Chris >> >> >> >> >> >>From: Chris Barlock/Raleigh/IBM@IBMUS >>To: user@zookeeper.apache.org >>Date: 07/23/2015 09:34 PM >>Subject: Re: ZooKeeper Class Will Not Connect >> >> >> >>I tried the 3.5.0 alpha build to see if it made any difference. It did >>not. >> >>But, I had to hack the MANIFEST.MF file in the JAR because the >>"3.50-alpha" version fails tests in OSGi bundles that import the ZK >>classes which have something like: >> >>version="[3.2,4)" >> >>I suggest that if you want to name the JAR "3.50-alpha" that all the >>internals just use a version of 3.50. >> >>Chris >> >>IBM Tivoli Systems >>Research Triangle Park, NC >>(919) 224-2240 >>Internet: barlock@us.ibm.com >> >> >> >>From: Chris Barlock/Raleigh/IBM@IBMUS >>To: user@zookeeper.apache.org >>Date: 07/23/2015 01:37 PM >>Subject: ZooKeeper Class Will Not Connect >> >> >> >>We are attempting to upgrade from Kafka 0.8.0, which includes ZK 3.3.4 to >>Kafka 0.8.2.1 with ZK 3.4.6. My code which attempts to connect to ZK is >>pretty straightforward: >> >> try { >> ZooKeeper zk = new ZooKeeper(connectString, >sessionTimeout >>, this); >> int connectAttempts = 0; >> >> while (!zk.getState().isConnected() && connectAttempts < >>MAX_ZK_CONNECT_ATTEMPTS) { >> try { >> Thread.sleep(ZK_CONNECT_WAIT); >> } catch (InterruptedException e) { >> // Ignore >> } >> connectAttempts++; >> } >> } catch (IOException e) { >> trace.exception(CLASS_NAME, methodName, e); >> } >> >>With some additional tracing, States is always CONNECTING. Has something >>changed with 3.4.6 about how I should connect to the server? I can >>connect just fine with the zookeeper-shell.sh that Kafka ships. This >>code >> >> >>always runs on the same system as ZK, so the connectString is always >>"localhost:2181" >> >>Chris >> > > --=_alternative 0065254B85257E8F_=--