Files
knowledge-governance/internal/governance/library_recovery_identity.go
T
姚章浩 245cefd6b0 fix(library): 收紧 DS01 派发租约/投递/治理身份与绑定冲突
F2.a:Acquire/Confirm 在取得 effect 行锁后用数据库时钟重核 job/attempt/
恢复投递租约,等锁跨过到期零许可且状态保持 prepared。

F2.b:同一 CAS 事务锁 recovery queue 与 operation,复核 window/scope、
idempotency、owner/attempt/lease,并按原 window 锚点重算恢复请求摘要。

F3.identity:激活证据 v3 携带 PG 集群 system_identifier + 库 OID、完整构建
SHA 与协议批次;激活与使用点都现场重读并拒绝同名异域/副本/unknown/不兼容 SHA。

F4.binding:区分绑定冲突与仅禁止重发的 Held,准入/确认/续作/收尾在所有状态
拒绝冲突,合法 dispatching + 精确 marker 仍可确认。
2026-11-02 20:36:36 +08:00

53 lines
1.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package governance
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"strings"
)
// The recovery request has its own queue identity and stable operation. It
// borrows the original window's fence, never its immutable sending identity.
func LibraryRecoveryQueueID(windowJob string) string {
sum := sha256.Sum256([]byte(windowJob))
return "lrec-" + hex.EncodeToString(sum[:14])
}
func LibraryRecoveryDigest(scope, queue, window, operation, target, source, backup, plan string) (string, error) {
return LibraryRequestDigest(scope, LibraryJobRecover, map[string]any{
"recovery_queue": queue, "window_job": window, "original_operation": operation,
"target_id": target, "source_snapshot": source, "backup_snapshot": backup, "writeset_digest": plan,
})
}
// LibraryDeliveryOwner 是队列投递 + 业务 attempt 的合成 owner:
//
// <worker>#<queue job>#<queue attempt>
//
// 它就是 library_attempts.owner,也决定了"这次派发属于哪一次真实投递"。worker 与
// 派发台账必须用同一份格式,否则"当前 owner"会变成两处各自解释的字符串。
func LibraryDeliveryOwner(workerID, queueID string, attempt int) string {
if queueID == "" {
queueID = "-"
}
if workerID == "" {
workerID = "worker"
}
return fmt.Sprintf("%s#%s#%d", workerID, queueID, attempt)
}
// ParseLibraryDeliveryOwner 把 owner 拆回 (worker, ok);queue/attempt 必须逐位相同,
// 不能靠后缀匹配把别的投递混进来。
func ParseLibraryDeliveryOwner(owner, queueID string, attempt int) (string, bool) {
suffix := fmt.Sprintf("#%s#%d", queueID, attempt)
if queueID == "" || !strings.HasSuffix(owner, suffix) {
return "", false
}
worker := strings.TrimSuffix(owner, suffix)
if worker == "" || strings.Contains(worker, "#") {
return "", false
}
return worker, true
}