diff --git a/modules/nats/internal/keeper/keeper.go b/modules/nats/internal/keeper/keeper.go index 104be20ce..733532246 100644 --- a/modules/nats/internal/keeper/keeper.go +++ b/modules/nats/internal/keeper/keeper.go @@ -71,9 +71,13 @@ type Event struct { Asked map[string]Settings `json:"asked,omitempty"` Held map[string]Settings `json:"held,omitempty"` Fill *EventFill `json:"fill,omitempty"` - Snapshot string `json:"snapshot,omitempty"` - Why string `json:"why,omitempty"` - Revision uint64 `json:"revision"` + // Before and After are what each object of a recreated entry held before and after it, said by `recreated` (design 47 H2 + // H-A-740). + Before []EventFill `json:"before,omitempty"` + After []EventFill `json:"after,omitempty"` + Snapshot string `json:"snapshot,omitempty"` + Why string `json:"why,omitempty"` + Revision uint64 `json:"revision"` } // EventFill is the fill an event says: the object it is of, its messages, its bytes and its cap; Object is its name on the @@ -1049,11 +1053,16 @@ func (k *Keeper) emit(event string, p Plan, revision uint64, why string, asked, // emitFill is emit with the fill of the object judged, which full and full-cleared carry (design 47 H2 H-A-634 (9)). func (k *Keeper) emitFill(event string, p Plan, revision uint64, why string, asked, held map[string]Settings, fill *EventFill) { + k.emitBody(event, p, revision, why, asked, held, func(b *Event) { b.Fill = fill }) +} + +// emitBody is emit with the body changed before it is said. +func (k *Keeper) emitBody(event string, p Plan, revision uint64, why string, asked, held map[string]Settings, change func(*Event)) { if k.Emit == nil { return } s := k.saying(event, p, revision, why, asked, held) - s.Body.Fill = fill + change(&s.Body) if err := k.Emit(&s); err != nil { s.Error = err.Error() k.setStatus(func(st *Status) { st.Unsaid = append(st.Unsaid, s) }) diff --git a/modules/nats/internal/keeper/keeper_test.go b/modules/nats/internal/keeper/keeper_test.go index 0b02c5e6c..f11f4ebb3 100644 --- a/modules/nats/internal/keeper/keeper_test.go +++ b/modules/nats/internal/keeper/keeper_test.go @@ -1443,7 +1443,9 @@ func TestTheKeeperMakesWhatAVerdictAsksForAndSaysIt(t *testing.T) { out.reset() bus.updated = nil 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 != "" { + 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) } }}, diff --git a/modules/nats/internal/keeper/requests.go b/modules/nats/internal/keeper/requests.go index fb43f86a6..9af8329ab 100644 --- a/modules/nats/internal/keeper/requests.go +++ b/modules/nats/internal/keeper/requests.go @@ -298,6 +298,7 @@ func (k *Keeper) act(r *Request) (string, error) { // whose retention changes. A change the bus refuses stops it: no object made empty, none changed after, the refusal naming // the object, no recreated, drifted left naming what differs (H-A-686 (2)). var words []string + var before, after []EventFill for i, st := range steps { o := st.o switch { @@ -319,13 +320,15 @@ func (k *Keeper) act(r *Request) (string, error) { return "partly done", fmt.Errorf("%s was removed and could not be made again (its snapshot at %s): %w", o.Stream(), path, err) } } - _, after, _, _ := k.Bus.Held(ctx, o) + _, 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}) + 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 { how = "made again empty" } words = append(words, fmt.Sprintf("%s %s: held %d messages, %d bytes before, %d messages, %d bytes after", o.Stream(), how, - st.before.Messages, st.before.Bytes, after.Messages, after.Bytes)) + st.before.Messages, st.before.Bytes, now.Messages, now.Bytes)) } wasDrift := m.Drift != "" m.Drift = "" @@ -339,7 +342,7 @@ func (k *Keeper) act(r *Request) (string, error) { m.Said = &said held.Made[r.Local] = m k.write(held) - k.emit(EventRecreated, m.Plan, held.Revision, r.Why+" ("+strings.Join(words, "; ")+")", nil, nil) + k.emitBody(EventRecreated, m.Plan, held.Revision, r.Why, nil, nil, func(b *Event) { b.Before, b.After = before, after }) if wasDrift { k.clear(conditionDrifted, r.Module, r.Local) }