更新 端到端主流程.md
This commit is contained in:
parent
4255abeb66
commit
301356b6e2
165
端到端主流程.md
165
端到端主流程.md
@ -1,3 +1,20 @@
|
|||||||
|
# PRDv5 全流程时序图(严格依据 v5 文档与引用约束)
|
||||||
|
|
||||||
|
说明:
|
||||||
|
- 本文仅使用 PRDv5 中明确存在的对象、状态与动作;不引入任何未在文档出现的状态或动作。
|
||||||
|
- 对象与状态集合(摘自 PRD):
|
||||||
|
- Task.status ∈ {created, running, finished, failed, revoking, revoked}
|
||||||
|
- Mention.status ∈ {active, invalid}
|
||||||
|
- Candidate.status ∈ {pending, locked, orphaned}
|
||||||
|
- Confirm.status ∈ {CONFIRMED, PUBLISHED, ROLLED_BACK}
|
||||||
|
- sync_status ∈ {PENDING, SYNCING, SYNCED, FAILED}
|
||||||
|
- 统一过滤约束:revoking / revoked 的查询/内部消费需执行过滤(参见 2.11)。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## A. 端到端主流程(创建任务 → 回调写入 → 生成候选 → 审核确认 → 发布 → 图投影)
|
||||||
|
|
||||||
|
```mermaid
|
||||||
sequenceDiagram
|
sequenceDiagram
|
||||||
autonumber
|
autonumber
|
||||||
actor Admin as Admin(管理员)
|
actor Admin as Admin(管理员)
|
||||||
@ -65,3 +82,151 @@ else status=ROLLED_BACK
|
|||||||
end
|
end
|
||||||
SyncW->>PG_Conf: 写回 sync_status='SYNCED' 或 'FAILED'
|
SyncW->>PG_Conf: 写回 sync_status='SYNCED' 或 'FAILED'
|
||||||
SyncW->>Audit: 写审计(action='sync',记录结果)
|
SyncW->>Audit: 写审计(action='sync',记录结果)
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## B. 回滚全过程(任务 → Mention → Candidate → Confirm → 投影清理)
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
sequenceDiagram
|
||||||
|
autonumber
|
||||||
|
actor Admin as Admin(管理员)
|
||||||
|
participant UI as 前端UI
|
||||||
|
participant API as 后端API(服务)
|
||||||
|
participant PG_Task as PostgreSQL(kg_task)
|
||||||
|
participant PG_M as PostgreSQL(kg_*_mention)
|
||||||
|
participant PG_Cand as PostgreSQL(kg_*_candidate)
|
||||||
|
participant PG_Conf as PostgreSQL(kg_*_confirm)
|
||||||
|
participant Audit as PostgreSQL(audit_log)
|
||||||
|
participant SyncW as 同步Worker
|
||||||
|
participant Neo4j as Neo4j(投影)
|
||||||
|
|
||||||
|
Note over Admin,PG_Task: 回滚触发(6.2)
|
||||||
|
Admin->>UI: 发起回滚(rollback)
|
||||||
|
UI->>API: POST /api/rollback?task_id=...(影响预估/阻断策略)
|
||||||
|
API->>PG_Task: 事务首步将task.status置为revoking(强中间态,可见)
|
||||||
|
API->>Audit: 写审计(rollback 受理)
|
||||||
|
|
||||||
|
Note over API,PG_M: 生命周期与可见性(2.11 / 3.2.4)
|
||||||
|
API->>PG_M: 与该task关联的mentions在查询/下游消费中被过滤\n(revoking/revoked 全局过滤契约)
|
||||||
|
API-->>UI: Candidate/图谱界面呈现“回撤处理中,只读提示”
|
||||||
|
|
||||||
|
Note over API,PG_Conf: Confirm 源集合更新(3.4 / 6.2)
|
||||||
|
API->>PG_Conf: 从source_tasks中移除该task_id;若为空→active_flag=false\n必要时关系随实体失活(按3.7.5约束)
|
||||||
|
API->>PG_Conf: 统一置 sync_status='PENDING'(脏标记)
|
||||||
|
API->>Audit: 写审计(rollback 细节)
|
||||||
|
|
||||||
|
Note over API,PG_Task: 任务完成回撤
|
||||||
|
API->>PG_Task: 将task.status置为revoked(终态)
|
||||||
|
API-->>UI: 返回回滚完成
|
||||||
|
|
||||||
|
Note over SyncW,Neo4j: 投影清理(4.3)
|
||||||
|
SyncW->>PG_Conf: 扫描 sync_status IN ('PENDING','FAILED')
|
||||||
|
SyncW->>PG_Conf: 原子置 SYNCING
|
||||||
|
alt status=ROLLED_BACK
|
||||||
|
SyncW->>Neo4j: 物理删除(DETACH DELETE)
|
||||||
|
else status=PUBLISHED(保持发布态但属性/来源已变更)
|
||||||
|
SyncW->>Neo4j: 幂等MERGE/SET(更新属性、来源集合)
|
||||||
|
end
|
||||||
|
SyncW->>PG_Conf: 写回 sync_status='SYNCED' 或 'FAILED'
|
||||||
|
SyncW->>Audit: 写审计(action='sync')
|
||||||
|
```
|
||||||
|
|
||||||
|
约束摘录:
|
||||||
|
- revoking 首步可见(2.11 / 6.2),所有读取统一过滤(revoking/revoked 不可被消费)。
|
||||||
|
- 关系恢复与失活遵循 3.7.5:任一端实体失活 → 关系失活;回滚的物理扩散通过 sync_status=PENDING 驱动同步器清理 Neo4j。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## C. 候选与确认的联动与并发安全(审核通过 → Confirm Upsert → 锁定候选)
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
sequenceDiagram
|
||||||
|
autonumber
|
||||||
|
participant API as 后端API(服务)
|
||||||
|
participant PG_Cand as PostgreSQL(kg_*_candidate)
|
||||||
|
participant PG_Conf as PostgreSQL(kg_*_confirm)
|
||||||
|
participant Audit as PostgreSQL(audit_log)
|
||||||
|
|
||||||
|
API->>PG_Cand: 读取待审核候选(status=pending)\n(统一过滤:task非revoking/revoked)
|
||||||
|
API->>PG_Conf: Upsert Confirm(实体或关系)\n- 命中ROLLED_BACK则复位为CONFIRMED(复活规则)\n- 统一置 sync_status='PENDING'
|
||||||
|
API->>PG_Cand: 条件更新:pending→locked(locked_by_confirm=true)
|
||||||
|
API->>Audit: 审计写入(review.accept / relation_uid_mismatch 等)
|
||||||
|
```
|
||||||
|
|
||||||
|
并发与一致性要点(摘自 3.3.3、3.4、4.3):
|
||||||
|
- 候选状态更新采用条件更新或行级锁,禁止盲写。
|
||||||
|
- Confirm Upsert、复活与脏标记(sync_status=PENDING)必须同事务完成。
|
||||||
|
- 审核拒绝不引入 Candidate 新状态(保持 pending),通过 audit_log 表达。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## D. 同步器标准指令集(实体/关系投影的一致性保障)
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
sequenceDiagram
|
||||||
|
autonumber
|
||||||
|
participant SyncW as 同步Worker
|
||||||
|
participant PG_Conf as PostgreSQL(kg_*_confirm)
|
||||||
|
participant Neo4j as Neo4j(投影)
|
||||||
|
participant Audit as PostgreSQL(audit_log)
|
||||||
|
|
||||||
|
SyncW->>PG_Conf: 扫描 sync_status ∈ {'PENDING','FAILED'}(批次/按租户)
|
||||||
|
SyncW->>PG_Conf: 原子置 SYNCING(加锁防重)
|
||||||
|
alt Confirm.status == 'PUBLISHED'
|
||||||
|
SyncW->>Neo4j: MERGE 节点/关系 + SET 属性 + 合并source_tasks
|
||||||
|
else Confirm.status == 'ROLLED_BACK'
|
||||||
|
SyncW->>Neo4j: 物理删除(DETACH DELETE)
|
||||||
|
else Confirm.status == 'CONFIRMED'
|
||||||
|
Note right of SyncW: 保持仅事实确认不投影(不对图操作)
|
||||||
|
end
|
||||||
|
alt 成功
|
||||||
|
SyncW->>PG_Conf: 更新 sync_status='SYNCED'
|
||||||
|
SyncW->>Audit: 写审计(action='sync', result='success')
|
||||||
|
else 失败
|
||||||
|
SyncW->>PG_Conf: 更新 sync_status='FAILED'
|
||||||
|
SyncW->>Audit: 写审计(action='sync', result='failed', error_msg)
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
要点(4.3):
|
||||||
|
- 脏标记必须与业务写入同事务(PENDING 幂等)。
|
||||||
|
- 同步器不改变业务事实,仅保障投影一致性与可观测性。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## E. 统一可见性过滤(跨层防脏读约束)
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
sequenceDiagram
|
||||||
|
autonumber
|
||||||
|
participant DAO as 统一DAO/Service封装
|
||||||
|
participant PG_Task as PostgreSQL(kg_task)
|
||||||
|
participant Reader as 读取者(Candidate生成器/查询)
|
||||||
|
|
||||||
|
Reader->>DAO: selectVisible(...)(封装统一过滤)
|
||||||
|
DAO->>PG_Task: Join kg_task 并过滤\nWHERE kg_task.status NOT IN ('revoking','revoked')
|
||||||
|
DAO-->>Reader: 返回过滤后的可见数据集
|
||||||
|
```
|
||||||
|
|
||||||
|
要点(2.11 / 3.2.4 / 3.3.3):
|
||||||
|
- 过滤逻辑必须统一封装调用(例如 baseMapper.selectVisible),禁止散落实现。
|
||||||
|
- Candidate 生成器、图谱读取等内部流程均需复用本封装。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## F. 状态机摘录(对照PRD冻结口径)
|
||||||
|
|
||||||
|
- Task(3.7.1)
|
||||||
|
- created → running → finished/failed → revoking → revoked
|
||||||
|
- Mention(3.7.2)
|
||||||
|
- — → active(task.finished)\nactive → invalid(task.revoking/revoked)\ninvalid → active(task.re-import 同一任务)
|
||||||
|
- Candidate(3.7.3)
|
||||||
|
- — → pending(由mentions生成)\npending → locked(confirm.publish 或映射既有Confirm)\nlocked → locked/pending(rollback 后视 source_tasks 是否为空)\npending → orphaned(无来源孤立)\norphaned → pending(新来源出现)
|
||||||
|
- Confirm(3.4、3.7.4/3.7.5)
|
||||||
|
- CONFIRMED → PUBLISHED → ROLLED_BACK(复活:命中ROLLED_BACK时复位为CONFIRMED)
|
||||||
|
- sync_status(4.3)
|
||||||
|
- PENDING → SYNCING → SYNCED / FAILED(失败可重试)
|
||||||
|
|
||||||
|
以上时序与状态转换严格沿用 PRDv5 所定义的动作与状态集合。
|
||||||
Loading…
x
Reference in New Issue
Block a user