优化加载后删除节点的逻辑;和数据库查询性能

This commit is contained in:
strepsiades
2026-04-02 19:31:04 +08:00
parent 74df53889c
commit 543c3ff906
17 changed files with 571 additions and 32 deletions
@@ -30,6 +30,25 @@ async def _resolve_local_id_for_unbind(
return None
async def _has_binding_record(
*,
node_type: str,
any_side_node_id: str,
binding_manager: "BindingManager",
) -> bool:
local_id = await _resolve_local_id_for_unbind(
node_type=node_type,
any_side_node_id=any_side_node_id,
binding_manager=binding_manager,
)
return local_id is not None
def _bootstrap_source_present(node) -> bool:
context = node.context if isinstance(node.context, dict) else {}
return not bool(context.get("_loaded_from_persistence"))
def _is_create_zombie(node) -> bool:
if node.action != SyncAction.CREATE:
return False
@@ -55,8 +74,27 @@ async def _cleanup_one_side(
)
continue
decision = e01_bootstrap(runtime, node=node, is_create_zombie=_is_create_zombie(node))
has_binding_record = await _has_binding_record(
node_type=node_type,
any_side_node_id=node.node_id,
binding_manager=binding_manager,
)
bootstrap_source_present = _bootstrap_source_present(node)
decision = e01_bootstrap(
runtime,
node=node,
is_create_zombie=_is_create_zombie(node),
bootstrap_source_present=bootstrap_source_present,
has_binding_record=has_binding_record,
)
if decision.to_state != "S15":
if decision.to_state == "S17":
node.context.pop("_loaded_from_persistence", None)
logger.warning(
f"[{node_type}] Bootstrap isolated node ({label}): "
f"node_id={node.node_id}, reason={node.error}"
)
continue
local_id_for_unbind = await _resolve_local_id_for_unbind(
@@ -74,9 +112,12 @@ async def _cleanup_one_side(
else:
bind_note = "no_binding"
reason = "status=FAILED" if node.status == SyncStatus.FAILED else "data_id empty"
if _is_create_zombie(node):
reason = "status=FAILED" if node.status == SyncStatus.FAILED else "data_id empty"
else:
reason = "persistence_only_source_missing_without_binding"
logger.info(
f"[{node_type}] Cleaning up CREATE zombie ({label}): "
f"[{node_type}] Cleaning up bootstrap zombie ({label}): "
f"node_id={node.node_id}, reason={reason}, {bind_note}"
)
@@ -118,7 +159,7 @@ async def run_phase2_cleanup(
total_cleaned += cleaned_count
if cleaned_count > 0:
logger.warning(
f"[{node_type}] Cleaned up CREATE-failed zombies: "
f"[{node_type}] Cleaned up bootstrap zombies: "
f"local_deleted={len(cleaned_local)}, remote_deleted={len(cleaned_remote)}"
)