fix(library): 修复封存终态回写并增加精确核对
build / build (push) Successful in 2m9s

修复 varchar 状态参数在 AdvanceLibraryJob 的 42P08;worker 开始/终态写入失败
不再吞掉。新增管理员核对路由,仅在 completed capture queue、export succeeded、
精确 test_sealed 版本、来源身份和归档复核一致时,以条件更新修复仍为
pending/running 的同一作业;已有不同快照或并发失败/取消行拒绝覆盖。保留
第一因与历史记录,不重新封存、不产生快照、不写源或目标知识。

验证:真实 varchar DDL PG 路径、handler 负例/幂等、worker 注入、web 组件;
umask022 与真实隔离 kg_library_test_* 下 Go 全量与 make verify 17 项通过。
This commit is contained in:
姚章浩
2026-11-06 10:04:19 +08:00
parent 77bbc3ac6b
commit 146ac832a2
18 changed files with 1082 additions and 39 deletions
@@ -57,12 +57,12 @@ func (s *Store) AdvanceLibraryJobGuarded(ctx context.Context, attempt governance
}
tag, err := s.db.Exec(ctx, `
UPDATE library_jobs SET
state=$2,
stage = CASE WHEN $3='' THEN stage ELSE $3 END,
error = CASE WHEN $4='' THEN error ELSE $4 END,
recovery = CASE WHEN $5='' THEN recovery ELSE $5 END,
snapshot_id = CASE WHEN $6='' THEN snapshot_id ELSE $6 END,
target_snapshot_id = CASE WHEN $7='' THEN target_snapshot_id ELSE $7 END,
state=$2::text,
stage = CASE WHEN $3::text='' THEN stage ELSE $3::text END,
error = CASE WHEN $4::text='' THEN error ELSE $4::text END,
recovery = CASE WHEN $5::text='' THEN recovery ELSE $5::text END,
snapshot_id = CASE WHEN $6::text='' THEN snapshot_id ELSE $6::text END,
target_snapshot_id = CASE WHEN $7::text='' THEN target_snapshot_id ELSE $7::text END,
updated_at=$8,
finished_at=COALESCE($9, finished_at)
WHERE id=$1 AND `+libraryFence("$1", 10, 11),
@@ -82,12 +82,12 @@ func (s *Store) UpdateLibraryStageGuarded(ctx context.Context, attempt governanc
stage, state string, total, completed, bytesTotal, bytesDone *int64, detail string, now time.Time) error {
tag, err := s.db.Exec(ctx, `
UPDATE library_job_stages SET
state = CASE WHEN $3='' THEN state ELSE $3 END,
state = CASE WHEN $3::text='' THEN state ELSE $3::text END,
total = COALESCE($4, total),
completed = COALESCE($5, completed),
bytes_total = COALESCE($6, bytes_total),
bytes_done = COALESCE($7, bytes_done),
detail = CASE WHEN $8='' THEN detail ELSE $8 END,
detail = CASE WHEN $8::text='' THEN detail ELSE $8::text END,
updated_at = $9
WHERE job_id=$1 AND stage=$2 AND `+libraryFence("$1", 10, 11),
attempt.JobID, stage, state, total, completed, bytesTotal, bytesDone, detail, now.UTC(),