feat(library): 整库发布身份、写集合与收尾边界
build / build (push) Successful in 1m45s

执行时真实时钟与持久授权回读(撤销/过期即停并保留预备份)、写集合写前落盘、
租约与 attempt 身份、恢复队列与原发送身份分离、成功收尾必须释放维护后再登记终态。
This commit is contained in:
姚章浩
2026-11-01 11:35:10 +08:00
parent 5afd8c0140
commit 8d838d9cb4
82 changed files with 4809 additions and 551 deletions
+37 -1
View File
@@ -57,6 +57,10 @@ type Archive struct {
}
func Open(root string, maxBlobBytes int64) (*Archive, error) {
return openArchive(root, maxBlobBytes, syncRoot)
}
func openArchive(root string, maxBlobBytes int64, syncDirectory func(*os.Root) error) (*Archive, error) {
if !filepath.IsAbs(root) || maxBlobBytes < 1 || maxBlobBytes == math.MaxInt64 {
return nil, errors.New("invalid archive configuration")
}
@@ -94,6 +98,22 @@ func Open(root string, maxBlobBytes int64) (*Archive, error) {
a.versions = sub
}
}
// File and child-directory fsync cannot persist their parent entries. The
// archive root links blobs/versions, and its parent links the archive itself.
if err := syncDirectory(r); err != nil {
a.Close()
return nil, err
}
parent, err := os.OpenRoot(filepath.Dir(root))
if err != nil {
a.Close()
return nil, err
}
err = errors.Join(syncDirectory(parent), parent.Close())
if err != nil {
a.Close()
return nil, err
}
return a, nil
}
func (a *Archive) Close() error {
@@ -282,6 +302,22 @@ func (a *Archive) countRows(p Part, resources map[string]bool) (int64, error) {
}
defer f.Close()
dec := json.NewDecoder(io.LimitReader(f, a.maxBlobBytes+1))
if p.Kind == "schema" {
var catalog map[string][]map[string]json.RawMessage
if err := dec.Decode(&catalog); err != nil || len(catalog) != 6 {
return 0, errors.New("invalid source schema catalog")
}
for _, key := range []string{"columns", "constraints", "indexes", "triggers", "relations", "sequences"} {
if rows, ok := catalog[key]; !ok || rows == nil {
return 0, errors.New("incomplete source schema catalog")
}
}
var extra any
if dec.Decode(&extra) != io.EOF {
return 0, errors.New("trailing source schema catalog data")
}
return 1, nil
}
token, err := dec.Token()
if err != nil || token != json.Delim('[') {
return 0, errors.New("snapshot component must be a JSON row array")
@@ -401,7 +437,7 @@ func encodeManifest(m Manifest) ([]byte, error) {
seen := map[string]bool{}
for _, p := range m.Parts {
key := p.Kind + "/" + p.Name
if (!required[key] && !(p.Kind == "resource" && identifier(p.Name) && p.Count == 1)) || seen[key] || !validDigest(p.SHA256) || p.Bytes < 0 || p.Count < 0 {
if (!required[key] && !(p.Kind == "resource" && identifier(p.Name) && p.Count == 1) && !(key == "schema/migration-catalog" && p.Count == 1)) || seen[key] || !validDigest(p.SHA256) || p.Bytes < 0 || p.Count < 0 {
return nil, errors.New("invalid or nonknowledge snapshot component")
}
seen[key] = true