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: // // ## // // 它就是 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 }