F01:捕获、写前镜像、指纹和恢复后内容校验共用按目标精确绑定的资源闭包: 从已限定范围的 resource_bindings 与正文 handle 一次提取,再按索引取资源, 不再对每个租户资源扫描全部正文表。无绑定正文引用仍保留,缺失资源仍失败。 F02/F03:恢复验证使用 capture/verify/canary/restore/finalize 自己的阶段,登记 证据不再叫新版本生效;顶部优先在飞作业;已验证且 API reason 为空时不再同屏 显示未读到状态,报告可展开。 F04-F11:显示实际目标实例/项目/库;运行中主按钮查看当前任务并禁止重复启动; 快照历史默认已登记、可筛选分页并定位所选;无真实下次计划时显示未读取;各 scope 独立 overview;新操作清旧通知;存储行按文档/分块/资源/绑定及 Wiki 页面/目录/日志分项。高影响恢复验证/恢复增加一次影响确认。 验证:隔离 PG 20k 无关资源夹具旧扫描 683ms→新导出 41ms,资源 ID 闭包相等; Go/前端全量及 make verify 17 项通过。未部署、未做 8088 UI 验收。
This commit is contained in:
@@ -68,22 +68,52 @@ func joinLines(items []string) string {
|
||||
// 归档没有的列(生产默认值/后续新增列)不参与比对,避免"我们没管的列"造成假失败,
|
||||
// 但归档里有的每一列都必须逐字一致。
|
||||
func (t *ProductionLibraryTarget) productionTableContent(ctx context.Context, table string, columns map[string]bool) (int64, string, error) {
|
||||
// 不加表别名:scopeWhere(resources) 里引用了 resources.id,别名会让它失效。
|
||||
rows, err := t.pool.Query(ctx, fmt.Sprintf(`SELECT to_jsonb(%s) FROM %s WHERE %s`, table, table, scopeWhere(table)),
|
||||
t.scope.TenantID, t.scope.KnowledgeBaseID)
|
||||
if err != nil {
|
||||
return 0, "", fmt.Errorf("读取生产 %s 内容失败: %w", table, err)
|
||||
identity := PostgresIdentity{TenantID: t.scope.TenantID, KnowledgeBaseID: t.scope.KnowledgeBaseID}
|
||||
exporter := PostgresExporter{db: t.pool}
|
||||
var rows []json.RawMessage
|
||||
if table == "resources" {
|
||||
// F01: verification must use the same bounded reference set as capture;
|
||||
// the legacy per-resource body scan made post-sync verification minutes
|
||||
// long on a small target inside a large tenant.
|
||||
var bodies, bindings []json.RawMessage
|
||||
for _, name := range productionLibraryTables {
|
||||
if name == "resources" {
|
||||
continue
|
||||
}
|
||||
items, err := exporter.queryRows(ctx, fmt.Sprintf(`SELECT to_jsonb(%s) FROM %s WHERE %s`,
|
||||
name, name, scopeWhere(name)), identity.TenantID, identity.KnowledgeBaseID)
|
||||
if err != nil {
|
||||
return 0, "", fmt.Errorf("读取生产 %s 内容失败: %w", table, err)
|
||||
}
|
||||
if name != "resource_bindings" && name != "knowledge_tag_relations" {
|
||||
bodies = append(bodies, items...)
|
||||
}
|
||||
if name == "resource_bindings" {
|
||||
bindings = items
|
||||
}
|
||||
}
|
||||
items, err := scopedResourceRows(ctx, &exporter, identity, true, bodies, bindings)
|
||||
if err != nil {
|
||||
return 0, "", fmt.Errorf("读取生产 %s 内容失败: %w", table, err)
|
||||
}
|
||||
rows = items
|
||||
} else {
|
||||
items, err := exporter.queryRows(ctx, fmt.Sprintf(`SELECT to_jsonb(%s) FROM %s WHERE %s`, table, table, scopeWhere(table)),
|
||||
identity.TenantID, identity.KnowledgeBaseID)
|
||||
if err != nil {
|
||||
return 0, "", fmt.Errorf("读取生产 %s 内容失败: %w", table, err)
|
||||
}
|
||||
rows = items
|
||||
}
|
||||
defer rows.Close()
|
||||
digests := make([]string, 0, 64)
|
||||
for rows.Next() {
|
||||
var raw map[string]json.RawMessage
|
||||
if err := rows.Scan(&raw); err != nil {
|
||||
digests := make([]string, 0, len(rows))
|
||||
for _, raw := range rows {
|
||||
var value map[string]json.RawMessage
|
||||
if err := json.Unmarshal(raw, &value); err != nil {
|
||||
return 0, "", err
|
||||
}
|
||||
projected := make(map[string]json.RawMessage, len(columns))
|
||||
for key := range columns {
|
||||
if value, ok := raw[key]; ok {
|
||||
if value, ok := value[key]; ok {
|
||||
projected[key] = value
|
||||
}
|
||||
}
|
||||
@@ -93,9 +123,6 @@ func (t *ProductionLibraryTarget) productionTableContent(ctx context.Context, ta
|
||||
}
|
||||
digests = append(digests, digest)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return 0, "", err
|
||||
}
|
||||
return int64(len(digests)), combineRowDigests(digests), nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user