nats: a recreate's ask takes its words from the per-object lines, recreated's before names the held cap

Builds: design 47 H2 H-A-686 (3), H-A-740
This commit is contained in:
2026-11-25 18:52:08 +01:00
parent cda35e6c42
commit b15c220822
4 changed files with 22 additions and 5 deletions
@@ -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,