Fix async issues in namespace init

This commit is contained in:
yangdx
2025-03-09 15:22:06 +08:00
parent 6a969e8de4
commit 90527875fd
3 changed files with 12 additions and 10 deletions

View File

@@ -355,7 +355,7 @@ async def get_all_update_flags_status() -> Dict[str, list]:
return result
def try_initialize_namespace(namespace: str) -> bool:
async def try_initialize_namespace(namespace: str) -> bool:
"""
Returns True if the current worker(process) gets initialization permission for loading data later.
The worker does not get the permission is prohibited to load data from files.
@@ -365,15 +365,17 @@ def try_initialize_namespace(namespace: str) -> bool:
if _init_flags is None:
raise ValueError("Try to create nanmespace before Shared-Data is initialized")
if namespace not in _init_flags:
_init_flags[namespace] = True
async with get_internal_lock():
if namespace not in _init_flags:
_init_flags[namespace] = True
direct_log(
f"Process {os.getpid()} ready to initialize storage namespace: [{namespace}]"
)
return True
direct_log(
f"Process {os.getpid()} ready to initialize storage namespace: [{namespace}]"
f"Process {os.getpid()} storage namespace already initialized: [{namespace}]"
)
return True
direct_log(
f"Process {os.getpid()} storage namespace already initialized: [{namespace}]"
)
return False