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

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
@@ -256,6 +256,12 @@ class FullSyncPipeline:
self._prepare_datasources()
self._logger.info("✅ Bootstrap: datasource prepared")
await self._bootstrap_refresh_latest_data()
self._logger.info("✅ Bootstrap: datasource refresh completed")
await self._run_bootstrap_reset_cleanup()
self._logger.info("✅ Bootstrap: reset cleanup completed")
await self._apply_project_scope_cleanup()
async def phase_bind(self) -> None:
@@ -359,7 +365,7 @@ class FullSyncPipeline:
await _safe_close("persistence", self.persistence.close())
async def _load_persistence_state(self) -> None:
"""加载持久化数据并清理僵尸节点"""
"""加载持久化数据到内存,等待 bootstrap datasource refresh 与 E01 cleanup。"""
if not self.enable_persistence:
return
@@ -376,10 +382,50 @@ class FullSyncPipeline:
for node_type in binding_node_types:
await self.binding_manager.load_from_persistence(node_type)
self._logger.info("🔄 Persistence loaded (state preserved; pending E01 normalization)")
# 加载后 reset 清理:清理 CREATE 失败的僵尸绑定
def _resolve_bootstrap_refresh_node_types(self) -> List[str]:
local_types = {node.node_type for node in self.local_collection.filter()}
remote_types = {node.node_type for node in self.remote_collection.filter()}
candidate_types = local_types | remote_types
if not candidate_types:
return []
ordered: List[str] = []
for node_type in [*self.load_order, *self.bootstrap_binding_node_types, *sorted(candidate_types)]:
if node_type in candidate_types and node_type not in ordered:
ordered.append(node_type)
return ordered
async def _bootstrap_refresh_latest_data(self) -> None:
if not self.enable_persistence:
return
node_types = self._resolve_bootstrap_refresh_node_types()
if not node_types:
self._logger.info("⏭️ Bootstrap datasource refresh skipped: no persisted node types")
return
for node_type in node_types:
self._logger.info("🔄 Bootstrap refresh node_type=%s from datasource", node_type)
await self._load_node_type_from_datasource(
self.local_datasource,
datasource_role="local",
node_type=node_type,
reason="bootstrap persistence refresh",
)
await self._load_node_type_from_datasource(
self.remote_datasource,
datasource_role="remote",
node_type=node_type,
reason="bootstrap persistence refresh",
)
async def _run_bootstrap_reset_cleanup(self) -> None:
if not self.enable_persistence:
return
if not self.strategies:
raise RuntimeError("no strategies configured: cannot run bootstrap event E01")
total_cleaned = await run_phase2_cleanup(
node_types=self.node_types,
local_collection=self.local_collection,
@@ -388,8 +434,7 @@ class FullSyncPipeline:
runtime=self.sm_runtime,
)
if total_cleaned > 0:
self._logger.info(f"🧹 Reset cleanup: {total_cleaned} CREATE-failed zombies cleaned")
self._logger.info("🔄 Post-load reset cleanup completed")
self._logger.info(f"🧹 Reset cleanup: {total_cleaned} bootstrap zombies cleaned")
async def _apply_preloaded_state(self) -> None:
if self._preloaded_local_nodes: