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 EF7EF1743A for ; Fri, 24 Oct 2014 13:33:55 +0000 (UTC) Received: (qmail 81752 invoked by uid 500); 24 Oct 2014 13:33:55 -0000 Delivered-To: apmail-zookeeper-user-archive@zookeeper.apache.org Received: (qmail 81704 invoked by uid 500); 24 Oct 2014 13:33:55 -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 81693 invoked by uid 99); 24 Oct 2014 13:33:54 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Oct 2014 13:33:54 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of Dejan.Markic@mobik-ics.com designates 213.142.225.16 as permitted sender) Received: from [213.142.225.16] (HELO ALICE.main.mobik.si) (213.142.225.16) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Oct 2014 13:33:49 +0000 From: Dejan Markic To: "user@zookeeper.apache.org" Subject: New ZooKeeper user and C API question Thread-Topic: New ZooKeeper user and C API question Thread-Index: Ac/vis+UF1MIgdXmSsugO0P/tYRhcg== Date: Fri, 24 Oct 2014 13:33:27 +0000 Message-ID: <1458C6B4EF2B37428F20085D75DD94DB0178C43439@MARY.main.mobik.si> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [192.168.9.233] x-esetresult: clean, is OK x-esetid: C6A47E238B56557E93E727 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Virus-Checked: Checked by ClamAV on apache.org Hello all! I'm fairly new to ZooKeeper, been testing it now for a few days and I have = one question (hopefuly simple). I've implemented exclusive lock recipe and it seems to be working. So to te= st it, I made a counter application. Using simple mechanism: - get_xlock(myLock) - get_node_value(counter) - increment counter by 1 - set_node_value(counter) - free_xlock Program is linked with zookeeper_mt library, zookeeper version: zookeeper.v= ersion=3D3.4.6-1569965, built on 02/20/2014 09:09 GMT built on Debian 7.7. I run this application two times, each incrementing counter 1000 times. So,= if everything is OK (no timeouts etc), the final value should be 2000. Ins= tead, it comes out like something in 300-400. But final version is 2000. I may not understand ZooKeeper underhood, but ... I see that version of the "counter" node is increasing correctly. But the v= alue is not. How come? Do I need to call any function so that it will wait = for the value to get written to the node?! This is the node after both counter applications finished:=20 --- [zk: localhost:2181(CONNECTED) 0] get /test/MyLock/counter 386 cZxid =3D 0xa ctime =3D Fri Oct 24 14:53:46 CEST 2014 mZxid =3D 0x177d mtime =3D Fri Oct 24 14:54:14 CEST 2014 pZxid =3D 0xa cversion =3D 0 dataVersion =3D 2000 aclVersion =3D 0 ephemeralOwner =3D 0x0 dataLength =3D 3 numChildren =3D 0 --- Any hints on what's going on? Thank you and kind regards, Dejan Markic ADDITIONAL INFORMATION (TL;DR) Here's a little snippet from my simple logging of what's going on in two pa= rallel running counter applications: #1: App#1 is running alone, incrementing the counter to 246, version 246 #1.1: App#1 is trying to obtain lock #1.2: App#2 successfuly obtained the lock #2.1: App#2 Reads the value counter=3D246, version=3D246. Increments the va= lue and writes it. It's expected to be: counter=3D247 version=3D247 #2.2: App#1 Obtains the lock #3.1: App#1 Reads the counter node value and ... counter=3D246, version=3D2= 47 !??! ... the rest is history ... Output snippets: ---- ... [1414155244.397642]: [244]: bzk_xlock [1414155244.400405]: [244]: Lock obtained [1414155244.400801]: [244]: Counter node value: 244 version: 244 [1414155244.400807]: [244]: Counter node value increased: 245 [1414155244.401794]: [244]: Counter value set successfuly: 245 [1414155244.403844]: [244]: bzk_xunlock [1414155244.403863]: [245]: bzk_xlock [1414155244.411246]: [245]: Lock obtained [1414155244.411938]: [245]: Counter node value: 245 version: 245 [1414155244.411944]: [245]: Counter node value increased: 246 [1414155244.414031]: [245]: Counter value set successfuly: 246 [1414155244.415146]: [245]: bzk_xunlock [1414155244.415150]: [246]: bzk_xlock =