fix(library): 当前生效版本改按精确查询
接管分类、基线判定、已知索引映射、同步闸口的创建判据与归档保留的保护标记, 原来都用 LibraryVersions(scope, 50/100) 这个分页窗口再在内存里筛。生效版本每 scope 只有一行、可能很久以前登记,历史一长就被挤出窗口 —— 于是"已生效"被读成 "没有生效":接管会把已经上线的目标重写一遍,基线入口会给已有权威版本的目标 再建一次基线。 现在统一走两条精确查询:LibraryCurrentVersion(kind='production_effective' AND superseded_at IS NULL,每 scope 至多一行)与 LibraryVersionOfSnapshot(按快照 身份取回"已顶替"证据)。多行、自相矛盾、读不到一律 fail closed;同一含义只留 一份实现(knownIndexMapping 同步与恢复共用)。LibraryVersions 仍是 1..100 的 展示窗口,只用于列表。 验证:真实 PG 上先复现(窗口实现 ⇒ found=false),改后 7 条 store 契约用例与 worker 端到端判定用例全绿;本机 make verify 15 项 success(用例 1264 通过 / 0 失败 / 93 已声明可选跳过)。
This commit is contained in:
@@ -103,14 +103,19 @@ func libraryStorageHandler(w http.ResponseWriter, r *http.Request, config Config
|
||||
if listErr == nil {
|
||||
for _, item := range versions {
|
||||
kinds[item.SnapshotID] = item
|
||||
if item.Kind == governance.LibraryVersionProductionEffective && item.SupersededAt == nil {
|
||||
protectedBy[item.SnapshotID] = append(protectedBy[item.SnapshotID], "生产生效版本")
|
||||
}
|
||||
if item.Kind == governance.LibraryVersionProductionPrebackup {
|
||||
protectedBy[item.SnapshotID] = append(protectedBy[item.SnapshotID], "生产预备份")
|
||||
}
|
||||
}
|
||||
}
|
||||
// 生产生效版本 = 唯一一条未顶替的记录,必须精确查:它可能早已掉出上面的
|
||||
// 展示窗口,靠列表判"是否受保护"会让当前生效的那份被当成普通版本清掉。
|
||||
if current, found, currentErr := store.LibraryCurrentVersion(r.Context(), scope); currentErr == nil && found {
|
||||
if _, seen := kinds[current.SnapshotID]; !seen {
|
||||
kinds[current.SnapshotID] = current
|
||||
}
|
||||
protectedBy[current.SnapshotID] = appendUnique(protectedBy[current.SnapshotID], "生产生效版本")
|
||||
}
|
||||
jobs, jobErr := store.ListLibraryJobs(r.Context(), scope, 20)
|
||||
if jobErr == nil {
|
||||
for _, job := range jobs {
|
||||
@@ -205,3 +210,14 @@ func libraryStorageHandler(w http.ResponseWriter, r *http.Request, config Config
|
||||
response.Capacity = libraryretention.CheckCapacity(total.ContentBytes, requiredBytes, config.LibraryCapacityBudgetBytes)
|
||||
writeJSON(w, http.StatusOK, response)
|
||||
}
|
||||
|
||||
// appendUnique 只追加还没出现过的标签:同一条版本可能同时被展示窗口与精确查询命中,
|
||||
// 重复标签会让"保护依据"看起来像两条不同理由。
|
||||
func appendUnique(labels []string, value string) []string {
|
||||
for _, item := range labels {
|
||||
if item == value {
|
||||
return labels
|
||||
}
|
||||
}
|
||||
return append(labels, value)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user