f91359f881
build / build (push) Successful in 1m15s
为什么:存储页原来只有占用数字,保留/依赖保护/清理预览写"未接线";这些都不需要生产写权限, 按"未设置就不做决定"的口径实现成只读计算。 - internal/libraryretention:按保留数量/天数生成预览;生产生效、每库最近封存、每次生产预备份、 在飞作业引用一律受保护;回收预览只算独占字节,共享 blob 不计。 - internal/libraryretention.CheckCapacity:预算未设置即不放行(无法证明装得下),超预算阻断; 已并入 POST /library/syncs 的 gate 缺项。 - 新增 GET /api/v1/library/storage:真实归档用量 + 三类版本保护依据 + 策略 + 预览 + 容量,只读。 - 系统设置→存储管理改为读该接口:策略未设置时明确"全部保留、不生成候选",自动清理恒关闭。 - 配置项 LIBRARY_CAPACITY_BUDGET_BYTES / LIBRARY_RETENTION_VERSIONS / LIBRARY_RETENTION_DAYS(未设=0)。
36 lines
1.3 KiB
Go
36 lines
1.3 KiB
Go
package libraryretention
|
|
|
|
import "fmt"
|
|
|
|
// Capacity 是生产写入前的容量门禁:预算未设置就不放行(无法证明"装得下"),
|
|
// 预算已知但不足也阻断。它不复用清理预览的回收量——清理未授权,不能拿它抵账。
|
|
type Capacity struct {
|
|
BudgetBytes int64 `json:"budget_bytes"`
|
|
CurrentBytes int64 `json:"current_bytes"`
|
|
RequiredBytes int64 `json:"required_bytes"`
|
|
ProjectedByte int64 `json:"projected_bytes"`
|
|
Configured bool `json:"configured"`
|
|
OK bool `json:"ok"`
|
|
Reason string `json:"reason,omitempty"`
|
|
}
|
|
|
|
func CheckCapacity(currentBytes, requiredBytes, budgetBytes int64) Capacity {
|
|
result := Capacity{BudgetBytes: budgetBytes, CurrentBytes: currentBytes, RequiredBytes: requiredBytes,
|
|
ProjectedByte: currentBytes + requiredBytes}
|
|
if budgetBytes <= 0 {
|
|
result.Reason = "容量预算未设置(LIBRARY_CAPACITY_BUDGET_BYTES),无法证明装得下"
|
|
return result
|
|
}
|
|
result.Configured = true
|
|
if requiredBytes < 0 || currentBytes < 0 {
|
|
result.Reason = "容量口径异常(负数),拒绝放行"
|
|
return result
|
|
}
|
|
if result.ProjectedByte > budgetBytes {
|
|
result.Reason = fmt.Sprintf("写入后预计占用 %d 字节,超过预算 %d 字节", result.ProjectedByte, budgetBytes)
|
|
return result
|
|
}
|
|
result.OK = true
|
|
return result
|
|
}
|