fix(library): 收口 B1-R1/B2-R1/B5-R1 并让恢复链经过正式队列终态
B1-R1: 演练写集改为受限 restore-drill(V2 信封/contract 1/schema 摘要,零对象、零索引、零本地映射,来源身份必填)。B2-R1: verify 作业先建不可变 operation 并携带 operation_id,同 job recover 的网关 claim 同时携带原 operation 与 recovery 身份。B5-R1: 前端按 scope 世代与动作序号丢弃迟到响应,不污染新 scope 或父级旧回调。harness 的 recovery 改由生产 jobs.Worker.RunOnce 消费并读回 jobs 终态;原失败窗口作业保持 failed,不改写历史。
This commit is contained in:
@@ -19,6 +19,12 @@ const WriteSetVersion = 1
|
||||
// MigrationWriteSetVersion rejects reinterpretation by old V1 executors.
|
||||
const MigrationWriteSetVersion = 2
|
||||
|
||||
// WriteSetKindRestoreDrill marks a write set that authorizes only a recovery
|
||||
// drill: canary rows plus a zero-object/zero-index execution plan. It shares
|
||||
// the V2 envelope so the object gateway controller can verify it, but it is
|
||||
// never a publish plan and must not be adopted as one.
|
||||
const WriteSetKindRestoreDrill = "restore-drill"
|
||||
|
||||
// WriteSetRow 是台账里的一行:本次发布明确要写的精确身份 + 写前状态。
|
||||
//
|
||||
// 为什么需要"写前状态":恢复不能在目标里按"没人引用"推断残渣。历史孤儿资源、
|
||||
@@ -89,6 +95,10 @@ type LocalIDMapping struct {
|
||||
}
|
||||
|
||||
type WriteSet struct {
|
||||
// Kind 区分发布执行计划与受限演练恢复计划。空值 = 历史发布计划。
|
||||
// 演练计划必须显式为 restore-drill:它只授权 canary 回放,不含对象/索引
|
||||
// 写项,读取方不能把它当发布计划接管。
|
||||
Kind string `json:"kind,omitempty"`
|
||||
Index []IndexWrite `json:"index,omitempty"`
|
||||
Objects []ObjectWrite `json:"objects,omitempty"`
|
||||
SchemaDigest string `json:"schema_digest,omitempty"`
|
||||
@@ -218,6 +228,22 @@ func (w *WriteSet) Verify() error {
|
||||
if w.Version != WriteSetVersion && w.Version != MigrationWriteSetVersion {
|
||||
return fmt.Errorf("写集合记录版本 %d 不受支持(当前 %d)", w.Version, WriteSetVersion)
|
||||
}
|
||||
if w.Kind != "" && w.Kind != WriteSetKindRestoreDrill {
|
||||
return fmt.Errorf("写集合记录种类 %q 不受支持", w.Kind)
|
||||
}
|
||||
if w.Kind == WriteSetKindRestoreDrill {
|
||||
// 演练恢复计划只回放写前镜像:不新建对象、不按发布计划改索引、不做本地 ID 映射。
|
||||
// 任何一项非空都说明它被当成发布计划构造/改写过,拒绝。
|
||||
if w.Version != MigrationWriteSetVersion || w.ContractVersion != 1 || len(w.SchemaDigest) != 64 {
|
||||
return errors.New("演练恢复计划缺少可执行契约(V2 + contract 1 + schema 摘要)")
|
||||
}
|
||||
if len(w.Objects) != 0 || len(w.Index) != 0 || len(w.LocalIDs) != 0 {
|
||||
return errors.New("演练恢复计划不得包含对象/索引/本地映射写项")
|
||||
}
|
||||
if w.SourceTenantID == 0 || w.SourceKnowledgeBaseID == "" {
|
||||
return errors.New("演练恢复计划缺少来源身份")
|
||||
}
|
||||
}
|
||||
if w.JobID == "" || w.BackupSnapshotID == "" || w.TargetSnapshotID == "" {
|
||||
return errors.New("写集合记录缺少作业/预备份/快照绑定")
|
||||
}
|
||||
@@ -248,6 +274,9 @@ func (w *WriteSet) Verify() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsRestoreDrill 表示这是一份受限演练恢复计划,而不是发布执行计划。
|
||||
func (w WriteSet) IsRestoreDrill() bool { return w.Kind == WriteSetKindRestoreDrill }
|
||||
|
||||
// CreatedIDs 返回"本次新建"的精确身份(写前不存在的行)。恢复只允许删这些。
|
||||
func (w WriteSet) CreatedIDs(table string) []string {
|
||||
ids := make([]string, 0, 8)
|
||||
|
||||
Reference in New Issue
Block a user