NATS3 (rest): the bus module plans from the catalog half of every watched branch, not from manifest-accepted
The keeper follows meshcatalogclient's branch follower and the seat list on its views reader, and plans again at each move of a branch's view, the registrations or the seat list. Each local name is planned from the first of the module's watched branches in its registration's order; another branch asking it with other settings is said drifted, naming the branch. A module of the new form whose resolved seat definition has a verb or an event gets its sent store; one including only parts, and a foundation part, none. A module in no watched branch's newest revision loses its plans key, its entries orphans. The sum of the caps counts the old sections the entries declare. The manifest consumes the catalog half's and the seat list's events and invokes their verbs; manifest-accepted and indexer_bus_state go. Builds: design 47 G §344, §433, §532, §533, §537, §538, §547, §591 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
"git.novox.be/novox/mesh-sdk/go/membership"
|
||||
"git.novox.be/novox/mesh-sdk/go/seatdef"
|
||||
)
|
||||
|
||||
// Module is the bus module's own name: the publisher of its events and its conditions.
|
||||
@@ -81,8 +82,8 @@ type EventFill struct {
|
||||
Cap int64 `json:"cap"`
|
||||
}
|
||||
|
||||
// Accepted is a manifest-accepted the keeper heard, or a module of its first view: the module, its manifest's digest,
|
||||
// the indexer's revision of the verdict (0 when the event does not say it yet), and its bus-state entries whole.
|
||||
// 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.
|
||||
type Accepted struct {
|
||||
Module string `json:"module"`
|
||||
Digest string `json:"digest"`
|
||||
@@ -90,10 +91,33 @@ type Accepted struct {
|
||||
BusState []catalogue.BusStateEntry `json:"bus-state"`
|
||||
}
|
||||
|
||||
// FirstView is the indexer's answer of indexer_bus_state: every accepted manifest's bus-state entries, by module.
|
||||
type FirstView struct {
|
||||
Revision uint64 `json:"revision"`
|
||||
Modules []Accepted `json:"modules"`
|
||||
// CatalogModule is one module of the catalog half for the bus module (design 47 G §344, §532, §533, §547): what its
|
||||
// watched branches' newest revisions ask of the bus, the seats they claim, whether one declares an event of its own,
|
||||
// whether it is a foundation part (it declares an old `objects` section `sent-objects`), and the caps of the old
|
||||
// sections it declares, in bytes.
|
||||
type CatalogModule struct {
|
||||
Accepted
|
||||
Claims []string `json:"claims,omitempty"`
|
||||
EmitsOwn bool `json:"emits-own,omitempty"`
|
||||
Foundation bool `json:"foundation,omitempty"`
|
||||
OldBytes int64 `json:"old-bytes,omitempty"`
|
||||
}
|
||||
|
||||
// Drift is a local name a later watched branch asks with other settings than the branch it is planned from (design 47
|
||||
// G §532): said as the bus module's drifted, naming the branch, and planned from nothing of that branch.
|
||||
type Drift struct {
|
||||
Module string `json:"module"`
|
||||
Local string `json:"local-name"`
|
||||
Branch string `json:"branch"`
|
||||
// From is the branch whose settings are planned.
|
||||
From string `json:"from"`
|
||||
}
|
||||
|
||||
// CatalogView is the catalog half as the bus module plans from it: every module in a watched branch's newest revision,
|
||||
// and the drifts between branches.
|
||||
type CatalogView struct {
|
||||
Modules []CatalogModule
|
||||
Drifts []Drift
|
||||
}
|
||||
|
||||
// Planned is the value of a module's key in StatePlans: the entries as planned, their digest and the revision of the verdict.
|
||||
@@ -123,7 +147,9 @@ type Asked struct {
|
||||
Revision uint64 `json:"revision"`
|
||||
Entries []catalogue.BusStateEntry `json:"entries"`
|
||||
Made map[string]Made `json:"made,omitempty"`
|
||||
At time.Time `json:"at"`
|
||||
// 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"`
|
||||
}
|
||||
|
||||
// Made is one entry as the keeper made it: its plan and what stands of it now.
|
||||
@@ -151,9 +177,13 @@ type Status struct {
|
||||
Pass time.Time `json:"pass"`
|
||||
// Limits are the bus's storage limits as last read (design 47 G §547): what `list` shows against the sum of the caps.
|
||||
Limits Limits `json:"limits,omitempty"`
|
||||
// FirstView is the indexer's first view: when asked, when answered and at which revision, or why not.
|
||||
// OldBytes is the sum of the caps of every old section the catalog graph's entries declare, in bytes, as last planned
|
||||
// (design 47 G §547, §591): counted in the sum of the bus's caps beside the entries made.
|
||||
OldBytes int64 `json:"old-sections-bytes,omitempty"`
|
||||
// FirstView is the catalog half's first views (design 47 G §614): when last planned from, when answered and at which
|
||||
// revision, or what it waits for.
|
||||
FirstView FirstViewStatus `json:"first-view"`
|
||||
// Heard is when the last manifest-accepted was heard, and Unanswered since when one has waited unhandled.
|
||||
// Heard is when the catalog half last moved, and Unanswered since when an event has waited unhandled.
|
||||
Heard time.Time `json:"heard,omitempty"`
|
||||
Unanswered time.Time `json:"unanswered,omitempty"`
|
||||
// Unsaid are the events the bus did not take, kept with their id and the subjects still to say them on, and
|
||||
@@ -191,10 +221,11 @@ type FirstViewStatus struct {
|
||||
Next time.Time `json:"next,omitempty"`
|
||||
}
|
||||
|
||||
// The first view's owner and verb (design 25 § 12.2).
|
||||
// The first view's seat and verb: the catalog half of each watched branch, read through the seat mesh-catalog's
|
||||
// `revision` (design 47 G §433, §614).
|
||||
const (
|
||||
FirstViewOwner = "mesh-delivery-indexer"
|
||||
FirstViewVerb = "indexer_bus_state"
|
||||
FirstViewOwner = "mesh-catalog"
|
||||
FirstViewVerb = "revision"
|
||||
)
|
||||
|
||||
// Bus is the bus as the keeper's own account reaches it.
|
||||
@@ -257,7 +288,7 @@ func (k *Keeper) capRoom(ctx context.Context, held *Asked, m *Made) error {
|
||||
}
|
||||
all := k.Held()
|
||||
all[held.Module] = *held
|
||||
sum := CapSum(all, held.Module, m.Plan.Local)
|
||||
sum := CapSum(all, held.Module, m.Plan.Local) + k.Status().OldBytes
|
||||
for _, o := range m.Plan.Objects {
|
||||
sum += o.Settings.MaxBytes
|
||||
}
|
||||
@@ -297,8 +328,12 @@ type Keeper struct {
|
||||
// Emit says one of the bus module's events (Saying); Say raises or clears a condition through the condition keeper.
|
||||
Emit func(s *Saying) error
|
||||
Say func(oc.Condition) error
|
||||
// View asks the indexer's indexer_bus_state.
|
||||
View func() (FirstView, error)
|
||||
// Catalog reads the catalog half of every watched branch as it stands (design 47 G §433, §532): an error while a
|
||||
// branch has no first view yet, when the keeper plans nothing. Seats are the seat list's definitions, each resolved
|
||||
// with the parts it includes (§537). Again asks every first view of the catalog half again, by hand.
|
||||
Catalog func() (CatalogView, error)
|
||||
Seats func() map[string]seatdef.Definition
|
||||
Again func() error
|
||||
// Act records a hand act through the seat mesh-hand-acts; Warrant reads the router's record of an ask.
|
||||
Act func(what, why, cause string) error
|
||||
Warrant func(askID string) (*oc.Ask, *oc.Warrant, error)
|
||||
@@ -417,81 +452,148 @@ func (k *Keeper) statusWritten(s Status, err error) {
|
||||
}
|
||||
}
|
||||
|
||||
// AskFirstView asks the indexer's first view once and applies it (design 25 § 12.2): every module it answers is
|
||||
// applied as an accepted verdict, a module the keeper holds and the view leaves out is kept (a set-aside manifest is
|
||||
// missing from it, never removed), and then check runs over what is held. It answers the error and when to ask again,
|
||||
// on the backoff from 10 s doubling to 5 min; the keeper's health is unhealthy meanwhile, naming the verb.
|
||||
func (k *Keeper) AskFirstView(wait time.Duration) (time.Duration, error) {
|
||||
// PlanCatalog plans from the catalog half as it stands (design 47 G §344, §433, §532, §537, §538): each module in a
|
||||
// watched branch's newest revision is applied (Heard), a module of the new form that sends gets its sent store, a drift
|
||||
// between branches is said once, and a module in no watched branch's newest revision has its plans key deleted, its
|
||||
// entries then orphans. Before every watched branch has its first view it plans nothing, and says what it waits for in
|
||||
// its status; the first plan checks what is held.
|
||||
func (k *Keeper) PlanCatalog() error {
|
||||
at := k.now()
|
||||
k.setStatus(func(s *Status) { s.FirstView.Asked = at })
|
||||
view, err := k.View()
|
||||
view, err := k.Catalog()
|
||||
if err != nil {
|
||||
next := wait * 2
|
||||
if wait <= 0 {
|
||||
next = 10 * time.Second
|
||||
}
|
||||
if next > 5*time.Minute {
|
||||
next = 5 * time.Minute
|
||||
}
|
||||
k.setStatus(func(s *Status) {
|
||||
s.FirstView.Error = fmt.Sprintf("%s.%s did not answer: %v", FirstViewOwner, FirstViewVerb, err)
|
||||
s.FirstView.Next = at.Add(next)
|
||||
})
|
||||
return next, err
|
||||
k.setStatus(func(s *Status) { s.FirstView.Asked, s.FirstView.Error = at, err.Error() })
|
||||
return err
|
||||
}
|
||||
k.mu.Lock()
|
||||
first := !k.viewed
|
||||
k.viewed = true
|
||||
k.mu.Unlock()
|
||||
k.setStatus(func(s *Status) {
|
||||
s.FirstView.Answered, s.FirstView.Revision, s.FirstView.Error, s.FirstView.Next = k.now(), view.Revision, "", time.Time{}
|
||||
})
|
||||
for _, a := range view.Modules {
|
||||
k.Heard(a)
|
||||
var revision uint64
|
||||
var old int64
|
||||
for _, m := range view.Modules {
|
||||
revision = max(revision, m.Revision)
|
||||
old += m.OldBytes
|
||||
}
|
||||
k.CheckAll()
|
||||
return 0, nil
|
||||
k.setStatus(func(s *Status) {
|
||||
s.FirstView.Asked, s.FirstView.Revision, s.FirstView.Error, s.FirstView.Next = at, revision, "", time.Time{}
|
||||
if s.FirstView.Answered.IsZero() {
|
||||
s.FirstView.Answered = at
|
||||
}
|
||||
s.OldBytes = old
|
||||
})
|
||||
var defs map[string]seatdef.Definition
|
||||
if k.Seats != nil {
|
||||
defs = k.Seats()
|
||||
}
|
||||
listed := map[string]bool{}
|
||||
for _, m := range view.Modules {
|
||||
listed[m.Module] = true
|
||||
k.Heard(m.Accepted)
|
||||
if !m.Foundation && Sends(m.Claims, m.EmitsOwn, defs) {
|
||||
k.Sends(m.Module)
|
||||
}
|
||||
}
|
||||
k.drifts(view.Drifts)
|
||||
gone := map[string]bool{}
|
||||
for module := range k.Held() {
|
||||
gone[module] = !listed[module]
|
||||
}
|
||||
if keys, err := k.Store.Keys(StatePlans); err == nil {
|
||||
for _, module := range keys {
|
||||
gone[module] = !listed[module]
|
||||
}
|
||||
}
|
||||
for _, module := range sortedKeys(gone) {
|
||||
if !gone[module] {
|
||||
continue
|
||||
}
|
||||
if _, ok := k.planned(module); ok {
|
||||
k.Heard(Accepted{Module: module, Revision: revision})
|
||||
}
|
||||
if err := k.Store.Delete(StatePlans, module); err != nil {
|
||||
k.logf("the plan of %s cannot be removed from its own %s: %v", module, StatePlans, err)
|
||||
}
|
||||
}
|
||||
if first {
|
||||
k.CheckAll()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Heard applies one accepted verdict (manifest-accepted, or a module of the first view): applied only when newer than
|
||||
// what the keeper holds for that module by the indexer's revision alone, so a replay never takes an entry back (a
|
||||
// verdict that says no revision is applied when its digest differs). Each entry asked is made where the bus lacks it;
|
||||
// each entry made that is no longer asked is an orphan. An empty verdict ("this module asks nothing now") ends the
|
||||
// module's key once nothing it made is held.
|
||||
// drifts says each drift once (design 47 G §532): kept in the module's key, said again only when the branch or the
|
||||
// settings planned change.
|
||||
func (k *Keeper) drifts(ds []Drift) {
|
||||
by := map[string]map[string]Drift{}
|
||||
for _, d := range ds {
|
||||
if by[d.Module] == nil {
|
||||
by[d.Module] = map[string]Drift{}
|
||||
}
|
||||
by[d.Module][d.Local] = d
|
||||
}
|
||||
for module, a := range k.Held() {
|
||||
if by[module] == nil && len(a.Drifts) > 0 {
|
||||
by[module] = map[string]Drift{}
|
||||
}
|
||||
}
|
||||
for _, module := range sortedKeys(by) {
|
||||
held, _, found := k.asked(module)
|
||||
if !found {
|
||||
held = Asked{V: 1, Module: module, At: k.now()}
|
||||
}
|
||||
now := by[module]
|
||||
changed := len(now) != len(held.Drifts)
|
||||
for local, d := range now {
|
||||
if held.Drifts[local] != d {
|
||||
changed = true
|
||||
var p Plan
|
||||
for _, e := range held.Entries {
|
||||
if e.Name == local {
|
||||
p, _ = PlanOf(module, e)
|
||||
}
|
||||
}
|
||||
p.Module, p.Local = module, local
|
||||
k.emit(EventDrifted, p, held.Revision, fmt.Sprintf("the branch %s asks %s of %s with other settings than the branch %s, whose are planned: nothing of %s is planned", d.Branch, local, module, d.From, d.Branch), nil, nil)
|
||||
}
|
||||
}
|
||||
if !changed {
|
||||
continue
|
||||
}
|
||||
held.Drifts = nil
|
||||
if len(now) > 0 {
|
||||
held.Drifts = now
|
||||
}
|
||||
if found || len(now) > 0 {
|
||||
k.write(held)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Heard applies one module's entry of the catalog half: it plans again only when its bus-state entries differ from those
|
||||
// it last planned (design 47 G §538), never on the manifest's digest, which changes with any field. Each entry asked is
|
||||
// made where the bus lacks it; each entry made that is no longer asked is an orphan. An entry that asks nothing ("this
|
||||
// module asks nothing now") ends the module's key once nothing it made is held.
|
||||
func (k *Keeper) Heard(a Accepted) {
|
||||
k.setStatus(func(s *Status) { s.Heard = k.now() })
|
||||
if !k.Viewed() {
|
||||
k.logf("manifest-accepted of %s heard before the first view: kept on the consumer until it is answered", a.Module)
|
||||
k.logf("the entry of %s is heard before the catalog half's first views: nothing is planned until they are in", a.Module)
|
||||
return
|
||||
}
|
||||
held, _, found := k.asked(a.Module)
|
||||
if found && a.Revision != 0 && a.Revision <= held.Revision {
|
||||
k.logf("manifest-accepted of %s at revision %d is not newer than the %d held: not applied", a.Module, a.Revision, held.Revision)
|
||||
return
|
||||
}
|
||||
if found && a.Revision == 0 && a.Digest != "" && a.Digest == held.Digest {
|
||||
return
|
||||
}
|
||||
if !found {
|
||||
held = Asked{V: 1, Module: a.Module}
|
||||
}
|
||||
if held.Made == nil {
|
||||
held.Made = map[string]Made{}
|
||||
}
|
||||
// It plans again only when its bus-state entries differ from those it last planned, never on the manifest's digest
|
||||
// (design 47 G §538).
|
||||
digest := EntriesDigest(a.BusState)
|
||||
if p, ok := k.planned(a.Module); ok && found && p.Digest == digest {
|
||||
held.Digest, held.At = a.Digest, k.now()
|
||||
if a.Revision > held.Revision {
|
||||
held.Revision = a.Revision
|
||||
if held.Digest != a.Digest || held.Revision != a.Revision {
|
||||
held.Digest, held.Revision, held.At = a.Digest, a.Revision, k.now()
|
||||
k.write(held)
|
||||
}
|
||||
k.write(held)
|
||||
return
|
||||
}
|
||||
held.Digest, held.Entries, held.At = a.Digest, a.BusState, k.now()
|
||||
if a.Revision > held.Revision {
|
||||
held.Revision = a.Revision
|
||||
}
|
||||
held.Digest, held.Entries, held.Revision, held.At = a.Digest, a.BusState, a.Revision, k.now()
|
||||
defer k.writePlan(a.Module, digest, held.Revision, a.BusState)
|
||||
asked := map[string]bool{}
|
||||
for _, e := range a.BusState {
|
||||
@@ -512,10 +614,10 @@ func (k *Keeper) Heard(a Accepted) {
|
||||
}
|
||||
m.Orphaned = true
|
||||
held.Made[local] = m
|
||||
k.emit(EventOrphaned, m.Plan, held.Revision, "no accepted manifest of "+a.Module+" asks for it now", nil, nil)
|
||||
k.emit(EventOrphaned, m.Plan, held.Revision, "no watched branch's newest revision of "+a.Module+" asks for it now", nil, nil)
|
||||
k.raise(conditionOrphaned, a.Module, local, occ.SeverityWarning, "Kept data no manifest asks for",
|
||||
"the operator's drop of it, or a manifest asking for it again",
|
||||
fmt.Sprintf("%s of %s is on the bus and no accepted manifest asks for it: it goes only by the bus module's drop, on your warrant (nats_drop), or a manifest asking for it again keeps it", BusName(a.Module, local), a.Module))
|
||||
fmt.Sprintf("%s of %s is on the bus and no watched branch's newest revision asks for it: it goes only by the bus module's drop, on your warrant (nats_drop), or a manifest asking for it again keeps it", BusName(a.Module, local), a.Module))
|
||||
}
|
||||
k.write(held)
|
||||
}
|
||||
@@ -895,7 +997,7 @@ func (k *Keeper) asked(module string) (Asked, uint64, bool) {
|
||||
// write keeps a module's key, or removes it when its manifest asks for nothing and nothing it made is held: a key goes
|
||||
// only so, never because a module is missing from a first view.
|
||||
func (k *Keeper) write(a Asked) {
|
||||
if len(a.Entries) == 0 && len(a.Made) == 0 {
|
||||
if len(a.Entries) == 0 && len(a.Made) == 0 && len(a.Drifts) == 0 {
|
||||
if err := k.Store.Delete(StateAsked, a.Module); err != nil {
|
||||
k.logf("the key of %s cannot be removed from its own %s: %v", a.Module, StateAsked, err)
|
||||
}
|
||||
|
||||
@@ -302,12 +302,12 @@ func (f *findingLog) Clear(_ context.Context, scope, id, kind, _ string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func newKeeper(view FirstView) (*Keeper, *fakeBus, *memStore, *said) {
|
||||
func newKeeper(view CatalogView) (*Keeper, *fakeBus, *memStore, *said) {
|
||||
bus, store, out := newFakeBus(), newMemStore(), &said{}
|
||||
at := time.Date(2026, 11, 4, 12, 0, 0, 0, time.UTC)
|
||||
k := &Keeper{Bus: bus, Store: store, Finding: &findingLog{}, Emit: out.emit, Say: out.say, Files: &memFiles{size: map[string]int64{}},
|
||||
View: func() (FirstView, error) { return view, nil },
|
||||
Now: func() time.Time { return at }}
|
||||
Catalog: func() (CatalogView, error) { return view, nil },
|
||||
Now: func() time.Time { return at }}
|
||||
return k, bus, store, out
|
||||
}
|
||||
|
||||
@@ -445,7 +445,7 @@ func TestTheKeeperMakesWhatAVerdictAsksForAndSaysIt(t *testing.T) {
|
||||
if len(bus.created) != 0 {
|
||||
t.Fatalf("created %v before the first view", bus.created)
|
||||
}
|
||||
if _, err := k.AskFirstView(0); err != nil {
|
||||
if err := k.PlanCatalog(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
k.Heard(Accepted{Module: "m", Digest: "d1", Revision: 3, BusState: []catalogue.BusStateEntry{drafts, log}})
|
||||
@@ -492,11 +492,66 @@ func TestTheKeeperMakesWhatAVerdictAsksForAndSaysIt(t *testing.T) {
|
||||
t.Errorf("the sent store was orphaned or removed: %+v %v", held.Made[SentLocal], bus.deleted)
|
||||
}
|
||||
}},
|
||||
{"a replay not newer is not applied", func(t *testing.T, k *Keeper, bus *fakeBus, out *said) {
|
||||
k.Heard(Accepted{Module: "m", Digest: "d2", Revision: 9, BusState: []catalogue.BusStateEntry{drafts}})
|
||||
k.Heard(Accepted{Module: "m", Digest: "d1", Revision: 4, BusState: nil})
|
||||
if a := k.Held()["m"]; a.Revision != 9 || len(a.Entries) != 1 || a.Made["drafts"].Orphaned {
|
||||
t.Errorf("held %+v: the replay at 4 took back what 9 asked", a)
|
||||
// §344, §533, §537: a module of the new form claiming a seat whose resolved definition has a verb or an event, or
|
||||
// declaring an event of its own, gets a sent store; a seat including only bodies, and a foundation part, none; a
|
||||
// definition gaining a verb gives its holder one at the next plan.
|
||||
{"the catalog half and the seat list plan the sent stores", func(t *testing.T, k *Keeper, bus *fakeBus, out *said) {
|
||||
defs := map[string]seatdef.Definition{
|
||||
"verbed": {Seat: "verbed", Verbs: []seatdef.Verb{{Name: "go"}}},
|
||||
"resolved": {Seat: "resolved", Includes: []string{"part"}, Verbs: []seatdef.Verb{{Name: "from-the-part"}}},
|
||||
"bodies": {Seat: "bodies", Includes: []string{"shared-bodies"}},
|
||||
}
|
||||
k.Seats = func() map[string]seatdef.Definition { return defs }
|
||||
k.Catalog = func() (CatalogView, error) {
|
||||
return CatalogView{Modules: []CatalogModule{
|
||||
{Accepted: Accepted{Module: "a"}, Claims: []string{"verbed"}},
|
||||
{Accepted: Accepted{Module: "b"}, Claims: []string{"resolved"}},
|
||||
{Accepted: Accepted{Module: "c"}, Claims: []string{"bodies"}},
|
||||
{Accepted: Accepted{Module: "d"}, Claims: []string{"verbed"}, Foundation: true},
|
||||
{Accepted: Accepted{Module: "e"}, EmitsOwn: true},
|
||||
}}, nil
|
||||
}
|
||||
_ = k.PlanCatalog()
|
||||
if want := "[OBJ_a_sent-objects OBJ_b_sent-objects OBJ_e_sent-objects]"; fmt.Sprint(bus.created) != want {
|
||||
t.Fatalf("created %v, want %s", bus.created, want)
|
||||
}
|
||||
defs["bodies"] = seatdef.Definition{Seat: "bodies", Includes: []string{"shared-bodies"}, Verbs: []seatdef.Verb{{Name: "new"}}}
|
||||
_ = k.PlanCatalog()
|
||||
if want := "[OBJ_a_sent-objects OBJ_b_sent-objects OBJ_e_sent-objects OBJ_c_sent-objects]"; fmt.Sprint(bus.created) != want {
|
||||
t.Errorf("created %v, want %s: the holder of a definition gaining a verb gets its store", bus.created, want)
|
||||
}
|
||||
}},
|
||||
// §532: a later branch asking a local name with other settings is said drifted once, naming the branch; §547: the
|
||||
// old sections' caps count in the sum.
|
||||
{"a drift between branches is said once, naming the branch", func(t *testing.T, k *Keeper, bus *fakeBus, out *said) {
|
||||
view := CatalogView{Modules: []CatalogModule{{Accepted: Accepted{Module: "m", Revision: 4, BusState: []catalogue.BusStateEntry{drafts}}, OldBytes: 8 * MiB}},
|
||||
Drifts: []Drift{{Module: "m", Local: "drafts", Branch: "feature", From: "main"}}}
|
||||
k.Catalog = func() (CatalogView, error) { return view, nil }
|
||||
_ = k.PlanCatalog()
|
||||
_ = k.PlanCatalog()
|
||||
if fmt.Sprint(out.events) != "[created m drafts drifted m drafts]" || !strings.Contains(out.bodies[1].Why, "the branch feature asks drafts") {
|
||||
t.Errorf("said %v (%+v): created from main, drifted once naming feature", out.events, out.bodies)
|
||||
}
|
||||
if k.Status().OldBytes != 8*MiB {
|
||||
t.Errorf("old sections %d: 8 MiB counted", k.Status().OldBytes)
|
||||
}
|
||||
}},
|
||||
// §538: a module in no watched branch's newest revision has its plans key deleted, its entries then orphans.
|
||||
{"a module no watched branch lists loses its plan, its entries orphans", func(t *testing.T, k *Keeper, bus *fakeBus, out *said) {
|
||||
k.Catalog = func() (CatalogView, error) {
|
||||
return CatalogView{Modules: []CatalogModule{{Accepted: Accepted{Module: "m", Revision: 9, BusState: []catalogue.BusStateEntry{drafts}}}}}, nil
|
||||
}
|
||||
_ = k.PlanCatalog()
|
||||
if _, ok := k.planned("m"); !ok {
|
||||
t.Fatal("m's plan is not kept")
|
||||
}
|
||||
k.Catalog = func() (CatalogView, error) { return CatalogView{}, nil }
|
||||
_ = k.PlanCatalog()
|
||||
if _, ok := k.planned("m"); ok {
|
||||
t.Error("m's plan is kept while no watched branch lists it")
|
||||
}
|
||||
if a := k.Held()["m"]; !a.Made["drafts"].Orphaned || len(bus.deleted) != 0 {
|
||||
t.Errorf("held %+v, deleted %v: drafts an orphan, kept on the bus", a, bus.deleted)
|
||||
}
|
||||
}},
|
||||
{"a grant not composed yet waits, then is made", func(t *testing.T, k *Keeper, bus *fakeBus, out *said) {
|
||||
@@ -641,12 +696,14 @@ func TestTheKeeperMakesWhatAVerdictAsksForAndSaysIt(t *testing.T) {
|
||||
}},
|
||||
{"a module missing from the first view keeps its key; one never made leaves none", func(t *testing.T, k *Keeper, bus *fakeBus, out *said) {
|
||||
k.Heard(Accepted{Module: "m", Revision: 1, BusState: []catalogue.BusStateEntry{drafts}})
|
||||
k.View = func() (FirstView, error) { return FirstView{Revision: 5}, nil }
|
||||
if _, err := k.AskFirstView(0); err != nil {
|
||||
t.Fatal(err)
|
||||
k.Catalog = func() (CatalogView, error) {
|
||||
return CatalogView{}, errors.New("the catalog half has no first view of main yet")
|
||||
}
|
||||
if err := k.PlanCatalog(); err == nil {
|
||||
t.Fatal("planned while a watched branch has no first view")
|
||||
}
|
||||
if a := k.Held()["m"]; len(a.Entries) != 1 || a.Made["drafts"].Orphaned {
|
||||
t.Errorf("held %+v: kept as asked, never orphaned by a first view", a)
|
||||
t.Errorf("held %+v: kept as asked, never orphaned while a first view waits", a)
|
||||
}
|
||||
bus.refuse["KV_n_x"] = errors.New("no")
|
||||
k.Heard(Accepted{Module: "n", Revision: 1, BusState: []catalogue.BusStateEntry{entry("x", catalogue.StorageKeyValue, catalogue.TemplateState, nil)}})
|
||||
@@ -687,19 +744,21 @@ func TestTheKeeperMakesWhatAVerdictAsksForAndSaysIt(t *testing.T) {
|
||||
if h := HealthOf(k.Status(), nil, 2, later); !strings.Contains(h.Why, "2 accepted verdict(s) wait") {
|
||||
t.Errorf("health %+v: names the verdicts waiting", h)
|
||||
}
|
||||
k.View = func() (FirstView, error) { return FirstView{}, errors.New("no responders") }
|
||||
k.Catalog = func() (CatalogView, error) {
|
||||
return CatalogView{}, errors.New("the catalog half has no first view of main yet")
|
||||
}
|
||||
k.mu.Lock()
|
||||
k.status.FirstView.Answered = time.Time{}
|
||||
k.mu.Unlock()
|
||||
if next, err := k.AskFirstView(10 * time.Second); err == nil || next != 20*time.Second {
|
||||
t.Fatalf("asked again in %s (%v): on the backoff", next, err)
|
||||
if err := k.PlanCatalog(); err == nil {
|
||||
t.Fatal("planned with no first view")
|
||||
}
|
||||
// The first view unanswered is unhealthy only past the bound since the start (review round 1: health.go:41).
|
||||
if h := HealthOf(k.Status(), nil, 0, at); !h.Healthy {
|
||||
t.Errorf("health %+v: healthy within the bound while the first view is asked", h)
|
||||
}
|
||||
k.FillPass()
|
||||
if h := HealthOf(k.Status(), nil, 0, later); h.Healthy || !strings.Contains(h.Why, "mesh-delivery-indexer.indexer_bus_state") {
|
||||
if h := HealthOf(k.Status(), nil, 0, later); h.Healthy || !strings.Contains(h.Why, "mesh-catalog.revision, has not answered: the catalog half has no first view of main yet") {
|
||||
t.Errorf("health %+v: unhealthy past the bound, naming the verb", h)
|
||||
}
|
||||
// What waits on its consumer unread is never skipped silently (review round 1: health.go:47).
|
||||
@@ -1157,24 +1216,26 @@ func TestTheKeeperMakesWhatAVerdictAsksForAndSaysIt(t *testing.T) {
|
||||
store := k.Store.(*memStore)
|
||||
var acts []string
|
||||
k.Act = func(what, why, cause string) error { acts = append(acts, cause+": "+what); return nil }
|
||||
k.View = func() (FirstView, error) {
|
||||
return FirstView{Revision: 8, Modules: []Accepted{{Module: "m", Revision: 8, BusState: []catalogue.BusStateEntry{drafts}}}}, nil
|
||||
k.Catalog = func() (CatalogView, error) {
|
||||
return CatalogView{Modules: []CatalogModule{{Accepted: Accepted{Module: "m", Revision: 8, BusState: []catalogue.BusStateEntry{drafts}}}}}, nil
|
||||
}
|
||||
again := 0
|
||||
k.Again = func() error { again++; return nil }
|
||||
raw, _ := json.Marshal(Request{ID: "r9", Verb: VerbFirstViewAgain, Why: "a verdict thought missed", Caller: "person.jo"})
|
||||
_, _ = store.Put(StateRequests, "r9", raw)
|
||||
k.ActOnRequests()
|
||||
raw, _, _, _ = store.Get(StateRequests, "r9")
|
||||
var got Request
|
||||
_ = json.Unmarshal(raw, &got)
|
||||
if got.Outcome != "the first view answered at revision 8" || fmt.Sprint(bus.created) != "[KV_m_drafts OBJ_m_drafts-objects]" ||
|
||||
len(acts) != 1 || !strings.Contains(acts[0], "nats_first_view_again: asked mesh-delivery-indexer.indexer_bus_state again by hand") {
|
||||
if got.Outcome != "the first views answered at revision 8" || fmt.Sprint(bus.created) != "[KV_m_drafts OBJ_m_drafts-objects]" || again != 1 ||
|
||||
len(acts) != 1 || !strings.Contains(acts[0], "nats_first_view_again: asked the catalog half's first views (mesh-catalog.revision) again by hand") {
|
||||
t.Errorf("ended %+v, created %v, recorded %v", got, bus.created, acts)
|
||||
}
|
||||
}},
|
||||
} {
|
||||
t.Run(row.name, func(t *testing.T) {
|
||||
k, bus, _, out := newKeeper(FirstView{Revision: 1})
|
||||
if _, err := k.AskFirstView(0); err != nil {
|
||||
k, bus, _, out := newKeeper(CatalogView{})
|
||||
if err := k.PlanCatalog(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
row.run(t, k, bus, out)
|
||||
@@ -1197,7 +1258,7 @@ func TestSends(t *testing.T) {
|
||||
}{
|
||||
{"a seat with a verb", []string{"verbed"}, false, true},
|
||||
{"a seat with an event", []string{"evented"}, false, true},
|
||||
{"a seat that includes parts", []string{"included"}, false, true},
|
||||
{"a seat that only includes parts (§537: resolved by the seat list, including alone counts for nothing)", []string{"included"}, false, false},
|
||||
{"a seat with neither", []string{"bare"}, false, false},
|
||||
{"a seat the list does not hold", []string{"unknown"}, false, false},
|
||||
{"an event of its own", nil, true, true},
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
// Package keeper is the bus module's keeper (novox/hq design 25 § 12.2-12.3, ADR 0595 §4-§6): it creates the bus state
|
||||
// every accepted manifest asks for in `requires`, compares what the bus holds with what was asked, finds orphans and
|
||||
// reads the fill of what refuses when full, and says each on the bus module's own events. It reads nothing of another
|
||||
// part's state: what to create comes on the indexer's manifest-accepted, and its first view from the indexer's tool
|
||||
// indexer_bus_state. Everything it touches it reaches through the interfaces in keeper.go; this file is pure.
|
||||
// part's state: what to create comes from the catalog half of each watched branch (design 47 G §433, §532). Everything it touches it reaches through the interfaces in keeper.go; this file is pure.
|
||||
package keeper
|
||||
|
||||
import (
|
||||
@@ -55,14 +54,14 @@ const StateObjectsCapMiB = 16
|
||||
|
||||
// Sends says whether a module sends (design 47 G §344): it claims a seat whose definition has a verb or an event, or it
|
||||
// declares an event of its own (emitsOwn). claims are the seats its catalog graph entry claims, defs the seat list's
|
||||
// definitions by seat; a claimed seat the list does not hold counts for nothing. A definition that includes parts takes
|
||||
// their verbs and events whole (seatdef.Resolve), so one counts as having some.
|
||||
// definitions by seat, each as the seat list answers that one seat, resolved with the parts it includes; a claimed seat
|
||||
// the list does not hold counts for nothing, and including parts alone counts for nothing (design 47 G §537).
|
||||
func Sends(claims []string, emitsOwn bool, defs map[string]seatdef.Definition) bool {
|
||||
if emitsOwn {
|
||||
return true
|
||||
}
|
||||
for _, c := range claims {
|
||||
if d, ok := defs[c]; ok && (len(d.Verbs) > 0 || len(d.Events) > 0 || len(d.Includes) > 0) {
|
||||
if d, ok := defs[c]; ok && (len(d.Verbs) > 0 || len(d.Events) > 0) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ const (
|
||||
VerbApply = "apply"
|
||||
VerbRecreate = "recreate"
|
||||
VerbDrop = "drop"
|
||||
// VerbFirstViewAgain asks the indexer's first view at once, by hand (design 25 § 12.2), beside the backoff.
|
||||
// VerbFirstViewAgain asks the catalog half's first views again at once, by hand (design 47 G §614).
|
||||
VerbFirstViewAgain = "first-view-again"
|
||||
)
|
||||
|
||||
@@ -175,13 +175,19 @@ func (k *Keeper) ActOnRequests() {
|
||||
|
||||
func (k *Keeper) act(r *Request) (string, error) {
|
||||
if r.Verb == VerbFirstViewAgain {
|
||||
_, err := k.AskFirstView(0)
|
||||
err := fmt.Errorf("the keeper follows no catalog half")
|
||||
if k.Again != nil {
|
||||
err = k.Again()
|
||||
}
|
||||
if err == nil {
|
||||
err = k.PlanCatalog()
|
||||
}
|
||||
s := k.Status().FirstView
|
||||
k.record(r, fmt.Sprintf("asked %s.%s again by hand: answered %v at revision %d", s.Owner, s.Verb, err == nil, s.Revision))
|
||||
k.record(r, fmt.Sprintf("asked the catalog half's first views (%s.%s) again by hand: answered %v at revision %d", s.Owner, s.Verb, err == nil, s.Revision))
|
||||
if err != nil {
|
||||
return "asked, not answered", err
|
||||
}
|
||||
return fmt.Sprintf("the first view answered at revision %d", s.Revision), nil
|
||||
return fmt.Sprintf("the first views answered at revision %d", s.Revision), nil
|
||||
}
|
||||
if !k.Viewed() {
|
||||
return "", fmt.Errorf("%w: the keeper holds no first view yet, so it acts on nothing", ErrNoWarrant)
|
||||
|
||||
Reference in New Issue
Block a user