From 72f47f216aeee4fadb4df5210b2ec141dabbc21c Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Wed, 21 Oct 2020 03:49:13 -0400 Subject: [PATCH] Revert "Add locking in common zkhander" This reverts commit 53c0d2b4f620e10f3e0e6b0f19495d8473792563. This resulted in a massive performance hit and some inconsistent behaviour. Revert for now an re-investigate later. --- daemon-common/zkhandler.py | 94 +++++--------------------------------- 1 file changed, 12 insertions(+), 82 deletions(-) diff --git a/daemon-common/zkhandler.py b/daemon-common/zkhandler.py index 1c853c2c..1649c3b9 100644 --- a/daemon-common/zkhandler.py +++ b/daemon-common/zkhandler.py @@ -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 + children = zk_conn.get_children(key) + return children -# 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 + zk_conn.delete(key, recursive=recursive) # 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_raw = zk_conn.get(key) + data = data_raw[0].decode('utf8') + meta = data_raw[1] + return data # 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 + lock_id = str(uuid.uuid1()) + lock = zk_conn.WriteLock('{}'.format(key), lock_id) 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 + lock_id = str(uuid.uuid1()) + lock = zk_conn.ReadLock('{}'.format(key), lock_id) return lock