From e148618d18a29a90032c017960244d32b9a9dc8b Mon Sep 17 00:00:00 2001 From: Mic Bowman Date: Fri, 1 Nov 2024 11:43:34 -0600 Subject: [PATCH] Add a lock around the block manager and key value start Signed-off-by: Mic Bowman --- python/pdo/common/block_store_manager.py | 6 ++++++ python/pdo/common/key_value.py | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/python/pdo/common/block_store_manager.py b/python/pdo/common/block_store_manager.py index c705edb9..8865fa66 100644 --- a/python/pdo/common/block_store_manager.py +++ b/python/pdo/common/block_store_manager.py @@ -33,14 +33,20 @@ # XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX # XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +import threading +__block_manager_lock__ = threading.Lock() __local_block_manager__ = None def local_block_manager() : global __local_block_manager__ + + __block_manager_lock__.acquire() if __local_block_manager__ is None : block_store_file = pconfig.shared_configuration(['StorageService','BlockStore'], "./blockstore.mdb") __local_block_manager__ = BlockStoreManager(block_store_file, True) + __block_manager_lock__.release() + return __local_block_manager__ # XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX diff --git a/python/pdo/common/key_value.py b/python/pdo/common/key_value.py index 6d4787cf..b556a14e 100644 --- a/python/pdo/common/key_value.py +++ b/python/pdo/common/key_value.py @@ -25,12 +25,19 @@ import logging logger = logging.getLogger(__name__) +# XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +# XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +import threading +__block_store_lock__ = threading.Lock() __block_store_initialized__ = False # ----------------------------------------------------------------- # ----------------------------------------------------------------- def KeyValueInitialize(block_store_file = None) : global __block_store_initialized__ + + __block_store_lock__.acquire() + if __block_store_initialized__ : raise Exception("duplicate block store initialization") @@ -41,6 +48,8 @@ def KeyValueInitialize(block_store_file = None) : kvs.block_store_open(block_store_file) __block_store_initialized__ = True + __block_store_lock__.release() + # ----------------------------------------------------------------- # ----------------------------------------------------------------- def KeyValueTerminate() :