为什么:父审指出预备份引用持久化失败仍继续写目标、接管依赖启动扫描且漏掉租约未过期、 恢复失败被标成"无需恢复"、版本登记与作业状态分叉。 - BackupPrepared 返回 error,持久化失败即零写入;预备份同时登记 production_prebackup 版本。 - 接管改为按队列租约判定 + 运行期 30s 扫描 + 原子抢占 + 固定幂等键 + attempt 归零。 - 接管场景保留预备份、不再宣称"未写无需恢复"。 - 恢复/重放同一快照重新激活 production_effective(清 superseded_at)。 - finalize 续作只做校验+登记(finalize_only),不重写生产。 - 索引映射基线缺失时采用首次观察值并登记;索引校验加孤儿文档检查(按 knowledge_id)。 真实验收(候选 API :18089 + 真实 PG/ES/MinIO): A0 首次发布、A1 撤销、B 按版本恢复、C 写阶段 SIGKILL 接管、 D 跨 kind 互斥与多 worker 单次执行、E1 登记失败、E2 finalize 续作、E3 预备份失败零写入。
This commit is contained in:
@@ -31,6 +31,8 @@ type libraryStageRecorder struct {
|
||||
store *postgresstore.Store
|
||||
jobID string
|
||||
scope string
|
||||
// mappingDigest 是本次读到的生产索引映射,随预备份一起登记成版本证据。
|
||||
mappingDigest string
|
||||
}
|
||||
|
||||
func (r libraryStageRecorder) Stage(ctx context.Context, stage, state, detail string) {
|
||||
@@ -80,6 +82,24 @@ func run(ctx context.Context, getenv func(string) string) error {
|
||||
} else if resumed > 0 || failed > 0 {
|
||||
log.Printf("library job resume: %d resumed, %d failed without backup", resumed, failed)
|
||||
}
|
||||
// 运行期也要持续接管:只在启动扫一次会漏掉"worker 在两次重启之间被杀"的情况。
|
||||
go func() {
|
||||
ticker := time.NewTicker(30 * time.Second)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-ticker.C:
|
||||
resumed, failed, err := resumeInterruptedLibraryJobs(ctx, store, config)
|
||||
if err != nil {
|
||||
log.Printf("library job takeover sweep: %v", err)
|
||||
} else if resumed > 0 || failed > 0 {
|
||||
log.Printf("library job takeover sweep: %d resumed, %d failed without backup", resumed, failed)
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
if repaired, reconcileErr := store.ReconcileLibraryJobs(context.Background(), time.Now().UTC()); reconcileErr != nil {
|
||||
log.Printf("library job reconcile failed: %v", reconcileErr)
|
||||
} else if repaired > 0 {
|
||||
|
||||
Reference in New Issue
Block a user