T1 page by cursor: a state page continues from an opaque cursor in sequence order
mesh/state.page reads a state from an ordered watch starting after the cursor's sequence, never a replay of the bucket per page: each kept message once across the pages of a read, a key's older kept revisions included, at most 768 KB a page, next the opaque cursor, empty at the end. A value written after the read reached its bucket comes marked seen-again (the cursor carries that mark; the runner keeps nothing per read); a deleted key gets no entry. A state kept one bucket per node is read one node's bucket after another. Builds: design 47 H2 §779, H-A-254, H-A-382
This commit is contained in:
@@ -67,7 +67,17 @@ func (c *catalogStandIn) handle(body json.RawMessage) (any, error) {
|
||||
// for a verb that sends chunks (design 47 G A-490m).
|
||||
func TestTheToolRunnerStartedByItsEntryServesABundleOverTheSeatListItReads(t *testing.T) {
|
||||
mesh := mt.New(t)
|
||||
mesh.Issue(t, mt.MembershipOf("ledger", "anchor", true, map[string][]string{"node-desk": {"who", "slow"}}))
|
||||
ledger := mt.MembershipOf("ledger", "anchor", true, map[string][]string{"node-desk": {"who", "slow"}})
|
||||
ledger.State = []bus.StateIssued{{Name: "pages", Bucket: "ledger_pages", Writes: true}}
|
||||
mesh.Issue(t, ledger)
|
||||
// a state of 10,000 keys of 300 bytes each, about four pages of 768 KB (design 47 H2 §779)
|
||||
pages := mesh.Bucket(t, "ledger_pages")
|
||||
value := []byte(`"` + strings.Repeat("v", 298) + `"`)
|
||||
for i := range 10000 {
|
||||
if _, err := pages.Put(fmt.Sprintf("k%05d", i), value); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
dir := t.TempDir()
|
||||
credential, _ := json.Marshal(bus.Credential{URL: mt.URL(t), Module: runtimeModule, Node: "anchor"})
|
||||
file := filepath.Join(dir, "broker")
|
||||
@@ -172,12 +182,60 @@ func TestTheToolRunnerStartedByItsEntryServesABundleOverTheSeatListItReads(t *te
|
||||
listings := catalog.listings
|
||||
catalog.mu.Unlock()
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if listings != 2 || len(fresh) != 1 || fresh[0]["call"] == nil || fresh[0]["call"] == "" {
|
||||
t.Errorf("the list was read %d times (want 2) and the holder of node-desk.fresh was asked %v (want once, with a call token)", listings, fresh)
|
||||
}
|
||||
mu.Unlock()
|
||||
|
||||
// a state read in pages by the bundle, each after the cursor the page before answered, delivers each kept message once
|
||||
// across the pages, and a key written again mid-read comes again in a later page marked seen-again (design 47 H2 §779,
|
||||
// H-A-382)
|
||||
type paged struct {
|
||||
Keys []string `json:"keys"`
|
||||
Again []string `json:"again"`
|
||||
Next string `json:"next"`
|
||||
Error any `json:"error"`
|
||||
}
|
||||
readPage := func(cursor string) paged {
|
||||
t.Helper()
|
||||
answered, err := asker.AskWithin("ledger.page", map[string]any{"cursor": cursor}, "", 30*time.Second)
|
||||
var p paged
|
||||
if err != nil || json.Unmarshal(answered.Result, &p) != nil || p.Error != nil {
|
||||
t.Fatalf("the page after %q was answered %.300s, %v", cursor, answered.Result, err)
|
||||
}
|
||||
return p
|
||||
}
|
||||
handed, again, count := map[string]int{}, []string{}, 0
|
||||
for p, n := readPage(""), 1; ; p, n = readPage(p.Next), n+1 {
|
||||
count++
|
||||
for _, k := range p.Keys {
|
||||
handed[k]++
|
||||
}
|
||||
again = append(again, p.Again...)
|
||||
if n == 1 {
|
||||
if len(p.Keys) == 0 || p.Keys[0] != "k00000" || p.Next == "" {
|
||||
t.Fatalf("the first page holds %d keys from %v and next %q; want k00000 first and more to follow", len(p.Keys), p.Keys[:min(1, len(p.Keys))], p.Next)
|
||||
}
|
||||
if _, err := pages.Put("k00000", []byte(`"again"`)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if p.Next == "" {
|
||||
break
|
||||
}
|
||||
if count > 20 {
|
||||
t.Fatal("the read did not end within 20 pages")
|
||||
}
|
||||
}
|
||||
if count < 3 || len(handed) != 10000 || len(again) != 1 || again[0] != "k00000" {
|
||||
t.Errorf("the read took %d pages, handed %d keys and marked %v seen-again; want at least 3 pages, 10,000 keys and k00000", count, len(handed), again)
|
||||
}
|
||||
for k, n := range handed {
|
||||
if n != 1 {
|
||||
t.Errorf("%s was handed %d times outside of seen-again, want once", k, n)
|
||||
}
|
||||
}
|
||||
|
||||
// at its stop the runner drains (design 47 H2 §813 (12), H-A-353; the bound 2 s here for the setting's 30 s): a call of 1 s in
|
||||
// flight is answered, one of 6 s is cut at the bound, said, and its caller answered nothing; a call after the stop is answered nothing
|
||||
type answer struct {
|
||||
@@ -220,7 +278,6 @@ func TestTheToolRunnerStartedByItsEntryServesABundleOverTheSeatListItReads(t *te
|
||||
if !journal.has("cut ledger's call hold") {
|
||||
t.Errorf("the journal does not say the cut call: %s", journal.String())
|
||||
}
|
||||
mu.Lock()
|
||||
}
|
||||
|
||||
// said is the runner's journal in a test, safe to read while it writes.
|
||||
|
||||
Reference in New Issue
Block a user