NATS-R2: nats_consumer_remove judges durables by every accepted module
The refusal read the keeper's state asked, which holds only a module that asks for kept data, so a running module keeping no bus data would lose its live durables. It now reads the keeper's state plans, one key per module of a watched branch's newest revision; the keeper no longer deletes a plan key when a module's asked key goes, so plans stays that accepted set. Builds: design 47 H H-A-126, H-A-127, H-A-128; design 47 G §538 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
@@ -191,7 +191,7 @@ func allTools() []stdio.Tool {
|
||||
defer cancel()
|
||||
return monitor(ctx, heldJsz)
|
||||
}
|
||||
out := append(tools(monitor, ReadUsers, UsersWritten), removalTools(LiveBus(), SaidByTheRuntime, HeldInState, RecordedBySeat)...)
|
||||
out := append(tools(monitor, ReadUsers, UsersWritten), removalTools(LiveBus(), SaidByTheRuntime, HeldInState, PlansInState, RecordedBySeat)...)
|
||||
out = append(out, expiryTools(LiveBus(), SaidByTheRuntime, RecordedBySeat)...)
|
||||
out = append(out, brokerTools(HeldInState, StatusInState, jsz, StreamHistory(LiveBus()))...)
|
||||
out = append(out, keeperHealthTool(StatusInState, HeldInState, jsz))
|
||||
|
||||
@@ -24,6 +24,8 @@ import (
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
"github.com/nats-io/nats.go"
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
"nats-tools/internal/keeper"
|
||||
)
|
||||
|
||||
// Bus opens JetStream on the bus as the module's credential for one call; close ends the connection.
|
||||
@@ -341,12 +343,13 @@ func RemoveStream(ctx context.Context, bus Bus, said Said, a map[string]any) (an
|
||||
// that cannot be read refuses too: what cannot be told apart is not removed.
|
||||
//
|
||||
// **A consumer is judged by its name, not by its stream** (design 47 H, H-A-126, H-A-127): the mesh names a module's
|
||||
// durable <node>_<module>, so a durable of that form for a module of an accepted manifest (the keeper's accepted set) is
|
||||
// refused, on any stream; every other durable is an orphan and goes, `why` its warrant, at once, and its removal is
|
||||
// durable <node>_<module>, so a durable of that form for a module of an accepted manifest (the keeper's accepted set:
|
||||
// every module it heard as accepted, its state plans, one key per module of a watched branch's newest revision whether
|
||||
// it asks for kept data or not, design 47 G §538) is refused, on any stream; every other durable is an orphan and goes, `why` its warrant, at once, and its removal is
|
||||
// recorded as a hand act through mesh-hand-acts, as nats_bucket_expiry's change is.
|
||||
func removalTools(bus Bus, said Said, newForm heldEntries, record Recorded) []stdio.Tool {
|
||||
func removalTools(bus Bus, said Said, newForm heldEntries, accepted acceptedModules, record Recorded) []stdio.Tool {
|
||||
removeConsumer := func(a map[string]any) (any, error) {
|
||||
if err := refuseAcceptedDurable(newForm, arg(a, "consumer")); err != nil {
|
||||
if err := refuseAcceptedDurable(accepted, arg(a, "consumer")); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out, err := RemoveConsumer(context.Background(), bus, said, a)
|
||||
@@ -398,16 +401,19 @@ func removalTools(bus Bus, said Said, newForm heldEntries, record Recorded) []st
|
||||
}
|
||||
|
||||
// refuseAcceptedDurable refuses a durable named <node>_<module>, or beginning <node>_<module>_, for a module of the
|
||||
// keeper's accepted set, on any node (design 47 H, H-A-127, H-A-128); a set that cannot be read refuses too: what cannot be told apart is not removed.
|
||||
func refuseAcceptedDurable(newForm heldEntries, consumer string) error {
|
||||
if newForm == nil {
|
||||
// keeper's accepted set, on any node (design 47 H, H-A-127, H-A-128): every module it heard as accepted, read from its
|
||||
// state plans (design 47 G §538), never from its state asked, which holds only a module that asks for kept data (a
|
||||
// module keeping none would lose its live durables: H-A-128's silent failure, P3). A set that cannot be read refuses
|
||||
// too: what cannot be told apart is not removed.
|
||||
func refuseAcceptedDurable(accepted acceptedModules, consumer string) error {
|
||||
if accepted == nil {
|
||||
return nil
|
||||
}
|
||||
node, module, ok := strings.Cut(consumer, "_")
|
||||
if !ok || node == "" || module == "" {
|
||||
return nil
|
||||
}
|
||||
held, err := newForm()
|
||||
held, err := accepted()
|
||||
if err != nil {
|
||||
return fmt.Errorf("whether %s is the durable of a module of an accepted manifest cannot be read (%v), so nothing was removed", consumer, err)
|
||||
}
|
||||
@@ -419,6 +425,9 @@ func refuseAcceptedDurable(newForm heldEntries, consumer string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// acceptedModules reads the keeper's accepted set: every module it heard as accepted, by name (its state plans, §538).
|
||||
type acceptedModules func() (map[string]keeper.Planned, error)
|
||||
|
||||
// refuseNewForm refuses a stream the keeper made for a module's bus state, naming the tool that removes it.
|
||||
func refuseNewForm(newForm heldEntries, stream string) error {
|
||||
if newForm == nil || stream == "" {
|
||||
|
||||
@@ -195,7 +195,7 @@ accounts { MESH { jetstream: enabled, users: [
|
||||
// Through the tool, `why` its warrant: each removal is recorded as a hand act (design 47 H, H-A-127).
|
||||
var handActs []meshhandactsclient.Request
|
||||
var removeConsumer func(map[string]any) (any, error)
|
||||
for _, tl := range removalTools(bus, say, nil, func(q meshhandactsclient.Request) error { handActs = append(handActs, q); return nil }) {
|
||||
for _, tl := range removalTools(bus, say, nil, nil, func(q meshhandactsclient.Request) error { handActs = append(handActs, q); return nil }) {
|
||||
if tl.Name == "nats_consumer_remove" {
|
||||
removeConsumer = tl.Run
|
||||
}
|
||||
|
||||
@@ -234,6 +234,11 @@ func TestTheRemovalToolsRefuseBeforeTheyReachTheBus(t *testing.T) {
|
||||
}
|
||||
return map[string]keeper.Asked{"m": {Module: "m", Made: made}}, nil
|
||||
}
|
||||
// The keeper's accepted set (its state plans, §538): m, which asks for kept data, and quiet, which asks for none and
|
||||
// so has no key in asked (review round 2: a module keeping no bus data still has live durables).
|
||||
accepted := func() (map[string]keeper.Planned, error) {
|
||||
return map[string]keeper.Planned{"m": {Module: "m"}, "quiet": {Module: "quiet"}}, nil
|
||||
}
|
||||
for _, c := range []struct {
|
||||
tool string
|
||||
args map[string]any
|
||||
@@ -260,9 +265,12 @@ func TestTheRemovalToolsRefuseBeforeTheyReachTheBus(t *testing.T) {
|
||||
{"nats_consumer_remove", map[string]any{"stream": "m_log", "consumer": "ace_m", "why": "x"}, "a module of an accepted manifest"},
|
||||
// H-A-128: a durable beginning <node>_<module>_ is the module's too.
|
||||
{"nats_consumer_remove", map[string]any{"stream": "EVENTS", "consumer": "novox_m_keeper", "why": "x"}, "a module of an accepted manifest"},
|
||||
// H-A-128: an accepted module that asks for no kept data is refused too, its durables and its suffixed ones.
|
||||
{"nats_consumer_remove", map[string]any{"stream": "EVENTS", "consumer": "novox_quiet", "why": "x"}, "a module of an accepted manifest"},
|
||||
{"nats_consumer_remove", map[string]any{"stream": "EVENTS", "consumer": "novox_quiet_tools", "why": "x"}, "a module of an accepted manifest"},
|
||||
} {
|
||||
var run func(map[string]any) (any, error)
|
||||
for _, tl := range removalTools(bus, said, newForm, nil) {
|
||||
for _, tl := range removalTools(bus, said, newForm, accepted, nil) {
|
||||
if tl.Name == c.tool {
|
||||
run = tl.Run
|
||||
}
|
||||
@@ -278,7 +286,7 @@ func TestTheRemovalToolsRefuseBeforeTheyReachTheBus(t *testing.T) {
|
||||
unreachable := func(context.Context) (jetstream.JetStream, func(), error) {
|
||||
return nil, nil, errors.New("the bus is not reached here")
|
||||
}
|
||||
for _, tl := range removalTools(unreachable, said, newForm, nil) {
|
||||
for _, tl := range removalTools(unreachable, said, newForm, accepted, nil) {
|
||||
if tl.Name != "nats_consumer_remove" {
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user