Skip to content

Commit

Permalink
Add a lock around the block manager and key value start
Browse files Browse the repository at this point in the history
Signed-off-by: Mic Bowman <[email protected]>
  • Loading branch information
cmickeyb committed Nov 6, 2024
1 parent 5e487ce commit 4f44384
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions python/pdo/common/block_store_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions python/pdo/common/key_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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() :
Expand Down

0 comments on commit 4f44384

Please sign in to comment.