mirror of
https://github.com/HKUDS/LightRAG.git
synced 2025-12-13 15:57:29 +00:00
fix: move node existence check inside lock to prevent race condition
Move knowledge_graph_inst.has_node check inside get_storage_keyed_lock in _merge_edges_then_upsert to ensure atomic check-then-act operations and prevent duplicate node creation during concurrent updates.
This commit is contained in:
parent
2ade3067f8
commit
a85d7054d4
@ -1016,25 +1016,12 @@ async def _merge_edges_then_upsert(
|
|||||||
)
|
)
|
||||||
|
|
||||||
for need_insert_id in [src_id, tgt_id]:
|
for need_insert_id in [src_id, tgt_id]:
|
||||||
if await knowledge_graph_inst.has_node(need_insert_id):
|
|
||||||
# This is so that the initial check for the existence of the node need not be locked
|
|
||||||
continue
|
|
||||||
workspace = global_config.get("workspace", "")
|
workspace = global_config.get("workspace", "")
|
||||||
namespace = f"{workspace}:GraphDB" if workspace else "GraphDB"
|
namespace = f"{workspace}:GraphDB" if workspace else "GraphDB"
|
||||||
async with get_storage_keyed_lock(
|
async with get_storage_keyed_lock(
|
||||||
[need_insert_id], namespace=namespace, enable_logging=False
|
[need_insert_id], namespace=namespace, enable_logging=False
|
||||||
):
|
):
|
||||||
if not (await knowledge_graph_inst.has_node(need_insert_id)):
|
if not (await knowledge_graph_inst.has_node(need_insert_id)):
|
||||||
# # Discard this edge if the node does not exist
|
|
||||||
# if need_insert_id == src_id:
|
|
||||||
# logger.warning(
|
|
||||||
# f"Discard edge: {src_id} - {tgt_id} | Source node missing"
|
|
||||||
# )
|
|
||||||
# else:
|
|
||||||
# logger.warning(
|
|
||||||
# f"Discard edge: {src_id} - {tgt_id} | Target node missing"
|
|
||||||
# )
|
|
||||||
# return None
|
|
||||||
await knowledge_graph_inst.upsert_node(
|
await knowledge_graph_inst.upsert_node(
|
||||||
need_insert_id,
|
need_insert_id,
|
||||||
node_data={
|
node_data={
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user