RG2: the registry's list pages by module and cursor; the sweep reads it page by page
oci-artifact-registry's list filters by name or module while it reads and answers at most 768 KB a page with capped, total and the cursor next, in order of the names; container-image-registry's answers whole as its form says. The registry takes a removal for retention whoever asks it: the refusal "not the sweep's" and its read of the sweep seat's holder go. The sweep reads the list from its cursor until no page is left. Builds: design 47 H2 §813 (7), §811, §779; H-A-350 DMC-10, H-A-399
This commit is contained in:
@@ -11,6 +11,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
@@ -244,26 +245,82 @@ func TestTheSeatSweepsAtABuildsEndOnARealBusWithNoLease(t *testing.T) {
|
||||
}
|
||||
time.Sleep(20 * time.Millisecond)
|
||||
}
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if len(acts) != 3 || !strings.Contains(acts[0], archiveRef("letta", 2)) || !strings.Contains(acts[1], imageRef("letta", 2)) ||
|
||||
!strings.Contains(acts[2], mirror(1)) {
|
||||
t.Fatalf("the hand acts recorded are %v; the store was asked %v", acts, door.asked)
|
||||
}
|
||||
if len(gone) != 1 || !strings.Contains(gone[0], `"fingerprint":"`+fp(2)+`"`) {
|
||||
t.Fatalf("artifacts-gone said %v", gone)
|
||||
}
|
||||
func() {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if len(acts) != 3 || !strings.Contains(acts[0], archiveRef("letta", 2)) || !strings.Contains(acts[1], imageRef("letta", 2)) ||
|
||||
!strings.Contains(acts[2], mirror(1)) {
|
||||
t.Fatalf("the hand acts recorded are %v; the store was asked %v", acts, door.asked)
|
||||
}
|
||||
if len(gone) != 1 || !strings.Contains(gone[0], `"fingerprint":"`+fp(2)+`"`) {
|
||||
t.Fatalf("artifacts-gone said %v", gone)
|
||||
}
|
||||
|
||||
// S25 through the real findings bucket: letta's wanted image missing from the store is a finding there.
|
||||
view, _ := mem.Listed(ctx)
|
||||
repo, digest, _ := splitReference(imageRef("letta", 1))
|
||||
delete(view.L.Repos[repo].Revisions, digest)
|
||||
if err := h.Observe(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if keys, _ := bus.Keys("artifact-store-tools." + FindingsState); len(keys) != 1 || keys[0] != "module.letta.ace.image-missing" {
|
||||
t.Fatalf("the findings are %v", keys)
|
||||
}
|
||||
// S25 through the real findings bucket: letta's wanted image missing from the store is a finding there.
|
||||
view, _ := mem.Listed(ctx)
|
||||
repo, digest, _ := splitReference(imageRef("letta", 1))
|
||||
delete(view.L.Repos[repo].Revisions, digest)
|
||||
if err := h.Observe(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if keys, _ := bus.Keys("artifact-store-tools." + FindingsState); len(keys) != 1 || keys[0] != "module.letta.ace.image-missing" {
|
||||
t.Fatalf("the findings are %v", keys)
|
||||
}
|
||||
}()
|
||||
|
||||
// Design 47 H2 §813 (7): a pass reads oci-artifact-registry's list page by page, each at most 768 KB, over 20,000
|
||||
// artifacts, so its view holds every one.
|
||||
t.Run("a pass reads 20,000 artifacts page by page", func(t *testing.T) {
|
||||
const many, pageBytes = 20000, 768 << 10
|
||||
repos := make([]map[string]any, many)
|
||||
for i := range repos {
|
||||
repos[i] = map[string]any{"name": fmt.Sprintf("m%05d/bundle", i), "manifests": []map[string]any{{
|
||||
"digest": fmt.Sprintf("sha256:%064x", i), "artifact": fmt.Sprintf("sha256:%064x", many+i), "size": 100}}}
|
||||
}
|
||||
pages := 0
|
||||
sub, err := nc.Subscribe("mesh.seat.oci-artifact-registry.tool.list.paged", func(m *nats.Msg) {
|
||||
var in struct{ Next string }
|
||||
_ = json.Unmarshal(m.Data, &in)
|
||||
page, size, next := []map[string]any{}, 0, ""
|
||||
for _, r := range repos {
|
||||
if r["name"].(string) <= in.Next {
|
||||
continue
|
||||
}
|
||||
raw, _ := json.Marshal(r)
|
||||
if size+len(raw)+1 > pageBytes-1024 { // its comma, and room for the answer's other fields
|
||||
next = page[len(page)-1]["name"].(string)
|
||||
break
|
||||
}
|
||||
size += len(raw) + 1
|
||||
page = append(page, r)
|
||||
}
|
||||
pages++
|
||||
out, _ := json.Marshal(map[string]any{"repositories": page, "next": next, "capped": next != "", "total": many})
|
||||
_ = m.Respond(out)
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() { _ = sub.Unsubscribe() }()
|
||||
store := &Store{Ask: func(key string, body any) (json.RawMessage, error) {
|
||||
if key != "seat:oci-artifact-registry.list" {
|
||||
return ask(key, body)
|
||||
}
|
||||
raw, _ := json.Marshal(body)
|
||||
m, err := nc.Request("mesh.seat.oci-artifact-registry.tool.list.paged", raw, 5*time.Second)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(m.Data) > pageBytes {
|
||||
t.Errorf("a page of %d bytes", len(m.Data))
|
||||
}
|
||||
return m.Data, nil
|
||||
}}
|
||||
got, err := store.ListOf("oci-artifact-registry", "")
|
||||
if err != nil || len(got) != many || got[many-1].Name != "m19999/bundle" || pages < 2 {
|
||||
t.Fatalf("read %d repositories in %d pages: %v", len(got), pages, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// findingsAt reads and writes the holder's own findings in its bucket, artifact-store-tools_findings.
|
||||
|
||||
@@ -79,20 +79,46 @@ type Store struct {
|
||||
Ask func(key string, body any) (json.RawMessage, error)
|
||||
}
|
||||
|
||||
// ListOf asks seat's list, of one repository or, with name empty, of every one.
|
||||
// ListOf asks seat's list, of one repository or, with name empty, of every one. oci-artifact-registry's list is read page by
|
||||
// page from its cursor until it answers none (design 47 H2 §813 (7), §779); container-image-registry's answers whole.
|
||||
func (s *Store) ListOf(seat, name string) ([]reg.Repository, error) {
|
||||
if s == nil || s.Ask == nil {
|
||||
return nil, fmt.Errorf("this process reaches no registry seat")
|
||||
}
|
||||
raw, err := s.Ask("seat:"+seat+"."+reg.VerbList, reg.ListInput{Name: name})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s's list: %w", seat, err)
|
||||
if seat != ociseat.Seat {
|
||||
raw, err := s.Ask("seat:"+seat+"."+reg.VerbList, reg.ListInput{Name: name})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s's list: %w", seat, err)
|
||||
}
|
||||
var a reg.ListAnswer
|
||||
if err := json.Unmarshal(raw, &a); err != nil {
|
||||
return nil, fmt.Errorf("%s's answer to list: %w", seat, err)
|
||||
}
|
||||
return a.Repositories, nil
|
||||
}
|
||||
var a reg.ListAnswer
|
||||
if err := json.Unmarshal(raw, &a); err != nil {
|
||||
return nil, fmt.Errorf("%s's answer to list: %w", seat, err)
|
||||
var out []reg.Repository
|
||||
seen := map[string]bool{}
|
||||
for in := (ociseat.ListInput{Name: name}); ; {
|
||||
raw, err := s.Ask("seat:"+seat+"."+reg.VerbList, in)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s's list: %w", seat, err)
|
||||
}
|
||||
var a struct {
|
||||
Repositories []reg.Repository `json:"repositories"`
|
||||
Next string `json:"next"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &a); err != nil {
|
||||
return nil, fmt.Errorf("%s's answer to list: %w", seat, err)
|
||||
}
|
||||
out = append(out, a.Repositories...)
|
||||
if a.Next == "" {
|
||||
return out, nil
|
||||
}
|
||||
if seen[a.Next] {
|
||||
return nil, fmt.Errorf("%s's list answered the cursor %q twice", seat, a.Next)
|
||||
}
|
||||
seen[a.Next], in.Next = true, a.Next
|
||||
}
|
||||
return a.Repositories, nil
|
||||
}
|
||||
|
||||
// View reads the store now, through both seats.
|
||||
|
||||
@@ -92,7 +92,20 @@ func (f *fakeStore) ask(t *testing.T) func(string, any) (json.RawMessage, error)
|
||||
repos = append(repos, reg.Repository{Name: name, Manifests: ms})
|
||||
}
|
||||
}
|
||||
return json.Marshal(reg.ListAnswer{Repositories: repos})
|
||||
if seat != "oci-artifact-registry" {
|
||||
return json.Marshal(reg.ListAnswer{Repositories: repos})
|
||||
}
|
||||
// oci-artifact-registry pages (design 47 H2 §813 (7)): one repository a page, after the one its cursor names.
|
||||
var page struct{ Next string }
|
||||
_ = json.Unmarshal(raw, &page)
|
||||
for len(repos) > 0 && repos[0].Name <= page.Next {
|
||||
repos = repos[1:]
|
||||
}
|
||||
next := ""
|
||||
if len(repos) > 1 {
|
||||
repos, next = repos[:1], repos[0].Name
|
||||
}
|
||||
return json.Marshal(map[string]any{"repositories": repos, "next": next, "capped": next != ""})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user