GR13 purge: the named asks go at the first revision that leaves them, or by grants_named_purge
While no entry of the revision invokes a queue of a build seat (seat:<seat>.accept.<queue>, read by catalogue.QueueInvoke), the part composes no named worker, and at the first such pass it purges accept.<queue>.* of each build seat's stream and deletes the named workers, saying each in its journal; a failed read of the catalog half purges nothing. Its account alone is granted the stream's purge and the named workers' delete. The hand tool grants_named_purge records its hand act first, then asks the process to do it. Builds: design 47 G §544, §600, §601, A-231 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
@@ -132,3 +132,29 @@ func (c creating) AddFilters(stream, name string, add []string) error {
|
||||
_, err = c.js.UpdateConsumer(ctx, stream, cfg)
|
||||
return err
|
||||
}
|
||||
|
||||
// PurgeSubject purges the messages of one subject of a stream (design 47 G §544): the named asks of a build seat's queue.
|
||||
func (c creating) PurgeSubject(stream, subject string) error {
|
||||
ctx, cancel := context.WithTimeout(c.ctx, requestWithin)
|
||||
defer cancel()
|
||||
st, err := c.js.Stream(ctx, stream)
|
||||
if errors.Is(err, jetstream.ErrStreamNotFound) {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return st.Purge(ctx, jetstream.WithPurgeSubject(subject))
|
||||
}
|
||||
|
||||
// DeleteConsumer deletes one consumer of a stream (design 47 G §544): a build seat's named worker; one the bus does not hold
|
||||
// is no error.
|
||||
func (c creating) DeleteConsumer(stream, name string) error {
|
||||
ctx, cancel := context.WithTimeout(c.ctx, requestWithin)
|
||||
defer cancel()
|
||||
err := c.js.DeleteConsumer(ctx, stream, name)
|
||||
if errors.Is(err, jetstream.ErrConsumerNotFound) || errors.Is(err, jetstream.ErrStreamNotFound) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -623,6 +623,31 @@ func TestTheGrantsPartWhole(t *testing.T) {
|
||||
if again, _ := stream.Info(ctx); !slices.Equal(again.Config.Subjects, []string{"a.>", "b.>"}) {
|
||||
t.Errorf("subjects after adding a held one: %v", again.Config.Subjects)
|
||||
}
|
||||
// The named asks' purge takes one subject's messages and no other's, and a named worker's delete is said done also
|
||||
// where the bus holds none (design 47 G §544).
|
||||
for _, subj := range []string{"b.one", "b.two"} {
|
||||
if _, err := js.Publish(ctx, subj, []byte("{}")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
held, _ := stream.Info(ctx)
|
||||
if err := c.PurgeSubject("ADDS", "b.*"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if left, _ := stream.Info(ctx); left.State.Msgs != held.State.Msgs-2 {
|
||||
t.Errorf("the purge left %d messages of %d, want the two of b.* gone", left.State.Msgs, held.State.Msgs)
|
||||
}
|
||||
for i := 0; i < 2; i++ {
|
||||
if err := c.DeleteConsumer("ADDS", "idx"); err != nil {
|
||||
t.Fatalf("delete %d: %v", i, err)
|
||||
}
|
||||
}
|
||||
if _, err := js.Consumer(ctx, "ADDS", "idx"); err == nil {
|
||||
t.Error("the consumer is still held after its delete")
|
||||
}
|
||||
if err := c.PurgeSubject("NO_SUCH", "x.*"); err != nil {
|
||||
t.Errorf("the purge of a stream the bus lacks: %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
// And what the part composes holds on a server that loads it (one integration test per module, the test budget).
|
||||
|
||||
@@ -169,7 +169,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
branches.Entries.Changed = func(meshcatalogclient.EntryRow) { f.Wake() }
|
||||
fv.Catalog = &grants.CatalogOf{Branches: branches, Context: ctx, Wake: f.Wake}
|
||||
f.Part = &grants.Part{Read: fv, Call: conn, Store: ownStore{conn}, Emit: emitting{conn}, Views: fv, FirstViewContext: ctx,
|
||||
Create: creating{ctx: ctx, js: js}, Consumers: creating{ctx: ctx, js: js},
|
||||
Create: creating{ctx: ctx, js: js}, Consumers: creating{ctx: ctx, js: js}, NamedPurge: creating{ctx: ctx, js: js},
|
||||
Objects: sealedObjects{ctx: ctx, js: js}, Purging: ownPurging{ctx: ctx, js: js, module: account.Module}, Logf: logger.Printf,
|
||||
Bus: grants.BusAddress{URL: account.URL, Fingerprint: account.Fingerprint}}
|
||||
f.Watch = fv
|
||||
|
||||
@@ -281,6 +281,14 @@ func toolsOf(p *grants.Part) []stdio.Tool {
|
||||
Run: func(a map[string]any) (any, error) {
|
||||
return p.ReleaseWait(stdio.CallerOf(a), grants.Answer(a, "module"), grants.Answer(a, "why"), recordHandAct)
|
||||
}},
|
||||
{Name: grants.ToolNamedPurge, Description: "Purge the build seats' named asks (accept.<queue>.* of each seat's stream) and delete " +
|
||||
"their named workers, by a person's act with why, recorded as a hand act (the seat mesh-hand-acts) before anything is " +
|
||||
"asked (design 47 G §544): the step where the grants part stopped before it purged them at the first revision in " +
|
||||
"which no entry invokes a queue of a build seat. Asks the part's process, whose journal names each purge and delete.",
|
||||
Input: schema(map[string]string{"why": "why, kept in the hand act"}, "why"),
|
||||
Run: func(a map[string]any) (any, error) {
|
||||
return p.AskNamedPurge(stdio.CallerOf(a), grants.Answer(a, "why"), recordHandActAs("named-purge"))
|
||||
}},
|
||||
{Name: grants.ToolRunning, Description: "What each node-engine said it runs (novox/hq design 47, ADR 0660 §2): the last event " +
|
||||
"running of each node and module, as the grants part keeps it in its state running (module, node, the build's " +
|
||||
"fingerprint, the digest of that build's manifest, when it was seen running healthy). A seat's holder is read from " +
|
||||
@@ -291,9 +299,14 @@ func toolsOf(p *grants.Part) []stdio.Tool {
|
||||
}
|
||||
|
||||
// recordHandAct records a person's act through the seat mesh-hand-acts.
|
||||
func recordHandAct(what, why string) error {
|
||||
_, err := meshhandactsclient.Recorder{Ask: stdio.Ask}.Record(meshhandactsclient.Request{What: what, Why: why, Cause: "first-view-again"})
|
||||
return err
|
||||
func recordHandAct(what, why string) error { return recordHandActAs("first-view-again")(what, why) }
|
||||
|
||||
// recordHandActAs records a person's act of the cause given through the seat mesh-hand-acts.
|
||||
func recordHandActAs(cause string) func(what, why string) error {
|
||||
return func(what, why string) error {
|
||||
_, err := meshhandactsclient.Recorder{Ask: stdio.Ask}.Record(meshhandactsclient.Request{What: what, Why: why, Cause: cause})
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// serveTools serves the tools to the runtime until it stops.
|
||||
|
||||
Reference in New Issue
Block a user