feat(library): 快照搬运先于维护、双向校验与云端版本回传
为什么改:云端 release-executor 与目标同机后,本机封存的快照必须"先到、先验证" 才允许开维护窗口。此前只有 pack/unpack 两条人工命令:UI 点发布时执行器读到的是 本机归档路径,云端根本没有这份快照,作业只能在装配阶段失败;而预备份落在云端, 本机页面也读不到。用户已批准补齐这条链路。 搬运(新包 internal/libraryhandoff):本机 Load 逐 blob 重算 → Pack → SSH 流式写入 云端暂存 → 原子改名 → 云端 snapshot-unpack 再逐 blob 校验 → 读回版本清单摘要自证 → scope/tenant/知识库身份与治理库作业一致。只有全部通过才投递 library.sync|restore, 失败时发布作业根本不存在(目标不进维护、不写知识)。远端命令是固定 argv,容器名与 路径只来自部署配置;同 ID 异内容拒绝;同一快照本机 flock 串行化;暂存 bundle 用后即删, 归档本体永不自动清理。 回传:capture 角色按已成功作业的 snapshot_id 扫描,把本机缺失的云端快照 Fetch 回来 (云端 pack → SSH 流回 → 本机 Unpack 逐 blob 校验)。回传成功后 API/页面既有的列表、 详情、差异、存储与历史恢复路径读到的就是真实字节;失败则版本不出现在本机,不会被误报成可恢复。 角色:搬运与回传只注册在 capture;若接线到 full(同时消费发布作业)启动即失败, 避免与云端执行器抢同一批作业。release-executor 仍不拥有治理库 DDL,也不消费 QA/邮件/来源扫描。 验证:internal/libraryhandoff 全绿(跨进程 push/fetch、身份不符拒绝、幂等复用、 并发串行、篡改与未知快照不落版本、路径穿越拒绝、远端错误不当作"没有"); cmd/worker 在隔离 fixture 库(独立测试 PG)上验证"校验通过才入队发布、失败不入队"; httpapi 队列决策单测;相关包 go test 全绿;go vet 全仓通过。 未部署、未推送、未构建镜像:云端接线与验收仍由父执行。真实云链路(含 SSH 通道) 本轮没有云侧写操作,只有本机跨进程与隔离 fixture 证据。
This commit is contained in:
@@ -34,6 +34,7 @@ import (
|
||||
|
||||
"knowledge-governance/internal/librarydeadletter"
|
||||
"knowledge-governance/internal/libraryfreeze"
|
||||
"knowledge-governance/internal/libraryhandoff"
|
||||
"knowledge-governance/internal/librarymaintenance"
|
||||
"knowledge-governance/internal/librarysnapshot"
|
||||
v071 "knowledge-governance/internal/releaseadapter/v071"
|
||||
@@ -60,6 +61,9 @@ type options struct {
|
||||
job string
|
||||
dryRun bool
|
||||
snapshot string
|
||||
// kb/tenant 是 snapshot-push 要核对的期望身份(来自治理库作业,不是 bundle 自报)。
|
||||
kb string
|
||||
tenant uint64
|
||||
// bundle 是快照跨主机包路径(snapshot-pack 输出 / snapshot-unpack 输入)。
|
||||
bundle string
|
||||
// releasedDeadLetters 是治理平台审计过的精确解除指纹(逗号分隔)。它只让这些
|
||||
@@ -106,6 +110,10 @@ func main() {
|
||||
runErr = runSnapshotPack(opts)
|
||||
case "snapshot-unpack":
|
||||
runErr = runSnapshotUnpack(opts)
|
||||
case "snapshot-push":
|
||||
runErr = runSnapshotPush(opts)
|
||||
case "snapshot-fetch":
|
||||
runErr = runSnapshotFetch(opts)
|
||||
default:
|
||||
usage()
|
||||
os.Exit(2)
|
||||
@@ -130,6 +138,8 @@ func usage() {
|
||||
snapshot-pack export one sealed snapshot into a single verifiable bundle file
|
||||
snapshot-unpack verify a bundle and install it into this archive (content-addressed,
|
||||
version manifest is the commit point; repeated import is idempotent)
|
||||
snapshot-push send one sealed snapshot to the cloud release executor (verify on both sides)
|
||||
snapshot-fetch bring a cloud-held snapshot back into this archive (verified)
|
||||
|
||||
Flags (defaults target the local WKNFull test stack):
|
||||
-source-app WKNFull-app container whose env describes the source
|
||||
@@ -187,6 +197,8 @@ func parseFlags(command string, args []string) (options, []string, error) {
|
||||
set.StringVar(&opts.snapshot, "snapshot", "", "snapshot id for verify")
|
||||
set.StringVar(&opts.releasedDeadLetters, "released-dead-letters", "", "audited dead-letter fingerprints (comma separated)")
|
||||
set.StringVar(&opts.bundle, "bundle", "", "snapshot bundle path (snapshot-pack / snapshot-unpack)")
|
||||
set.StringVar(&opts.kb, "kb", "", "expected knowledge base id (snapshot-push)")
|
||||
set.Uint64Var(&opts.tenant, "tenant", 0, "expected tenant id (snapshot-push)")
|
||||
if err := set.Parse(args); err != nil {
|
||||
return opts, nil, err
|
||||
}
|
||||
@@ -1206,3 +1218,54 @@ func runSnapshotUnpack(opts options) error {
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
// runSnapshotPush 把一份本机封存快照送到云端发布执行器(先校验字节,再校验身份)。
|
||||
// 只读本机归档;远端只写暂存目录与目标归档,不做任何目标库动作。
|
||||
func runSnapshotPush(opts options) error {
|
||||
if opts.snapshot == "" || opts.scope == "" || opts.kb == "" || opts.tenant == 0 {
|
||||
return errors.New("snapshot-push 需要 -snapshot <id> -scope internal|external -tenant <n> -kb <uuid>")
|
||||
}
|
||||
handoff, err := openHandoff(opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
evidence, err := handoff.Push(context.Background(), libraryhandoff.Identity{
|
||||
SnapshotID: opts.snapshot, Scope: opts.scope, TenantID: opts.tenant, KnowledgeBaseID: opts.kb})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printJSON(evidence)
|
||||
return nil
|
||||
}
|
||||
|
||||
// runSnapshotFetch 把云端的快照取回本机归档(预备份/云端版本的读回)。
|
||||
func runSnapshotFetch(opts options) error {
|
||||
if opts.snapshot == "" {
|
||||
return errors.New("snapshot-fetch 需要 -snapshot <id>")
|
||||
}
|
||||
handoff, err := openHandoff(opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
evidence, err := handoff.Fetch(context.Background(), opts.snapshot)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printJSON(evidence)
|
||||
return nil
|
||||
}
|
||||
|
||||
// openHandoff 只认部署注入的配置:CLI 不接受调用方指定远端路径/容器/上游地址。
|
||||
func openHandoff(opts options) (*libraryhandoff.Handoff, error) {
|
||||
config, configured, err := libraryhandoff.FromEnv(os.Getenv)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !configured {
|
||||
return nil, errors.New("快照搬运未接线(缺少 LIBRARY_HANDOFF_*)")
|
||||
}
|
||||
if opts.archiveRoot != "" && config.LocalArchive == "" {
|
||||
config.LocalArchive = opts.archiveRoot
|
||||
}
|
||||
return libraryhandoff.New(config, nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user