Design 47 H2's corrections: the gate's ledger lifetimes and owed acts, the bus module's recreate, gitea runs-as part 2 (issue 1984) #758

Merged
mesh-tools merged 51 commits from feat/47-H2-corrections into main 2026-11-25 20:11:52 +00:00
9 changed files with 207 additions and 95 deletions
Showing only changes of commit 9d7c4b2e8c - Show all commits
@@ -20,6 +20,7 @@ import (
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
meshcatalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
meshdelivery "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
stdio "git.novox.be/novox/mesh-sdk/go"
"github.com/nats-io/nats-server/v2/server"
"github.com/nats-io/nats.go"
@@ -134,10 +135,29 @@ type runtime struct {
operatorCancels []string
// owedSaid are the subjects of the seat events owed the gate said, in order (W11.17).
owedSaid []string
// endedSaid are the bodies of the record-ended events the gate said, in order (AC-G4a, AC-G4b).
endedSaid []json.RawMessage
// logs is what the bundle said in its journal.
logs *testLog
}
// endedSays are the end counts the gate said record-ended with for a record, in order.
func (r *runtime) endedSays(record string) []int64 {
r.mu.Lock()
defer r.mu.Unlock()
var out []int64
for _, raw := range r.endedSaid {
var e struct {
Record string `json:"record"`
Ends int64 `json:"ends"`
}
if json.Unmarshal(raw, &e) == nil && e.Record == record {
out = append(out, e.Ends)
}
}
return out
}
// journalHas is whether the bundle said a line in its journal holding every one of words.
func (r *runtime) journalHas(words ...string) bool {
r.logs.mu.Lock()
@@ -349,6 +369,11 @@ func (r *runtime) answer(m rpcMessage) {
r.operatorAsks = append(r.operatorAsks, a)
r.mu.Unlock()
}
if p.Subject == meshdelivery.SubjectRecordEnded {
r.mu.Lock()
r.endedSaid = append(r.endedSaid, p.Body)
r.mu.Unlock()
}
if strings.HasPrefix(p.Subject, "mesh.seat.mesh-delivery.event.owed.") {
r.mu.Lock()
r.owedSaid = append(r.owedSaid, p.Subject)
@@ -111,6 +111,35 @@ func TestAGateWholeTakesAMergeCallAndWatchesTheHeadsOverARealBus(t *testing.T) {
want.Round(time.Minute))
}
// AC-G4b (H-A-609 (2), H-A-617, H-A-728), over the bus: a mover-added counts its mover in the record its pipeline names, a
// pipeline-ended of a higher end count reopens the ended record, and its next end says record-ended with ends 2.
rt.until("the first end said record-ended with ends 1", eventWithin, func() bool {
says := rt.endedSays(instance)
return len(says) == 1 && says[0] == 1
})
b.publish(t, "mesh.seat.mesh-pipeline-runner.event.mover-added."+escaped+".1", map[string]any{"v": 1, "pipeline": recordMilestone(branch, 1),
"revision": 4, "module": "extra", "fingerprint": "x", "from": recordMilestone(branch, 1) + ".again.1"})
added, _ := MoverInstance(recordMilestone(branch, 1), "extra")
rt.until("the added mover counted in the record that carries its pipeline", eventWithin, func() bool {
b.mu.Lock()
defer b.mu.Unlock()
return strings.Contains(string(b.ledger.states[added]), `"module":"extra"`)
})
b.publish(t, "mesh.seat.mesh-pipeline-runner.event.pipeline-ended."+escaped+".1", map[string]any{"v": 1, "branch": branch, "source": 1,
"pipeline": recordMilestone(branch, 1), "outcome": "passed", "end-count": 2, "movers": []any{}})
rt.until("the record reopened by the pipeline's higher end", eventWithin, func() bool {
b.mu.Lock()
defer b.mu.Unlock()
reopened := Record{}
return json.Unmarshal(b.ledger.states[instance], &reopened) == nil && reopened.Ended == nil && reopened.PipelineEnds == 2
})
b.publish(t, "mesh.seat.mesh-wants.event.pipeline-wanted."+escaped+".1", map[string]any{"v": 1, "branch": branch,
"source": 1, "pipeline": recordMilestone(branch, 1), "outcome": "running"})
rt.until("the reopened record ended again with ends 2", eventWithin, func() bool {
says := rt.endedSays(instance)
return len(says) == 2 && says[1] == 2
})
// GT1 (design 47 H2 §809; H-A-385, H-A-391, H-A-453 (3), H-A-455): a record of 126 movers writes 127 entries, its head
// and one per mover, and its acts owed the forge each an entry of its own, none over 64 KiB, the head counting 126 and
// holding no act; an entry made too large raises record-too-large, and the record's end clears it.
@@ -194,6 +223,31 @@ func TestAGateWholeTakesAMergeCallAndWatchesTheHeadsOverARealBus(t *testing.T) {
rt.until("the journal line naming the record, the mover on test and both times", eventWithin, func() bool {
return rt.journalHas(instance2, late["module"].(string)+" on test", "after it ended")
})
// AC-G4a (H-A-597, H-A-609 (2)), over the bus: the late running said record-ended again with ends 2, and the same running
// heard again moves nothing and says nothing. A running from a machine that was away at the end cannot be heard here: no
// event of the gate's marks a machine away (only the unit tests mark one).
rt.until("record-ended said again with ends 2", eventWithin, func() bool {
says := rt.endedSays(instance2)
return len(says) == 2 && says[0] == 1 && says[1] == 2
})
endedAt := ended2.Ended.At
b.publish(t, "mesh.seat.node-engine.event.running.test."+late["module"].(string), map[string]any{"v": 1, "module": late["module"],
"node": "test", "fingerprint": late["fingerprint"], "at": time.Now().Add(time.Minute).UTC().Format(time.RFC3339)})
b.publish(t, "mesh.seat.mesh-pipeline-runner.event.mover-added."+escaped+".2", map[string]any{"v": 1, "pipeline": recordMilestone(branch, 2),
"revision": 4, "module": "witness", "fingerprint": "w", "from": recordMilestone(branch, 2) + ".again.1"})
witness, _ := MoverInstance(recordMilestone(branch, 2), "witness")
rt.until("the event heard after the repeated running", eventWithin, func() bool {
b.mu.Lock()
defer b.mu.Unlock()
return strings.Contains(string(b.ledger.states[witness]), `"module":"witness"`)
})
b.mu.Lock()
again := Record{}
err = json.Unmarshal(b.ledger.states[instance2], &again)
b.mu.Unlock()
if says := rt.endedSays(instance2); err != nil || again.Ends != 2 || !again.Ended.At.Equal(endedAt) || len(says) != 2 {
t.Errorf("a repeated running left the record at end %d, ended %v (was %v), said %v: want it unchanged, ends 2", again.Ends, again.Ended, endedAt, says)
}
// The seed (§768): every watched branch's first source revision at its head; its head-moved then holds nothing.
seeded := strings.Repeat("5", 40)
@@ -658,18 +658,88 @@ func TestTheBusModuleRunsWhole(t *testing.T) {
t.Errorf("the binding names ended-days %d, want 30: the bus holds every lifetime", got)
}
})
// Design 47 H2 H-A-600, H-A-615, H-A-621: nats_consumer_narrow on the real bus keeps the consumer's delivery position, delivers it
// no message of a removed subject, and refuses every filter, a subject not filtered and one the module's entry consumes.
t.Run("nats_consumer_narrow keeps a consumer's position and delivers none of a removed subject", func(t *testing.T) {
if _, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: "NARROW", Subjects: []string{"narrow.>"}}); err != nil {
t.Fatal(err)
// Design 47 H2 H-A-686, AC-G15b: a ledger holding messages and keys, recreated on the operator's warrant with a lifetime per
// message and per key turned on, keeps them all and takes the lifetime on its next write, the change entering through the
// request, the ask's warrant and the router's decided event as the live path does.
t.Run("a recreate on the warrant changes a ledger in place, keeping its messages and keys", func(t *testing.T) {
plain := entry("records", "ledger", "ledger", map[string]string{"max-mib": "4"})
plain.Configuration = map[string]json.RawMessage{"max-age-days": json.RawMessage("90")}
plain.Types = []catalogue.LedgerType{{Name: "record", EndsWith: "ended", Schema: map[string]catalogue.LedgerField{"ended": {Type: "map"}},
Operations: []catalogue.LedgerOperation{{Name: "end", Effect: catalogue.EffectSetFields, Fields: []string{"ended"}}}}}
accepted("rc", 20, plain)
eventually(t, "created rc records", saidHas("created rc records"))
snap, ok := held("rc_records_snapshot")
if !ok {
t.Fatal("the bus holds no rc_records_snapshot")
}
cons, err := js.CreateOrUpdateConsumer(ctx, "NARROW", jetstream.ConsumerConfig{Durable: "ace_nw", AckPolicy: jetstream.AckExplicitPolicy,
FilterSubjects: []string{"narrow.a", "narrow.b", "narrow.c"}})
for i := range 3 {
if _, err := js.Publish(ctx, strings.TrimSuffix(snap.Config.Subjects[0], ">")+fmt.Sprintf("k%d", i), []byte("x")); err != nil {
t.Fatal(err)
}
}
kv, err := js.KeyValue(ctx, "rc_records_state")
if err != nil {
t.Fatal(err)
}
for _, subject := range []string{"narrow.a", "narrow.c", "narrow.b"} {
for _, key := range []string{"a", "b"} {
if _, err := kv.Put(ctx, key, []byte("v")); err != nil {
t.Fatal(err)
}
}
ending := plain
ending.Configuration = map[string]json.RawMessage{"ended-days": json.RawMessage("30"), "max-age-days": json.RawMessage("90")}
accepted("rc", 21, ending)
eventually(t, "drifted rc records", saidHas("drifted rc records"))
r := keeper.Request{ID: "rc1", Verb: keeper.VerbRecreate, Module: "rc", Local: "records", Caller: "person.jo", Why: "take the lifetimes", At: time.Now(), AskExpires: time.Now().Add(keeper.AskLasts)}
a, err := askFor(r, "")
if err != nil {
t.Fatal(err)
}
r.Ask = a.ID
w := &oc.Warrant{Ask: a.ID, Asker: keeper.Module, Outcome: occ.OutcomeChosen, By: &oc.Person{Who: occ.Operator},
Option: "go", Label: "Rebuild", Level: occ.Approve, At: occ.FormatTime(time.Now()), AskDigest: occ.Digest(a)}
raw, _ := json.Marshal(map[string]any{"asker": keeper.Module, "ask": a, "state": "open", "warrant": w})
if _, err := asksKV.Put(ctx, keeper.Module+"."+a.ID, raw); err != nil {
t.Fatal(err)
}
raw, _ = json.Marshal(r)
if _, err := store.Put(keeper.StateRequests, r.ID, raw); err != nil {
t.Fatal(err)
}
body, _ := json.Marshal(w)
if _, err := js.Publish(ctx, DecidedSubject, body); err != nil {
t.Fatal(err)
}
eventually(t, "recreated rc records", saidHas("recreated rc records"))
snap, _ = held("rc_records_snapshot")
state, _ := held("KV_rc_records_state")
if snap.State.Msgs != 3 || state.State.Msgs != 2 || !snap.Config.AllowMsgTTL || !state.Config.AllowMsgTTL {
t.Errorf("the snapshot store holds %d messages (want 3, AllowMsgTTL %v), the state bucket %d keys (want 2, AllowMsgTTL %v): changed in place",
snap.State.Msgs, snap.Config.AllowMsgTTL, state.State.Msgs, state.Config.AllowMsgTTL)
}
msg := &nats.Msg{Subject: strings.TrimSuffix(snap.Config.Subjects[0], ">") + "late", Data: []byte("x"), Header: nats.Header{"Nats-TTL": []string{"60s"}}}
if _, err := js.PublishMsg(ctx, msg); err != nil {
t.Errorf("a message with a lifetime of its own is refused after the recreate: %v", err)
}
if _, err := kv.Create(ctx, "c", []byte("v"), jetstream.KeyTTL(time.Minute)); err != nil {
t.Errorf("a key with a lifetime of its own is refused after the recreate: %v", err)
}
if k.Held()["rc"].Made["records"].Drift != "" {
t.Errorf("the drift stays after the recreate: %s", k.Held()["rc"].Made["records"].Drift)
}
})
// Design 47 H2 H-A-600, H-A-615, H-A-621: nats_consumer_narrow on the real bus keeps the consumer's delivery position, delivers it
// no message of a removed subject, and refuses every filter, a subject not filtered and one the module's entry consumes.
t.Run("nats_consumer_narrow keeps a consumer's position and delivers none of a removed subject", func(t *testing.T) {
if _, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: "NARROW", Subjects: []string{"mesh.stream.nw.event.>"}}); err != nil {
t.Fatal(err)
}
cons, err := js.CreateOrUpdateConsumer(ctx, "NARROW", jetstream.ConsumerConfig{Durable: "ace_nw", AckPolicy: jetstream.AckExplicitPolicy,
FilterSubjects: []string{"mesh.stream.nw.event.a", "mesh.stream.nw.event.b", "mesh.stream.nw.event.c"}})
if err != nil {
t.Fatal(err)
}
for _, subject := range []string{"mesh.stream.nw.event.a", "mesh.stream.nw.event.c", "mesh.stream.nw.event.b"} {
if _, err := js.Publish(ctx, subject, []byte(subject)); err != nil {
t.Fatal(err)
}
@@ -684,7 +754,7 @@ func TestTheBusModuleRunsWhole(t *testing.T) {
before, _ := cons.Info(ctx)
bus := func(context.Context) (jetstream.JetStream, func(), error) { return js, func() {}, nil }
accepted := func() (map[string]keeper.Planned, error) { return map[string]keeper.Planned{"nw": {Module: "nw"}}, nil }
consumes := func(context.Context, string) ([]string, error) { return []string{"narrow.a"}, nil }
consumes := func(context.Context, string) ([]string, error) { return []string{"nw.a"}, nil }
var handActs []meshhandactsclient.Request
record := func(q meshhandactsclient.Request) error { handActs = append(handActs, q); return nil }
call := func(remove ...any) (any, error) {
@@ -694,32 +764,32 @@ func TestTheBusModuleRunsWhole(t *testing.T) {
remove []any
want string
}{
"a subject the entry still consumes": {[]any{"narrow.a"}, "still consumes narrow.a"},
"a subject it does not filter": {[]any{"narrow.b", "narrow.d"}, "does not filter narrow.d"},
"a subject the entry still consumes": {[]any{"mesh.stream.nw.event.a"}, "still consumes mesh.stream.nw.event.a"},
"a subject it does not filter": {[]any{"mesh.stream.nw.event.b", "mesh.stream.nw.event.d"}, "does not filter mesh.stream.nw.event.d"},
} {
if _, err := call(c.remove...); err == nil || !strings.Contains(err.Error(), c.want) {
t.Errorf("%s: %v, want a refusal saying %q", what, err, c.want)
}
}
consumes = func(context.Context, string) ([]string, error) { return nil, nil }
if _, err := call("narrow.a", "narrow.b", "narrow.c"); err == nil || !strings.Contains(err.Error(), "takes every filter") {
if _, err := call("mesh.stream.nw.event.a", "mesh.stream.nw.event.b", "mesh.stream.nw.event.c"); err == nil || !strings.Contains(err.Error(), "takes every filter") {
t.Errorf("removing every filter: %v, want a refusal", err)
}
if len(handActs) != 0 {
t.Errorf("a refused narrowing recorded hand acts %v", handActs)
}
got, err := call("narrow.c")
got, err := call("mesh.stream.nw.event.c")
if err != nil {
t.Fatal(err)
}
after, _ := cons.Info(ctx)
if n := got.(ConsumerNarrowed); fmt.Sprint(n.After) != "[narrow.a narrow.b]" || len(handActs) != 1 || handActs[0].Cause != "consumer-narrow" {
if n := got.(ConsumerNarrowed); fmt.Sprint(n.After) != "[mesh.stream.nw.event.a mesh.stream.nw.event.b]" || len(handActs) != 1 || handActs[0].Cause != "consumer-narrow" {
t.Errorf("narrowed %+v with hand acts %v", n, handActs)
}
if after.Delivered.Stream != before.Delivered.Stream || after.Delivered.Consumer != before.Delivered.Consumer || after.Config.AckWait != before.Config.AckWait || fmt.Sprint(after.Config.FilterSubjects) != "[narrow.a narrow.b]" {
if after.Delivered.Stream != before.Delivered.Stream || after.Delivered.Consumer != before.Delivered.Consumer || after.Config.AckWait != before.Config.AckWait || fmt.Sprint(after.Config.FilterSubjects) != "[mesh.stream.nw.event.a mesh.stream.nw.event.b]" {
t.Errorf("the consumer after is %+v, before %+v: its position and its other settings kept, its filters narrowed", after, before)
}
if _, err := js.Publish(ctx, "narrow.c", []byte("late")); err != nil {
if _, err := js.Publish(ctx, "mesh.stream.nw.event.c", []byte("late")); err != nil {
t.Fatal(err)
}
next, err := cons.Fetch(5, jetstream.FetchMaxWait(time.Second))
@@ -731,8 +801,8 @@ func TestTheBusModuleRunsWhole(t *testing.T) {
delivered = append(delivered, m.Subject())
_ = m.Ack()
}
if fmt.Sprint(delivered) != "[narrow.b]" {
t.Errorf("delivered %v after the narrowing: the one narrow.b still owed, and none of narrow.c", delivered)
if fmt.Sprint(delivered) != "[mesh.stream.nw.event.b]" {
t.Errorf("delivered %v after the narrowing: the one mesh.stream.nw.event.b still owed, and none of mesh.stream.nw.event.c", delivered)
}
})
t.Run("nats_first_view_again asks at once and records the hand act", func(t *testing.T) {
@@ -757,71 +827,3 @@ func entry(name, storage, template string, options map[string]string) catalogue.
}
return e
}
// Design 47 H2 H-A-686: the change the bus takes in place keeps what the object holds. On the real bus, a stream holding
// messages is changed to a shorter age, a lifetime per message and a refusal when full, keeps its messages, and takes a lifetime
// on its next write; a bucket changed to a lifetime per key keeps its keys.
func TestTheBusTakesARecreatesChangeInPlace(t *testing.T) {
s, err := server.NewServer(&server.Options{Port: -1, JetStream: true, StoreDir: t.TempDir(), NoLog: true, NoSigs: true})
if err != nil {
t.Fatal(err)
}
go s.Start()
if !s.ReadyForConnections(5 * time.Second) {
t.Fatal("the server did not start")
}
defer s.Shutdown()
nc, err := nats.Connect(s.ClientURL())
if err != nil {
t.Fatal(err)
}
defer nc.Close()
js, _ := jetstream.New(nc)
ctx := context.Background()
bus := keeper.JetStream{JS: js}
stream := keeper.Object{Kind: keeper.KindStream, Name: "m_events", Subjects: []string{"m.events.>"},
Settings: keeper.Settings{MaxBytes: 4 << 20, MaxAgeSeconds: 0, Discard: keeper.DiscardOld}}
bucket := keeper.Object{Kind: keeper.KindBucket, Name: "m_state", Settings: keeper.Settings{MaxBytes: 4 << 20, History: 1, Discard: keeper.DiscardNew}}
for _, o := range []keeper.Object{stream, bucket} {
if err := bus.Create(ctx, o); err != nil {
t.Fatal(err)
}
}
for i := range 5 {
if _, err := js.Publish(ctx, fmt.Sprintf("m.events.%d", i), []byte("x")); err != nil {
t.Fatal(err)
}
}
kv, _ := js.KeyValue(ctx, "m_state")
for _, k := range []string{"a", "b"} {
if _, err := kv.Put(ctx, k, []byte("v")); err != nil {
t.Fatal(err)
}
}
stream.Settings = keeper.Settings{MaxBytes: 4 << 20, MaxAgeSeconds: 3600, Discard: keeper.DiscardNew, KeyTTL: true}
bucket.Settings.KeyTTL = true
for _, o := range []keeper.Object{stream, bucket} {
if err := bus.Update(ctx, o); err != nil {
t.Fatalf("%s: %v", o.Stream(), err)
}
}
held, fill, _, err := bus.Held(ctx, stream)
if err != nil || fill.Messages != 5 || held.MaxAgeSeconds != 3600 || held.Discard != keeper.DiscardNew || !held.KeyTTL {
t.Fatalf("the stream holds %+v, %+v (%v): it keeps its messages and takes the settings", held, fill, err)
}
msg := &nats.Msg{Subject: "m.events.9", Data: []byte("x"), Header: nats.Header{"Nats-TTL": []string{"60s"}}}
if _, err := js.PublishMsg(ctx, msg); err != nil {
t.Fatalf("a message with a lifetime of its own is refused after the change: %v", err)
}
if _, fill, _, _ := bus.Held(ctx, bucket); fill.Messages != 2 {
t.Fatalf("the bucket holds %d keys, want 2", fill.Messages)
}
if _, err := kv.Create(ctx, "c", []byte("v"), jetstream.KeyTTL(time.Minute)); err != nil {
t.Fatalf("a key with a lifetime of its own is refused after the change: %v", err)
}
// A held lifetime is never turned off by an Update: the bus would refuse it, and the keeper's comparison matches it.
stream.Settings.KeyTTL = false
if err := bus.Update(ctx, stream); err != nil {
t.Fatalf("an ask of no lifetime over a held one: %v", err)
}
}
+14 -1
View File
@@ -25,6 +25,7 @@ import (
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
stdio "git.novox.be/novox/mesh-sdk/go"
"git.novox.be/novox/mesh-sdk/go/buscompose"
"github.com/nats-io/nats.go"
"github.com/nats-io/nats.go/jetstream"
@@ -537,7 +538,7 @@ func NarrowConsumer(ctx context.Context, bus Bus, accepted acceptedModules, cons
return nil, fmt.Errorf("what %s consumes cannot be read (%v), so nothing was narrowed", module, err)
}
for _, subject := range remove {
if slices.Contains(still, subject) {
if stillConsumed(still, subject) {
return nil, fmt.Errorf("%s still consumes %s, its accepted manifest says so: it is not removed from %s; nothing was narrowed", module, subject, durable)
}
}
@@ -815,3 +816,15 @@ func PurgeStream(ctx context.Context, bus Bus, said Said, a map[string]any) (any
}
return out, nil
}
// stillConsumed says whether a filter subject of a durable is one of the words the module's entry `consumes`: a word is
// `<emitter>.<event>` and its filter is the bus subject that names the event in a namespace (`mesh.mod.<emitter>.event.<event>`,
// the seat's or the stream's), so the subject goes to its word by the mesh-sdk's own mapping before the two are compared, a
// word with a wildcard standing for the subjects it overlaps (H-A-615, H-A-621). A subject that is no event's is compared as it is.
func stillConsumed(consumes []string, subject string) bool {
word := subject
if name, _, ok := buscompose.EventName(subject); ok {
word = name
}
return slices.ContainsFunc(consumes, func(c string) bool { return buscompose.Overlaps(c, word) })
}
+3 -3
View File
@@ -189,8 +189,8 @@ func askFor(r keeper.Request, explained string) (oc.Ask, error) {
OnExpiry: "nothing is removed and the entry stays as it is",
About: keeper.ConditionKey(map[string]string{keeper.VerbDrop: "orphaned", keeper.VerbRecreate: "drifted"}[r.Verb], r.Module, r.Local),
Headline: fmt.Sprintf("%s's kept data %s: %s it?", r.Module, r.Local, what),
Explanation: fmt.Sprintf("%s asks to %s %s on the bus, %s. A snapshot of it is taken first; its data is lost from the bus.",
r.Caller, what, name, r.Why) + explained,
Explanation: fmt.Sprintf("%s asks to %s %s on the bus, %s. A snapshot of it is taken first.", r.Caller, what, name, r.Why) +
map[bool]string{true: " Its data is lost from the bus."}[r.Verb == keeper.VerbDrop] + explained,
Options: []oc.Option{
{ID: "go", Label: strings.ToUpper(what[:1]) + what[1:], Does: fmt.Sprintf("%s %s after a snapshot", what, name), Level: occ.Approve, Binds: binds},
{ID: "keep", Label: "Keep it", Does: "nothing is removed", Level: occ.Acknowledge},
@@ -349,7 +349,7 @@ func requestTools(rs requestStore) []stdio.Tool {
firstView,
tool(keeper.VerbCreate, "Create one entry of a module's kept data on the bus now, as its accepted manifest asks for it (design 25 § 12.3): handed to the bus module's keeper, which alone may create, and recorded as a hand act."),
tool(keeper.VerbApply, "Apply what a module's manifest asks of one entry where the bus holds less (a larger cap, a longer age): only a difference that grows; handed to the keeper and recorded as a hand act."),
tool(keeper.VerbRecreate, "Rebuild one entry whose settings drifted in a way that does not grow: the operator is asked first, and the keeper acts only on their warrant, after a snapshot of the entry. Its data is lost from the bus (the snapshot keeps it). Dangerous."),
tool(keeper.VerbRecreate, "Rebuild one entry whose settings drifted in a way that does not grow: the operator is asked first, and the keeper acts only on their warrant, after a snapshot of the entry. The ask names, per object, what is kept and what is made empty (the snapshot keeps the data). Dangerous."),
tool(keeper.VerbDrop, "Remove one orphan, an entry no accepted manifest asks for: the operator is asked first, and the keeper acts only on their warrant, after a snapshot of the entry. Dangerous."),
}
}
@@ -236,4 +236,11 @@ func TestTheAskOfARecreateNamesEachObjectAndWhatItRemoves(t *testing.T) {
if err != nil || !strings.Contains(ask.Explanation, "42 messages older than the age") {
t.Fatalf("the ask %+v %v", ask, err)
}
// The recreate's words come from the per-object lines, which keep the data: it never says the data is lost (H-A-686 (3)).
if strings.Contains(ask.Explanation, "lost from the bus") {
t.Errorf("the recreate's ask says its data is lost: %s", ask.Explanation)
}
if drop, _ := askFor(keeper.Request{Verb: keeper.VerbDrop, Module: "m", Local: "records", Why: "w", Caller: "c", AskExpires: now}, ""); !strings.Contains(drop.Explanation, "lost from the bus") {
t.Errorf("the drop's ask does not say its data is lost: %s", drop.Explanation)
}
}
+4 -3
View File
@@ -282,14 +282,15 @@ func TestTheRemovalToolsRefuseBeforeTheyReachTheBus(t *testing.T) {
{"nats_consumer_narrow", map[string]any{"stream": "EVENTS", "durable": "novox_m", "remove": []any{"a.b"}}, "why is required"},
{"nats_consumer_narrow", map[string]any{"stream": "EVENTS", "durable": "novox_m", "why": "x"}, "remove is required"},
{"nats_consumer_narrow", map[string]any{"stream": "A.B", "durable": "d", "remove": []any{"a"}, "why": "x"}, "stream and durable are required"},
{"nats_consumer_narrow", map[string]any{"stream": "EVENTS", "durable": "novox_m", "remove": []any{"mesh.m.still.>"}, "why": "x"}, "m still consumes mesh.m.still.>"},
{"nats_consumer_narrow", map[string]any{"stream": "EVENTS", "durable": "novox_m_tools", "remove": []any{"mesh.m.still.>"}, "why": "x"}, "m still consumes mesh.m.still.>"},
{"nats_consumer_narrow", map[string]any{"stream": "EVENTS", "durable": "novox_m", "remove": []any{"mesh.mod.m.event.still.taken"}, "why": "x"}, "m still consumes mesh.mod.m.event.still.taken"},
{"nats_consumer_narrow", map[string]any{"stream": "EVENTS", "durable": "novox_m", "remove": []any{"mesh.seat.m.event.still.taken"}, "why": "x"}, "m still consumes mesh.seat.m.event.still.taken"},
{"nats_consumer_narrow", map[string]any{"stream": "EVENTS", "durable": "novox_m_tools", "remove": []any{"mesh.mod.m.event.still.taken"}, "why": "x"}, "m still consumes mesh.mod.m.event.still.taken"},
{"nats_consumer_narrow", map[string]any{"stream": "EVENTS", "durable": "novox_quiet", "remove": []any{"a"}, "why": "x"}, "what quiet consumes cannot be read"},
} {
var run func(map[string]any) (any, error)
for _, tl := range removalTools(bus, said, newForm, accepted, nil, nil, func(_ context.Context, module string) ([]string, error) {
if module == "m" {
return []string{"mesh.m.still.>"}, nil
return []string{"m.still.taken"}, nil
}
return nil, errors.New("the entry is not read")
}) {
@@ -1442,12 +1442,21 @@ func TestTheKeeperMakesWhatAVerdictAsksForAndSaysIt(t *testing.T) {
delete(bus.refuse, "update "+objects[1].Stream())
out.reset()
bus.updated = nil
// The bus holds the first object at a cap other than the one asked (a drift the first change left).
wasHeld := bus.held[objects[0].Stream()]
wasHeld.MaxBytes = objects[0].Settings.MaxBytes * 2
bus.held[objects[0].Stream()] = wasHeld
heldCap := wasHeld.MaxBytes
if got := recreate("r3"); got.Error != "" || len(bus.deleted) != 0 || len(bus.updated) != len(objects) ||
fmt.Sprint(out.events) != "[recreated m records]" || k.Held()["m"].Made["records"].Drift != "" ||
len(out.bodies) == 0 || len(out.bodies[len(out.bodies)-1].Before) != len(objects) || len(out.bodies[len(out.bodies)-1].After) != len(objects) ||
out.bodies[len(out.bodies)-1].Why != "" {
t.Fatalf("the change in place: %q, updated %v, deleted %v, said %v", got.Error, bus.updated, bus.deleted, out.events)
}
// The before names the cap the object held, never the cap asked (H-A-686 (3)).
if b, a := out.bodies[len(out.bodies)-1].Before[0], out.bodies[len(out.bodies)-1].After[0]; b.Cap != heldCap || heldCap == objects[0].Settings.MaxBytes || a.Cap != objects[0].Settings.MaxBytes {
t.Errorf("before names the cap %d, after %d: the held cap was %d, the asked %d", b.Cap, a.Cap, heldCap, objects[0].Settings.MaxBytes)
}
}},
// Review round 1 (security F2; design 25 § 12.3): a warrant acts once, spent by compare-and-set before anything is
// deleted; a second request naming the same ask is refused and deletes nothing.
+3 -2
View File
@@ -250,7 +250,7 @@ func (k *Keeper) act(r *Request) (string, error) {
if err != nil {
return "nothing done", fmt.Errorf("%s cannot be read, so nothing was changed: %w", o.Stream(), err)
}
steps = append(steps, rebuild{o: o, found: found, inPlace: found && st.WorkQueue == o.Settings.WorkQueue, before: fill})
steps = append(steps, rebuild{o: o, found: found, inPlace: found && st.WorkQueue == o.Settings.WorkQueue, before: fill, was: st})
}
// Short of room for the caps it asks, no object is changed and no snapshot taken; the warrant is spent (H-A-706, DQ-42).
if err := k.capRoom(ctx, &held, &m); err != nil {
@@ -321,7 +321,7 @@ func (k *Keeper) act(r *Request) (string, error) {
}
}
_, now, _, _ := k.Bus.Held(ctx, o)
before = append(before, EventFill{Object: o.Stream(), Part: m.Plan.PartOf(o), Count: st.before.Messages, Bytes: st.before.Bytes, Cap: o.Settings.MaxBytes})
before = append(before, EventFill{Object: o.Stream(), Part: m.Plan.PartOf(o), Count: st.before.Messages, Bytes: st.before.Bytes, Cap: st.was.MaxBytes})
after = append(after, EventFill{Object: o.Stream(), Part: m.Plan.PartOf(o), Count: now.Messages, Bytes: now.Bytes, Cap: o.Settings.MaxBytes})
how := "changed in place"
if !st.inPlace {
@@ -356,6 +356,7 @@ type rebuild struct {
o Object
found, inPlace bool
before Fill
was Settings // what the object held before: its cap is the before's, never the asked one
}
// warranted holds a recreate or a drop to the operator's warrant on the ask its tool raised: chosen by the operator,