为什么:父审指出预备份引用持久化失败仍继续写目标、接管依赖启动扫描且漏掉租约未过期、 恢复失败被标成"无需恢复"、版本登记与作业状态分叉。 - 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:
@@ -13,8 +13,11 @@ import (
|
||||
// 生产发布授权:管理员把"目标 + 快照 + 参数摘要 + 有效期"钉死。
|
||||
// 换快照、换目标或改参数都会得到不同摘要,旧授权自然失效;到期或被撤销也不能用。
|
||||
type libraryAuthorizationRequest struct {
|
||||
Scope string `json:"scope"`
|
||||
SnapshotID string `json:"snapshot_id"`
|
||||
Scope string `json:"scope"`
|
||||
SnapshotID string `json:"snapshot_id"`
|
||||
// Action 决定授权的动作:sync(默认)或 restore。两者摘要不同,
|
||||
// 同步授权不能当恢复授权用,反之亦然。
|
||||
Action string `json:"action"`
|
||||
ExpiresInMinutes int `json:"expires_in_minutes"`
|
||||
}
|
||||
|
||||
@@ -69,14 +72,28 @@ func libraryAuthorizationCreate(w http.ResponseWriter, r *http.Request, config C
|
||||
writeJSON(w, http.StatusBadRequest, map[string]string{"error": "expires_in_minutes must be between 5 and 1440"})
|
||||
return
|
||||
}
|
||||
digest, err := librarySyncParamsDigest(request.Scope, request.SnapshotID)
|
||||
action := strings.TrimSpace(request.Action)
|
||||
if action == "" {
|
||||
action = "sync"
|
||||
}
|
||||
var digest string
|
||||
var err error
|
||||
switch action {
|
||||
case "sync":
|
||||
digest, err = librarySyncParamsDigest(request.Scope, request.SnapshotID)
|
||||
case "restore":
|
||||
digest, err = libraryRestoreParamsDigest(request.Scope, request.SnapshotID)
|
||||
default:
|
||||
writeJSON(w, http.StatusBadRequest, map[string]string{"error": "action must be sync or restore"})
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
writeJSON(w, http.StatusInternalServerError, map[string]string{"error": "cannot digest params"})
|
||||
return
|
||||
}
|
||||
now := time.Now().UTC()
|
||||
item := governance.LibraryReleaseAuthorization{
|
||||
ID: "libauth-" + request.Scope + "-" + now.Format("20060102T150405.000000"),
|
||||
ID: "libauth-" + action + "-" + request.Scope + "-" + now.Format("20060102T150405.000000000"),
|
||||
Scope: request.Scope,
|
||||
SnapshotID: request.SnapshotID,
|
||||
ParamsDigest: digest,
|
||||
|
||||
@@ -597,7 +597,8 @@ func librarySyncEnqueue(w http.ResponseWriter, r *http.Request, config Config) {
|
||||
TargetSnapshotID: request.Target, Actor: actor,
|
||||
}, governance.SyncStages(), now)
|
||||
if errors.Is(err, governance.ErrLibraryJobActive) {
|
||||
writeJSON(w, http.StatusConflict, map[string]any{"code": "library_sync_active", "error": "该目标已有在飞的同步作业"})
|
||||
writeJSON(w, http.StatusConflict, map[string]any{"code": "library_sync_active",
|
||||
"error": "该目标已有在飞的生产写作业(同步与恢复互斥)"})
|
||||
return
|
||||
}
|
||||
if errors.Is(err, governance.ErrLibraryJobIdempotencyConflict) {
|
||||
|
||||
@@ -228,8 +228,13 @@ func libraryJobResume(w http.ResponseWriter, r *http.Request, config Config) {
|
||||
writeJSON(w, http.StatusAccepted, map[string]any{"job": job, "resumed_from": sourceID, "reused": true})
|
||||
return
|
||||
}
|
||||
payload, _ := json.Marshal(map[string]string{"library_job_id": job.ID, "scope": source.Scope,
|
||||
"target_snapshot_id": source.TargetSnapshotID})
|
||||
// 写入已完成、只差登记版本的情况:续作只做幂等收尾,不重写生产。
|
||||
body := map[string]any{"library_job_id": job.ID, "scope": source.Scope,
|
||||
"target_snapshot_id": source.TargetSnapshotID}
|
||||
if source.Stage == "finalize" && source.SnapshotID != "" {
|
||||
body["finalize_only"] = true
|
||||
}
|
||||
payload, _ := json.Marshal(body)
|
||||
queueJob, err := config.Store.Enqueue(r.Context(), jobs.EnqueueRequest{
|
||||
ID: governance.QueueJobIDFor(job.ID), Type: queueType, Payload: payload, AvailableAt: now,
|
||||
MaxAttempts: 1, IdempotencyKey: "library.resume.queue:" + job.ID,
|
||||
|
||||
Reference in New Issue
Block a user