Improve thread safety for relationship rebuilding

- Sort src and tgt for consistent lock keys
- Maintain order-independent locking
This commit is contained in:
yangdx 2025-07-19 10:25:48 +08:00
parent 05bc5cfb64
commit 6e1657a771

View file

@ -429,8 +429,12 @@ async def _rebuild_knowledge_from_chunks(
async with semaphore:
workspace = global_config.get("workspace", "")
namespace = f"{workspace}:GraphDB" if workspace else "GraphDB"
# Sort src and tgt to ensure order-independent lock key generation
sorted_key_parts = sorted([src, tgt])
async with get_storage_keyed_lock(
f"{src}-{tgt}", namespace=namespace, enable_logging=False
f"{sorted_key_parts[0]}-{sorted_key_parts[1]}",
namespace=namespace,
enable_logging=False,
):
try:
await _rebuild_single_relationship(