候选归档 79 版 / 56MB blob 上,overview、storage、snapshots 三个只读接口 都在 10s 请求期限后返回 503。分段计时定位到唯一瓶颈是按版本重读全部 blob: Open 0ms、LoadManifest×79 11~22ms、ContentUsage 15~25ms、 Usage(逐版 Load 验字节)13.75~14.11s;单版 Load 261~290ms。 - Usage 拆成 Usage(逐版复核字节,同步/恢复与运维 CLI 用)与 UsageFromManifests(同一份去重实现,只做清单级校验),列举路径改用后者; - library_storage.go 每版两次 Load、snapshots 每版一次 Load 改为一次清单读取; - wiki/文档差异只读所需部件,被读部件仍由 OpenPart 复核摘要; - LoadManifest 与 Load 共用同一套清单判据(严格解码 + 重新编码校验); - 列举响应带 verification=manifest / verified=false,详情整版复核后才是 content, 避免把"清单可读"读成"完整性已验证"; - libraryWithDeadline 去掉超时后再写已结束响应的 goroutine 写法 (候选环境实测 http: superfluous response.WriteHeader call)。 回归:多版本共享大 blob 时枚举不读 blob 字节(篡改后枚举仍成功), 而 Load/OpenPart/Usage 仍拒绝坏 blob;坏清单两条路径都整条报错。 make verify 15 项全绿(local 档案)。
This commit is contained in:
@@ -42,11 +42,16 @@ type libraryStorageResponse struct {
|
||||
Capacity libraryretention.Capacity `json:"capacity"`
|
||||
AutomaticCleanup bool `json:"automatic_cleanup"`
|
||||
Notes []string `json:"notes"`
|
||||
// 容量/保留计数是清单级口径:真实去重、每次重算,但"被引用字节是否完好"
|
||||
// 只在实际执行(同步/恢复)时逐部件复核,这两件事不能混成一句"已验证"。
|
||||
Verification string `json:"verification"`
|
||||
VerificationNote string `json:"verification_note"`
|
||||
}
|
||||
|
||||
func libraryStorageHandler(w http.ResponseWriter, r *http.Request, config Config) {
|
||||
response := libraryStorageResponse{Versions: []storageVersionView{}, Notes: []string{}, AutomaticCleanup: false,
|
||||
Policy: libraryretention.Policy{KeepVersions: int(config.LibraryRetentionVersions), KeepDays: int(config.LibraryRetentionDays)}}
|
||||
Policy: libraryretention.Policy{KeepVersions: int(config.LibraryRetentionVersions), KeepDays: int(config.LibraryRetentionDays)},
|
||||
Verification: libraryVerificationManifest, VerificationNote: libraryVerificationNote}
|
||||
if strings.TrimSpace(config.LibraryArchiveRoot) == "" {
|
||||
response.Reason = "未接线:LIBRARY_ARCHIVE_ROOT 未配置,没有可统计的归档"
|
||||
writeJSON(w, http.StatusServiceUnavailable, response)
|
||||
@@ -74,7 +79,7 @@ func libraryStorageHandler(w http.ResponseWriter, r *http.Request, config Config
|
||||
response.UnreferencedBytes = total.UnreferencedBytes
|
||||
response.ManifestFileBytes = total.ManifestFileBytes
|
||||
|
||||
usage, err := archive.Usage()
|
||||
usage, err := archive.UsageFromManifests()
|
||||
if err != nil {
|
||||
response.Reason = "归档逐版本用量不可读"
|
||||
writeJSON(w, http.StatusServiceUnavailable, response)
|
||||
@@ -127,13 +132,17 @@ func libraryStorageHandler(w http.ResponseWriter, r *http.Request, config Config
|
||||
versions := make([]libraryretention.Version, 0, len(ids))
|
||||
latestSealed := map[string]time.Time{}
|
||||
var requiredBytes int64
|
||||
for _, id := range ids {
|
||||
manifest, loadErr := archive.Load(id)
|
||||
if loadErr != nil {
|
||||
response.Reason = "归档快照校验失败"
|
||||
writeJSON(w, http.StatusServiceUnavailable, response)
|
||||
return
|
||||
}
|
||||
// 版本元数据走清单级读取:这里只做容量/保留盘点,不执行任何版本。
|
||||
// 需要动某个版本时(同步/恢复)仍然整版复核字节。
|
||||
manifests, err := libraryManifests(r.Context(), archive, ids)
|
||||
if err != nil {
|
||||
status, reason := libraryArchiveErrorStatus(err, "归档清单不可读")
|
||||
response.Reason = reason
|
||||
writeJSON(w, status, response)
|
||||
return
|
||||
}
|
||||
for index, id := range ids {
|
||||
manifest := manifests[index]
|
||||
kind := "unregistered"
|
||||
if record, ok := kinds[id]; ok {
|
||||
kind = string(record.Kind)
|
||||
@@ -153,12 +162,9 @@ func libraryStorageHandler(w http.ResponseWriter, r *http.Request, config Config
|
||||
ExclusiveBytes: item.ExclusiveBytes, SharedBytes: item.SharedBytes})
|
||||
response.Versions = append(response.Versions, view)
|
||||
}
|
||||
// 用与上面相同的排序再定位一次最新测试封存,避免把时间映射回 ID 时出错。
|
||||
for _, id := range ids {
|
||||
manifest, loadErr := archive.Load(id)
|
||||
if loadErr != nil {
|
||||
continue
|
||||
}
|
||||
// 用与上面相同的清单再定位一次最新测试封存,避免把时间映射回 ID 时出错。
|
||||
for index, id := range ids {
|
||||
manifest := manifests[index]
|
||||
if kindOf := kinds[id].Kind; kindOf == governance.LibraryVersionTestSealed ||
|
||||
(kindOf == "" && manifest.ValidationPolicy != "") {
|
||||
if manifest.CreatedAt.Equal(latestSealed[manifest.Scope]) {
|
||||
|
||||
Reference in New Issue
Block a user