Revert "Add locking in common zkhander"
This reverts commit 53c0d2b4f6
.
This resulted in a massive performance hit and some inconsistent
behaviour. Revert for now an re-investigate later.
This commit is contained in:
parent
9bfcab5e2b
commit
72f47f216a
|
@ -35,33 +35,15 @@ def exists(zk_conn, key):
|
|||
|
||||
# Child list function
|
||||
def listchildren(zk_conn, key):
|
||||
try:
|
||||
children = zk_conn.get_children(key)
|
||||
return children
|
||||
except:
|
||||
return None
|
||||
|
||||
# Key deletion function
|
||||
# Delete key function
|
||||
def deletekey(zk_conn, key, recursive=True):
|
||||
lock = exclusivelock(zk_conn, key)
|
||||
lock.acquire()
|
||||
|
||||
try:
|
||||
zk_conn.delete(key, recursive=recursive)
|
||||
lock.release()
|
||||
return True
|
||||
except:
|
||||
lock.release()
|
||||
return False
|
||||
|
||||
# Rename key recursive function
|
||||
def rename_key_element(zk_conn, zk_transaction, source_key, destination_key):
|
||||
lock_source = exclusivelock(zk_conn, source_key)
|
||||
lock_source.acquire()
|
||||
|
||||
lock_destination = exclusivelock(zk_conn, destination_key)
|
||||
lock_destination.acquire()
|
||||
|
||||
data_raw = zk_conn.get(source_key)
|
||||
data = data_raw[0]
|
||||
zk_transaction.create(destination_key, data)
|
||||
|
@ -74,9 +56,6 @@ def rename_key_element(zk_conn, zk_transaction, source_key, destination_key):
|
|||
|
||||
zk_transaction.delete(source_key)
|
||||
|
||||
lock_source.release()
|
||||
lock_destination.release()
|
||||
|
||||
# Rename key function
|
||||
def renamekey(zk_conn, kv):
|
||||
# Start up a transaction
|
||||
|
@ -104,18 +83,10 @@ def renamekey(zk_conn, kv):
|
|||
|
||||
# Data read function
|
||||
def readdata(zk_conn, key):
|
||||
lock = readlock(zk_conn, key)
|
||||
lock.acquire()
|
||||
|
||||
try:
|
||||
data_raw = zk_conn.get(key)
|
||||
data = data_raw[0].decode('utf8')
|
||||
meta = data_raw[1]
|
||||
|
||||
lock.release()
|
||||
return data
|
||||
except:
|
||||
return False
|
||||
|
||||
# Data write function
|
||||
def writedata(zk_conn, kv):
|
||||
|
@ -124,9 +95,6 @@ def writedata(zk_conn, kv):
|
|||
|
||||
# Proceed one KV pair at a time
|
||||
for key in sorted(kv):
|
||||
lock = writelock(zk_conn, key)
|
||||
lock.acquire()
|
||||
|
||||
data = kv[key]
|
||||
|
||||
# Check if this key already exists or not
|
||||
|
@ -149,9 +117,7 @@ def writedata(zk_conn, kv):
|
|||
zk_transaction.check(key, new_version)
|
||||
except TypeError:
|
||||
print('Zookeeper key "{}" does not match expected version'.format(key))
|
||||
lock.release()
|
||||
return False
|
||||
lock.release()
|
||||
|
||||
# Commit the transaction
|
||||
try:
|
||||
|
@ -162,48 +128,12 @@ def writedata(zk_conn, kv):
|
|||
|
||||
# Write lock function
|
||||
def writelock(zk_conn, key):
|
||||
count = 1
|
||||
while True:
|
||||
try:
|
||||
lock_id = str(uuid.uuid1())
|
||||
lock = zk_conn.WriteLock('{}'.format(key), lock_id)
|
||||
break
|
||||
except Exception:
|
||||
count += 1
|
||||
if count > 5:
|
||||
break
|
||||
else:
|
||||
continue
|
||||
return lock
|
||||
|
||||
# Read lock function
|
||||
def readlock(zk_conn, key):
|
||||
count = 1
|
||||
while True:
|
||||
try:
|
||||
lock_id = str(uuid.uuid1())
|
||||
lock = zk_conn.ReadLock('{}'.format(key), lock_id)
|
||||
break
|
||||
except Exception:
|
||||
count += 1
|
||||
if count > 5:
|
||||
break
|
||||
else:
|
||||
continue
|
||||
return lock
|
||||
|
||||
# Exclusive lock function
|
||||
def exclusivelock(zk_conn, key):
|
||||
count = 1
|
||||
while True:
|
||||
try:
|
||||
lock_id = str(uuid.uuid1())
|
||||
lock = zk_conn.Lock('{}'.format(key), lock_id)
|
||||
break
|
||||
except Exception:
|
||||
count += 1
|
||||
if count > 5:
|
||||
break
|
||||
else:
|
||||
continue
|
||||
return lock
|
||||
|
|
Loading…
Reference in New Issue