LISTSERV mailing list manager LISTSERV 16.5

Help for QSERV-L Archives


QSERV-L Archives

QSERV-L Archives


QSERV-L@LISTSERV.SLAC.STANFORD.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

QSERV-L Home

QSERV-L Home

QSERV-L  May 2014

QSERV-L May 2014

Subject:

concurrency in zookeeper

From:

Jacek Becla <[log in to unmask]>

Reply-To:

General discussion for qserv (LSST prototype baseline catalog)

Date:

Tue, 13 May 2014 21:25:46 -0700

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (96 lines)

Serge at al,

I am trying to implement code to avoid race conditions in zookeeper.
I figured I'd create an ephemeral node "/LOCKS/<dbName>" and proceed
with sensitive things only after creating such node successfully.
However, I have the impression zookeeper will allow multiple jobs
to create the same node, even in synchronous mode. Here is a test
I'm using (see below), if I run it concurrently (just two instances),
I'm typically seeing a collision (pasted below).

Can you have a look, think about it, and let's discuss tomorrow.
Thanks!


===================================

import os
import socket
import time
from random import randint


from kazoo.client import KazooClient
from kazoo.exceptions import NodeExistsError, NoNodeError

def sleepABit():
     v = randint(1,100) / 1000.0
     print "sleep ", v
     time.sleep(v)


def createIt(zk, k, v):
     while True:
         try:
             print "create ", v
             zk.create(k, v, ephemeral=True, makepath=True)
         except:
             print "create failed"
             sleepABit()
         finally:
             print "create ok"
             return


k = "/LOCKS/x"
zk = KazooClient(hosts="127.0.0.1:12181")
zk.start()

for i in range(0,100):
     v = str(socket.gethostbyname(socket.gethostname())) + '_' + 
str(os.getpid()) + '_' + str(i)

     createIt(zk, k, v)

     sleepABit()

     d, s = zk.get(k)
     print "got ", d

     print "delete"
     zk.delete(k)

     print "---"


=====================

create  141.142.225.179_8831_29
create ok
sleep  0.04
got  141.142.225.179_8839_16
delete
Traceback (most recent call last):
   File "quickTest.py", line 45, in <module>
     zk.delete(k)
   File 
"/usr/local/home/becla/qserv/1/stack/Linux64/kazoo/1.3.1/lib/python/kazoo-1.3.1-py2.6.egg/kazoo/client.py", 
line 1159, in delete
     return self.delete_async(path, version).get()
   File 
"/usr/local/home/becla/qserv/1/stack/Linux64/kazoo/1.3.1/lib/python/kazoo-1.3.1-py2.6.egg/kazoo/handlers/threading.py", 
line 107, in get
     raise self._exception
kazoo.exceptions.NoNodeError: ((), {})


See? the node has pid 8831 and successfully created the node,
but the other job (pid 8839) managed to create it OK as well
before job with pid 8831 deleted it.

########################################################################
Use REPLY-ALL to reply to list

To unsubscribe from the QSERV-L list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=QSERV-L&A=1

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

March 2018
February 2018
January 2018
December 2017
August 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
December 2012

ATOM RSS1 RSS2



LISTSERV.SLAC.STANFORD.EDU

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager

Privacy Notice, Security Notice and Terms of Use