Design 47 H1: the bus module counts every manifest's old-section entries as asked for (H-A-229) #723
@@ -45,11 +45,15 @@ func AsksOf(e catalog.CatalogEntry) (Asks, error) {
|
||||
return Asks{}, fmt.Errorf("the manifest of %s is not readable: %w", e.Module, err)
|
||||
}
|
||||
state := m.BusState
|
||||
// The old sections' entries are asked for too (design 47 H H-A-229, H-A-230), every manifest's, named and capped as
|
||||
// the grants part composes them.
|
||||
m.Module = cmp.Or(m.Module, e.Module)
|
||||
old := keeper.OldPlansOf(m)
|
||||
if e.Verdict != "" && e.Verdict != "accepted" {
|
||||
state = nil
|
||||
state, old = nil, nil
|
||||
}
|
||||
sum := sha256.Sum256(mustJSON(state))
|
||||
out := Asks{Accepted: keeper.Accepted{Module: e.Module, Digest: hex.EncodeToString(sum[:]), BusState: state},
|
||||
out := Asks{Accepted: keeper.Accepted{Module: e.Module, Digest: hex.EncodeToString(sum[:]), BusState: state, Old: old},
|
||||
EmitsOwn: len(m.Emits) > 0 || len(e.Streams) > 0}
|
||||
for _, c := range m.Claims {
|
||||
out.Claims = append(out.Claims, c.Name)
|
||||
@@ -81,7 +85,7 @@ type Branch struct {
|
||||
// branches in its registration's order (order: the registration's branches; a branch it does not name comes after, in
|
||||
// the order given) whose entry asks it; another branch asking that local name with other settings is a drift naming
|
||||
// the branch, and plans nothing. The module sends when a branch's entry says so; it is a foundation part, and its old
|
||||
// sections' caps are read, from the first branch.
|
||||
// sections' caps and entries are read, from the first branch (design 47 H H-A-229).
|
||||
func ViewOf(branches []Branch, order func(module string) []string) (keeper.CatalogView, error) {
|
||||
modules := map[string]bool{}
|
||||
for _, b := range branches {
|
||||
@@ -117,8 +121,8 @@ func ViewOf(branches []Branch, order func(module string) []string) (keeper.Catal
|
||||
return keeper.CatalogView{}, fmt.Errorf("the branch %s: %w", b.Name, err)
|
||||
}
|
||||
if i == 0 {
|
||||
cm = keeper.CatalogModule{Accepted: keeper.Accepted{Module: module, Digest: b.Entries[module].ManifestDigest, Revision: uint64(max(b.Revision, 0))},
|
||||
Foundation: a.Foundation, OldBytes: a.OldBytes}
|
||||
cm = keeper.CatalogModule{Accepted: keeper.Accepted{Module: module, Digest: b.Entries[module].ManifestDigest, Revision: uint64(max(b.Revision, 0)),
|
||||
Old: a.Accepted.Old}, Foundation: a.Foundation, OldBytes: a.OldBytes}
|
||||
}
|
||||
cm.EmitsOwn = cm.EmitsOwn || a.EmitsOwn
|
||||
for _, c := range a.Claims {
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
|
||||
"nats-tools/internal/keeper"
|
||||
)
|
||||
|
||||
func TestAsksOf(t *testing.T) {
|
||||
@@ -22,6 +27,42 @@ func TestAsksOf(t *testing.T) {
|
||||
if b.Accepted.Digest != a.Accepted.Digest {
|
||||
t.Errorf("the digest is of the bus-state asked alone: %s vs %s", b.Accepted.Digest, a.Accepted.Digest)
|
||||
}
|
||||
// Design 47 H H-A-229, H-A-230: the old sections of the artifact registry and the forge, as their manifests declare
|
||||
// them, are asked for under the bus names the grants part gives them, the names the live orphans of 2026-11-21 hold;
|
||||
// a manifest not accepted asks none.
|
||||
for _, row := range []struct{ module, sections, want string }{
|
||||
{"distribution", `{"state": ["transfers", {"name": "idle", "key-ttl": true}, "holds", "windows", "mirrors", "findings"],
|
||||
"streams": [{"name": "distribution-events", "events": ["old-name-closed"], "max-age-days": 7, "max-mib": 16}],
|
||||
"objects": [{"name": "incoming", "max-mib": 8192}]}`,
|
||||
"[KV_distribution_transfers KV_distribution_idle KV_distribution_holds KV_distribution_windows KV_distribution_mirrors KV_distribution_findings OBJ_distribution_incoming DISTRIBUTION_EVENTS]"},
|
||||
{"gitea", `{"state": ["bound", {"name": "idle", "key-ttl": true}, "transfers"], "objects": [{"name": "incoming", "max-mib": 2048}],
|
||||
"logs": [{"name": "calls", "max-mib": 8}]}`,
|
||||
"[KV_gitea_bound KV_gitea_idle KV_gitea_transfers OBJ_gitea_incoming LOG_gitea_calls]"},
|
||||
} {
|
||||
var m map[string]any
|
||||
if err := json.Unmarshal([]byte(row.sections), &m); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m["module"] = row.module
|
||||
a, err := AsksOf(catalog.CatalogEntry{Module: row.module, Verdict: "accepted", Manifest: m})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var names []string
|
||||
for _, p := range a.Accepted.Old {
|
||||
names = append(names, p.Objects[0].Stream())
|
||||
}
|
||||
if fmt.Sprint(names) != row.want {
|
||||
t.Errorf("%s asks %v of its old sections, want %s", row.module, names, row.want)
|
||||
}
|
||||
i := slices.IndexFunc(a.Accepted.Old, func(p keeper.Plan) bool { return p.Local == "incoming" })
|
||||
if i < 0 || a.Accepted.Old[i].Objects[0].Settings.MaxBytes != int64(m["objects"].([]any)[0].(map[string]any)["max-mib"].(float64))*keeper.MiB {
|
||||
t.Errorf("%s's incoming is not capped as declared: %+v", row.module, a.Accepted.Old)
|
||||
}
|
||||
if n, _ := AsksOf(catalog.CatalogEntry{Module: row.module, Verdict: "refused", Manifest: m}); len(n.Accepted.Old) != 0 {
|
||||
t.Errorf("a refused manifest of %s asks %v", row.module, n.Accepted.Old)
|
||||
}
|
||||
}
|
||||
if _, err := AsksOf(catalog.CatalogEntry{}); err == nil {
|
||||
t.Error("an entry with no module was read")
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
// newest revision lists, each local name from the first of its watched branches in its registration's order whose entry
|
||||
// asks it, another branch asking it with other settings a drift naming that branch; a branch the registration does not
|
||||
// name after; a verdict not accepted asks nothing; the claims of every branch; a foundation part and its old sections'
|
||||
// caps from the first branch.
|
||||
// caps and entries from the first branch (design 47 H H-A-229).
|
||||
func TestTheCatalogHalfIsReadPerWatchedBranch(t *testing.T) {
|
||||
entryOf := func(verdict string, manifest map[string]any) catalog.CatalogEntry {
|
||||
manifest["module"] = "m"
|
||||
@@ -44,17 +44,17 @@ func TestTheCatalogHalfIsReadPerWatchedBranch(t *testing.T) {
|
||||
want string
|
||||
}{
|
||||
{"one branch", []Branch{{Name: "main", Revision: 3, Entries: map[string]catalog.CatalogEntry{"m": main}}}, []string{"main"},
|
||||
"m 3 [drafts/key-value/state] [a] false 0;"},
|
||||
"m 3 [drafts/key-value/state] [a] false 0 0;"},
|
||||
{"a feature branch asking a local name with other settings drifts, its new one planned",
|
||||
[]Branch{{Name: "feature", Revision: 9, Entries: map[string]catalog.CatalogEntry{"m": feature}}, {Name: "main", Revision: 3, Entries: map[string]catalog.CatalogEntry{"m": main}}},
|
||||
[]string{"main", "feature"}, "m 3 [drafts/key-value/state log/stream/log] [a b] false 0; drifted m drafts feature from main"},
|
||||
[]string{"main", "feature"}, "m 3 [drafts/key-value/state log/stream/log] [a b] false 0 0; drifted m drafts feature from main"},
|
||||
{"the registration's order decides", []Branch{{Name: "main", Revision: 3, Entries: map[string]catalog.CatalogEntry{"m": main}}, {Name: "feature", Revision: 9, Entries: map[string]catalog.CatalogEntry{"m": feature}}},
|
||||
[]string{"feature"}, "m 9 [drafts/key-value/state log/stream/log] [b a] false 0; drifted m drafts main from feature"},
|
||||
[]string{"feature"}, "m 9 [drafts/key-value/state log/stream/log] [b a] false 0 0; drifted m drafts main from feature"},
|
||||
{"a verdict not accepted asks nothing", []Branch{{Name: "main", Revision: 3, Entries: map[string]catalog.CatalogEntry{"m": entryOf("refused", map[string]any{"bus-state": []any{state("")}})}}}, []string{"main"},
|
||||
"m 3 [] [] false 0;"},
|
||||
"m 3 [] [] false 0 0;"},
|
||||
{"a foundation part, its old sections counted", []Branch{{Name: "main", Revision: 3, Entries: map[string]catalog.CatalogEntry{"m": entryOf("accepted", map[string]any{
|
||||
"objects": []any{map[string]any{"name": "sent-objects", "max-mib": 256}}, "logs": []any{map[string]any{"name": "l", "max-mib": 4}}, "streams": []any{map[string]any{"name": "s"}}})}}}, []string{"main"},
|
||||
"m 3 [] [] true 1284;"},
|
||||
"m 3 [] [] true 1284 3;"},
|
||||
} {
|
||||
t.Run(row.name, func(t *testing.T) {
|
||||
v, err := ViewOf(row.branches, func(string) []string { return row.order })
|
||||
@@ -67,7 +67,7 @@ func TestTheCatalogHalfIsReadPerWatchedBranch(t *testing.T) {
|
||||
for _, e := range m.BusState {
|
||||
es = append(es, e.Name+"/"+e.Storage+"/"+e.Template)
|
||||
}
|
||||
got += fmt.Sprintf("%s %d [%s] %v %v %d;", m.Module, m.Revision, strings.Join(es, " "), m.Claims, m.Foundation, m.OldBytes/keeper.MiB)
|
||||
got += fmt.Sprintf("%s %d [%s] %v %v %d %d;", m.Module, m.Revision, strings.Join(es, " "), m.Claims, m.Foundation, m.OldBytes/keeper.MiB, len(m.Old))
|
||||
}
|
||||
for _, d := range v.Drifts {
|
||||
got += fmt.Sprintf(" drifted %s %s %s from %s", d.Module, d.Local, d.Branch, d.From)
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -84,11 +85,14 @@ type EventFill struct {
|
||||
|
||||
// Accepted is one module's entry as the catalog half's watched branches give it (design 47 G §344, §433, §532): the
|
||||
// module, its manifest's digest, the catalog revision of the branch it was read from, and its bus-state entries whole.
|
||||
// Old are the entries its old sections declare, as OldPlansOf names and caps them (design 47 H H-A-229, H-A-230): asked
|
||||
// for too, but never made by the keeper.
|
||||
type Accepted struct {
|
||||
Module string `json:"module"`
|
||||
Digest string `json:"digest"`
|
||||
Revision uint64 `json:"revision"`
|
||||
BusState []catalogue.BusStateEntry `json:"bus-state"`
|
||||
Old []Plan `json:"old-sections,omitempty"`
|
||||
}
|
||||
|
||||
// CatalogModule is one module of the catalog half for the bus module (design 47 G §344, §532, §533, §547): what its
|
||||
@@ -146,7 +150,9 @@ type Asked struct {
|
||||
Digest string `json:"digest,omitempty"`
|
||||
Revision uint64 `json:"revision"`
|
||||
Entries []catalogue.BusStateEntry `json:"entries"`
|
||||
Made map[string]Made `json:"made,omitempty"`
|
||||
// Old are the entries its old sections declare, as last planned (Accepted's Old; design 47 H H-A-229, H-A-230).
|
||||
Old []Plan `json:"old-sections,omitempty"`
|
||||
Made map[string]Made `json:"made,omitempty"`
|
||||
// Drifts are the local names a later watched branch asks with other settings, as last said (design 47 G §532).
|
||||
Drifts map[string]Drift `json:"drifts,omitempty"`
|
||||
At time.Time `json:"at"`
|
||||
@@ -259,7 +265,8 @@ type Limits struct {
|
||||
}
|
||||
|
||||
// CapSum is the sum, in bytes, of the caps of every object the entries made hold, but for the entry of skipModule and
|
||||
// skipLocal (design 47 G §547): what the bus's limits are read against. An entry never made, or refused, holds none.
|
||||
// skipLocal (design 47 G §547): what the bus's limits are read against. An entry never made, or refused, holds none, and
|
||||
// one an old objects, log or stream section keeps is counted once, in the old sections' caps (design 47 H H-A-229).
|
||||
func CapSum(held map[string]Asked, skipModule, skipLocal string) int64 {
|
||||
var sum int64
|
||||
for module, a := range held {
|
||||
@@ -267,6 +274,11 @@ func CapSum(held map[string]Asked, skipModule, skipLocal string) int64 {
|
||||
if (module == skipModule && local == skipLocal) || !(m.Created || m.Orphaned) {
|
||||
continue
|
||||
}
|
||||
// A kept entry of an objects, log or stream section is in the old sections' caps already; a state's is not
|
||||
// (design 47 G §547, H H-A-229).
|
||||
if p, kept := oldKept(a.Old, local, m); kept && p.Storage != catalogue.StorageKeyValue {
|
||||
continue
|
||||
}
|
||||
for _, o := range m.Plan.Objects {
|
||||
sum += o.Settings.MaxBytes
|
||||
}
|
||||
@@ -596,6 +608,15 @@ func (k *Keeper) Heard(a Accepted) {
|
||||
held.Made = map[string]Made{}
|
||||
}
|
||||
digest := EntriesDigest(a.BusState)
|
||||
if len(a.Old) > 0 {
|
||||
// The old sections' entries are planned too (design 47 H H-A-229): a module that declares none keeps its digest.
|
||||
raw, _ := json.Marshal(struct {
|
||||
BusState []catalogue.BusStateEntry `json:"bus-state"`
|
||||
Old []Plan `json:"old-sections"`
|
||||
}{a.BusState, a.Old})
|
||||
sum := sha256.Sum256(raw)
|
||||
digest = "sha256:" + hex.EncodeToString(sum[:])
|
||||
}
|
||||
if p, ok := k.planned(a.Module); ok && found && p.Digest == digest {
|
||||
if held.Digest != a.Digest || held.Revision != a.Revision {
|
||||
held.Digest, held.Revision, held.At = a.Digest, a.Revision, k.now()
|
||||
@@ -603,13 +624,18 @@ func (k *Keeper) Heard(a Accepted) {
|
||||
}
|
||||
return
|
||||
}
|
||||
held.Digest, held.Entries, held.Revision, held.At = a.Digest, a.BusState, a.Revision, k.now()
|
||||
held.Digest, held.Entries, held.Old, held.Revision, held.At = a.Digest, a.BusState, a.Old, a.Revision, k.now()
|
||||
defer k.writePlan(a.Module, digest, held.Revision, a.BusState)
|
||||
asked := map[string]bool{}
|
||||
for _, e := range a.BusState {
|
||||
asked[e.Name] = true
|
||||
k.makeEntry(&held, e)
|
||||
}
|
||||
for _, local := range sortedKeys(held.Made) {
|
||||
if !asked[local] && k.keepOld(&held, local) {
|
||||
asked[local] = true
|
||||
}
|
||||
}
|
||||
for _, local := range sortedKeys(held.Made) {
|
||||
m := held.Made[local]
|
||||
if asked[local] || m.Orphaned || local == SentLocal {
|
||||
@@ -650,6 +676,35 @@ func (k *Keeper) Sends(module string) {
|
||||
k.write(held)
|
||||
}
|
||||
|
||||
// keepOld keeps an entry the keeper made that an old section of the module declares under the same bus name (design 47
|
||||
// H H-A-229, H-A-230, H-A-231): never an orphan (one that was is asked for again, its condition cleared), compared with
|
||||
// the bus and grown to the declared cap, and rebuilt on request; the keeper creates none of its objects the bus lacks and
|
||||
// says no created for it, as the grants part makes and binds them. It answers whether an old section keeps it. An entry
|
||||
// never made is none of the keeper's: every other old-section entry is the grants part's alone.
|
||||
func (k *Keeper) keepOld(held *Asked, local string) bool {
|
||||
m := held.Made[local]
|
||||
p, ok := oldKept(held.Old, local, m)
|
||||
if !ok || !m.Created || local == SentLocal {
|
||||
return false
|
||||
}
|
||||
if m.Orphaned {
|
||||
m.Orphaned = false
|
||||
k.clear(conditionOrphaned, held.Module, local)
|
||||
}
|
||||
// Only the objects the keeper made are its own: one the old plan names beside them (a state's `<state>-objects` the
|
||||
// grants part made) is never compared, grown or rebuilt by the keeper (H-A-231).
|
||||
var objects []Object
|
||||
for _, o := range p.Objects {
|
||||
if slices.ContainsFunc(m.Plan.Objects, func(made Object) bool { return made.Stream() == o.Stream() }) {
|
||||
objects = append(objects, o)
|
||||
}
|
||||
}
|
||||
m.Plan.Objects = objects
|
||||
k.ensureMade(held, &m, false)
|
||||
held.Made[local] = m
|
||||
return true
|
||||
}
|
||||
|
||||
// makeEntry makes one asked entry where the bus lacks it, compares it where it holds it, and says what it did.
|
||||
func (k *Keeper) makeEntry(held *Asked, e catalogue.BusStateEntry) {
|
||||
module := held.Module
|
||||
@@ -679,7 +734,11 @@ func (k *Keeper) makeEntry(held *Asked, e catalogue.BusStateEntry) {
|
||||
|
||||
// ensure brings one planned entry onto the bus: each object the bus lacks created, a held one compared. A difference
|
||||
// that only grows is applied; any other is a drift, said and never fixed quietly.
|
||||
func (k *Keeper) ensure(held *Asked, m *Made) {
|
||||
func (k *Keeper) ensure(held *Asked, m *Made) { k.ensureMade(held, m, true) }
|
||||
|
||||
// ensureMade is ensure; with create false an object the bus lacks is left to the part that makes it (an old section's,
|
||||
// the grants part: design 47 H H-A-230) and nothing is created.
|
||||
func (k *Keeper) ensureMade(held *Asked, m *Made, create bool) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
asked, holds := map[string]Settings{}, map[string]Settings{}
|
||||
@@ -694,6 +753,9 @@ func (k *Keeper) ensure(held *Asked, m *Made) {
|
||||
m.Waiting = fmt.Sprintf("%s cannot be read: %v", o.Stream(), err)
|
||||
return
|
||||
}
|
||||
if !found && !create {
|
||||
continue
|
||||
}
|
||||
if !found {
|
||||
if err := k.capRoom(ctx, held, m); err != nil {
|
||||
if errors.Is(err, ErrRetry) {
|
||||
@@ -794,11 +856,16 @@ func (k *Keeper) CheckAll() []CheckLine {
|
||||
out = append(out, lineOf(module, local, m))
|
||||
continue
|
||||
}
|
||||
asked := false
|
||||
for _, e := range held.Entries {
|
||||
if e.Name == local {
|
||||
asked = true
|
||||
k.makeEntry(&held, e)
|
||||
}
|
||||
}
|
||||
if !asked {
|
||||
k.keepOld(&held, local)
|
||||
}
|
||||
out = append(out, lineOf(module, local, held.Made[local]))
|
||||
}
|
||||
k.write(held)
|
||||
|
||||
@@ -1112,6 +1112,90 @@ func TestTheKeeperMakesWhatAVerdictAsksForAndSaysIt(t *testing.T) {
|
||||
t.Errorf("the hand acts: %v", acts)
|
||||
}
|
||||
}},
|
||||
// Design 47 H H-A-229, H-A-230, H-A-231: an entry the keeper made, now declared in the module's old sections under
|
||||
// the same bus name, is asked for: its orphan cleared, grown to the declared cap, rebuilt on request; the keeper
|
||||
// creates nothing an old section declares and says no created for it.
|
||||
{"an entry an old section declares is no orphan and is rebuilt, nothing of the old sections made", func(t *testing.T, k *Keeper, bus *fakeBus, out *said) {
|
||||
store := k.Store.(*memStore)
|
||||
incoming := entry("incoming", catalogue.StorageObjectStore, catalogue.TemplateObjects, map[string]string{"max-mib": "8"})
|
||||
k.Heard(Accepted{Module: "m", Revision: 1, BusState: []catalogue.BusStateEntry{drafts, incoming}})
|
||||
k.Heard(Accepted{Module: "m", Revision: 2})
|
||||
if a := k.Held()["m"]; !a.Made["incoming"].Orphaned || !a.Made["drafts"].Orphaned {
|
||||
t.Fatalf("held %+v: both orphans once no section asks for them", a.Made)
|
||||
}
|
||||
delete(bus.held, "OBJ_m_drafts-objects")
|
||||
made := fmt.Sprint(bus.created)
|
||||
out.reset()
|
||||
old := OldPlansOf(catalogue.Manifest{Module: "m", State: []catalogue.StateDeclaration{{Name: "drafts"}, {Name: "bound"}},
|
||||
Objects: []catalogue.ObjectsDeclaration{{Name: "incoming", MaxMiB: 16}}})
|
||||
k.Heard(Accepted{Module: "m", Revision: 3, Old: old})
|
||||
a := k.Held()["m"]
|
||||
if a.Made["incoming"].Orphaned || a.Made["drafts"].Orphaned || len(a.Made) != 2 {
|
||||
t.Errorf("held %+v: incoming and drafts asked for by the old sections, bound none of the keeper's", a.Made)
|
||||
}
|
||||
if fmt.Sprint(bus.created) != made || len(out.events) != 0 || bus.held["OBJ_m_incoming"].MaxBytes != 16*MiB {
|
||||
t.Errorf("created %v (was %s), said %v, incoming held %+v: nothing made or said, grown to the declared 16 MiB",
|
||||
bus.created, made, out.events, bus.held["OBJ_m_incoming"])
|
||||
}
|
||||
if fmt.Sprint(out.conds) != "[cleared nats.orphaned.m_drafts cleared nats.orphaned.m_incoming]" {
|
||||
t.Errorf("conditions %v: both orphans cleared", out.conds)
|
||||
}
|
||||
k.CheckAll()
|
||||
if fmt.Sprint(bus.created) != made {
|
||||
t.Errorf("the check created %v (was %s): the grants part makes an old section's objects", bus.created, made)
|
||||
}
|
||||
binds, _ := occ.ActDigest(occ.Act{"verb": "recreate", "module": "m", "local": "incoming"})
|
||||
ask := oc.Ask{ID: "bus-9", Who: occ.Operator, Expires: occ.FormatTime(k.now().Add(time.Hour)), Options: []oc.Option{{ID: "go", Label: "Rebuild", Level: occ.Destroy, Binds: binds}}}
|
||||
w := &oc.Warrant{Ask: "bus-9", Asker: Module, Outcome: occ.OutcomeChosen, By: &oc.Person{Who: occ.Operator},
|
||||
Option: "go", Label: "Rebuild", Level: occ.Destroy, At: occ.FormatTime(k.now()), AskDigest: occ.Digest(ask)}
|
||||
k.Warrant = func(string) (*oc.Ask, *oc.Warrant, error) { return &ask, w, nil }
|
||||
out.reset()
|
||||
raw, _ := json.Marshal(Request{ID: "r9", Verb: VerbRecreate, Module: "m", Local: "incoming", Ask: "bus-9"})
|
||||
_, _ = store.Put(StateRequests, "r9", raw)
|
||||
k.ActOnRequests()
|
||||
raw, _, _, _ = store.Get(StateRequests, "r9")
|
||||
var got Request
|
||||
_ = json.Unmarshal(raw, &got)
|
||||
if got.Error != "" || fmt.Sprint(out.events) != "[recreated m incoming]" || bus.held["OBJ_m_incoming"].MaxBytes != 16*MiB {
|
||||
t.Errorf("request %+v, said %v, held %+v: rebuilt at the declared cap", got, out.events, bus.held["OBJ_m_incoming"])
|
||||
}
|
||||
}},
|
||||
// Design 47 H H-A-231, G §547: a state the keeper made as its bucket alone keeps only that bucket; the store beside it
|
||||
// the grants part made is neither compared, grown nor rebuilt by the keeper; a kept state's cap stays in the sum, a
|
||||
// kept objects section's is counted in the old sections' caps alone.
|
||||
{"a kept state's store made by the grants part is left alone, its bucket's cap summed", func(t *testing.T, k *Keeper, bus *fakeBus, out *said) {
|
||||
store := k.Store.(*memStore)
|
||||
incoming := entry("incoming", catalogue.StorageObjectStore, catalogue.TemplateObjects, map[string]string{"max-mib": "8"})
|
||||
k.Heard(Accepted{Module: "m", Revision: 1, BusState: []catalogue.BusStateEntry{incoming}})
|
||||
old := OldPlansOf(catalogue.Manifest{Module: "m", State: []catalogue.StateDeclaration{{Name: "findings"}},
|
||||
Objects: []catalogue.ObjectsDeclaration{{Name: "incoming", MaxMiB: 8}}})
|
||||
bucket := old[0].Objects[0]
|
||||
bus.held[bucket.Stream()] = bucket.Settings
|
||||
bus.held["OBJ_m_findings-objects"] = Settings{MaxBytes: 8 * MiB, Discard: DiscardNew}
|
||||
held := k.Held()["m"]
|
||||
held.Made["findings"] = Made{Plan: Plan{Module: "m", Local: "findings", Storage: catalogue.StorageKeyValue, Template: catalogue.TemplateState,
|
||||
Objects: []Object{bucket}}, Created: true, Orphaned: true}
|
||||
k.write(held)
|
||||
k.Heard(Accepted{Module: "m", Revision: 2, Old: old})
|
||||
k.CheckAll()
|
||||
if m := k.Held()["m"].Made["findings"]; m.Orphaned || len(m.Plan.Objects) != 1 || len(bus.updated) != 0 || m.Drift != "" {
|
||||
t.Errorf("findings %+v, updated %v: kept, its bucket alone, the grants part's store not grown", m, bus.updated)
|
||||
}
|
||||
if sum := CapSum(k.Held(), "", ""); sum != 64*MiB {
|
||||
t.Errorf("the sum is %d MiB, want 64: the kept state's bucket, not the kept objects section's store", sum/MiB)
|
||||
}
|
||||
binds, _ := occ.ActDigest(occ.Act{"verb": "recreate", "module": "m", "local": "findings"})
|
||||
ask := oc.Ask{ID: "bus-8", Who: occ.Operator, Expires: occ.FormatTime(k.now().Add(time.Hour)), Options: []oc.Option{{ID: "go", Label: "Rebuild", Level: occ.Destroy, Binds: binds}}}
|
||||
w := &oc.Warrant{Ask: "bus-8", Asker: Module, Outcome: occ.OutcomeChosen, By: &oc.Person{Who: occ.Operator},
|
||||
Option: "go", Label: "Rebuild", Level: occ.Destroy, At: occ.FormatTime(k.now()), AskDigest: occ.Digest(ask)}
|
||||
k.Warrant = func(string) (*oc.Ask, *oc.Warrant, error) { return &ask, w, nil }
|
||||
raw, _ := json.Marshal(Request{ID: "r8", Verb: VerbRecreate, Module: "m", Local: "findings", Ask: "bus-8"})
|
||||
_, _ = store.Put(StateRequests, "r8", raw)
|
||||
k.ActOnRequests()
|
||||
if fmt.Sprint(bus.deleted) != "[KV_m_findings]" || bus.held["OBJ_m_findings-objects"].MaxBytes != 8*MiB {
|
||||
t.Errorf("deleted %v, store held %+v: the recreate rebuilds the bucket alone", bus.deleted, bus.held["OBJ_m_findings-objects"])
|
||||
}
|
||||
}},
|
||||
{"a recreate rebuilds a drifted entry after a snapshot", func(t *testing.T, k *Keeper, bus *fakeBus, out *said) {
|
||||
store := k.Store.(*memStore)
|
||||
k.Heard(Accepted{Module: "m", Revision: 1, BusState: []catalogue.BusStateEntry{log}})
|
||||
|
||||
@@ -423,3 +423,70 @@ func Differs(asked, held Settings) string {
|
||||
add("key-ttl", asked.KeyTTL, held.KeyTTL)
|
||||
return strings.Join(out, "; ")
|
||||
}
|
||||
|
||||
// OldPlansOf are the entries a manifest declares in its old sections (state, objects, logs, streams), each named on the
|
||||
// bus and capped as the grants part composes it, by the SDK's one naming per section (design 47 H H-A-229, H-A-230): a
|
||||
// state `<module>_<state>` with its object store `<state>-objects` beside it (none for a state only read, or one whose
|
||||
// store's name is one of the module's own object buckets), an objects section `<module>_<name>`, a log
|
||||
// `LOG_<module>_<name>` and a stream its local name in capitals. They are asked for: an entry the keeper made under one
|
||||
// of their bus names is never an orphan, is kept, compared and grown to the declared cap, and rebuilt on request; the
|
||||
// keeper creates none of them and says no created for one (the grants part makes and binds them). Pure.
|
||||
func OldPlansOf(m catalogue.Manifest) []Plan {
|
||||
module := m.Module
|
||||
var out []Plan
|
||||
own := map[string]bool{}
|
||||
for _, o := range m.Objects {
|
||||
own[o.Name] = true
|
||||
}
|
||||
for _, s := range m.State {
|
||||
capMiB := int64(s.MaxMiB)
|
||||
if capMiB <= 0 {
|
||||
capMiB = StateCap / MiB
|
||||
}
|
||||
p := Plan{Module: module, Local: s.Name, Storage: catalogue.StorageKeyValue, Template: catalogue.TemplateState,
|
||||
Objects: []Object{{Kind: KindBucket, Name: buscompose.BucketName(module, s.Name),
|
||||
Settings: Settings{MaxBytes: capMiB * MiB, MaxAgeSeconds: int64(s.TTLSeconds), History: int64(max(s.History, 1)),
|
||||
Discard: DiscardNew, MaxMsgSize: ValueMost, KeyTTL: s.KeyTTL}}}}
|
||||
if objects := catalogue.StateObjectsName(s.Name); !s.ReadOnly && !own[objects] {
|
||||
objCap := int64(s.MaxMiB)
|
||||
if objCap <= 0 {
|
||||
objCap = StateObjectsCapMiB
|
||||
}
|
||||
objCap = min(max(objCap, catalogue.ObjectsLeastMiB), catalogue.ObjectsMostMiB)
|
||||
p.Objects = append(p.Objects, Object{Kind: KindObjects, Name: catalogue.ObjectsBucket(module, objects),
|
||||
Settings: Settings{MaxBytes: objCap * MiB, Discard: DiscardNew}})
|
||||
}
|
||||
out = append(out, p)
|
||||
}
|
||||
for _, o := range m.Objects {
|
||||
out = append(out, Plan{Module: module, Local: o.Name, Storage: catalogue.StorageObjectStore, Template: catalogue.TemplateObjects,
|
||||
Objects: []Object{{Kind: KindObjects, Name: o.Bucket(module), Settings: Settings{MaxBytes: int64(o.MaxMiB) * MiB, Discard: DiscardNew}}}})
|
||||
}
|
||||
for _, l := range m.Logs {
|
||||
out = append(out, Plan{Module: module, Local: l.Name, Storage: catalogue.StorageStream, Template: catalogue.TemplateLog,
|
||||
Objects: []Object{{Kind: KindStream, Name: buscompose.LogStreamName(module, l.Name), Subjects: []string{buscompose.LogSubject(module, l.Name) + ".>"},
|
||||
Settings: Settings{MaxBytes: int64(l.Cap()) * MiB, MaxAgeSeconds: days(int64(l.MaxAgeDays)), Discard: DiscardNew, MaxMsgSize: buscompose.LogMaxMessageBytes}}}})
|
||||
}
|
||||
for _, s := range m.Streams {
|
||||
discard := DiscardOld
|
||||
if s.KeepsHistory() {
|
||||
discard = DiscardNew
|
||||
}
|
||||
out = append(out, Plan{Module: module, Local: s.Name, Storage: catalogue.StorageStream,
|
||||
Objects: []Object{{Kind: KindStream, Name: s.BusName(), Settings: Settings{MaxBytes: int64(s.Cap()) * MiB,
|
||||
MaxAgeSeconds: days(int64(s.Days())), Discard: discard, WorkQueue: s.Retention == catalogue.StreamRetentionWorkQueue}}}})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// oldKept is the old-section plan that keeps the entry made under local, or false: one of olds of the same local name
|
||||
// whose objects are on the bus under the same names as the entry's (design 47 H H-A-229, H-A-230).
|
||||
func oldKept(olds []Plan, local string, m Made) (Plan, bool) {
|
||||
for _, p := range olds {
|
||||
if p.Local != local || len(p.Objects) == 0 || len(m.Plan.Objects) == 0 || p.Objects[0].Stream() != m.Plan.Objects[0].Stream() {
|
||||
continue
|
||||
}
|
||||
return p, true
|
||||
}
|
||||
return Plan{}, false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user