Assigner: says wanted in the same write as each want, kept last per node and module
Each want the assigner writes (the rules' wants, a backup answer's, a put's) and each removing want is said `wanted` on the subject of its node and module, each escaped as a name, with the revision and source of the kept assignment graph revision; a removal carries the fingerprint last wanted. A put that wrote nothing says nothing; with no revision kept the journal says wanted was not said. Builds: design 47 G A-61 (§693, §683, §556), A-67 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
@@ -7,9 +7,12 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
mcc "git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogclient"
|
||||
"git.novox.be/novox/mesh-delivery/contracts/go/seats/meshwants"
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
|
||||
"mesh-delivery-assigner/internal/assigngraph"
|
||||
)
|
||||
@@ -95,3 +98,23 @@ func (p *passer) capabilityDigests() []meshwants.AssignmentRevisionCapabilitiesI
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// sayWanted says `wanted` for a want written or removed now, from the revision the pass keeps (A-61, A-67); with none kept, it is
|
||||
// said in the log that it was not said. fp is the want's, and for a removal the fingerprint last wanted there.
|
||||
func (p *passer) sayWanted(node, module, fp string, removed bool) {
|
||||
if p.publishWants == nil {
|
||||
return
|
||||
}
|
||||
g := p.graph
|
||||
if g == nil || !g.ok {
|
||||
p.logf("the want of %s on %s is written, but no assignment graph revision is kept, so wanted is not said", module, node)
|
||||
return
|
||||
}
|
||||
at := p.clock().UTC()
|
||||
body := meshwants.WantedEvent{V: keys.Version, Node: node, Module: module, Fp: fp, Removed: removed, Revision: g.kept.Revision, Source: g.source, At: &at}
|
||||
event := strings.TrimPrefix(meshwants.SubjectWanted(keys.EscapeName(node), keys.EscapeName(module)), "mesh.seat."+meshwants.Seat+".event.")
|
||||
id := fmt.Sprintf("wanted.%s.%s.%s.%t.%d.%s", keys.EscapeName(node), keys.EscapeName(module), fp, removed, g.kept.Revision, at.Format(time.RFC3339Nano))
|
||||
if err := p.wantsSay(event, body, id); err != nil {
|
||||
p.logf("wanted of %s on %s is not said: %v", module, node, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
mcc "git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogclient"
|
||||
mwc "git.novox.be/novox/mesh-delivery/contracts/go/clients/meshwantsclient"
|
||||
"git.novox.be/novox/mesh-delivery/contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-delivery/contracts/go/seats/meshwants"
|
||||
|
||||
@@ -21,8 +22,9 @@ type said struct {
|
||||
}
|
||||
|
||||
// Design 47 G A-67, §292: the pass keeps an assignment graph revision per catalog revision taken in, before it writes any want, and
|
||||
// says assignment-revision once; the same inputs keep and say nothing more.
|
||||
func TestThePassKeepsAnAssignmentGraphRevisionPerCatalogRevision(t *testing.T) {
|
||||
// says assignment-revision; A-61, §693: a want written or removed is said `wanted` on the subject of its node and module in the same
|
||||
// write, from the kept revision and its catalog's source, a put that wrote nothing says nothing, and with no revision kept none is said.
|
||||
func TestTheWantsAreSaidWantedFromTheKeptAssignmentGraphRevision(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
at := time.Date(2026, 11, 12, 9, 0, 0, 0, time.UTC)
|
||||
kv := &memKV{values: map[string][]byte{}}
|
||||
@@ -40,6 +42,17 @@ func TestThePassKeepsAnAssignmentGraphRevisionPerCatalogRevision(t *testing.T) {
|
||||
Entries: map[string]meshcatalog.CatalogEntry{"web": {Module: "web", Fp: fpTest}}}
|
||||
objects := memObjects{}
|
||||
p.graph = &graphKeeper{objects: objects, halves: func() map[string]mcc.Half { return map[string]mcc.Half{trunkBranch: half} }}
|
||||
want := mwc.Want{Fp: fpTest, Self: true}
|
||||
|
||||
p.putWant(ctx, "ace", "web", want) // no revision kept yet: written, and not said
|
||||
if len(events) != 0 || kv.puts != 1 {
|
||||
t.Fatalf("with no revision kept: %d events, %d puts", len(events), kv.puts)
|
||||
}
|
||||
key, _ := mwc.WantKey("ace", "web")
|
||||
delete(p.w.read(buckets.Wants), key) // the world forgets the want, as before the first pass
|
||||
kv.puts = 0
|
||||
p.w.put(buckets.Wants, key, nil)
|
||||
|
||||
p.keepGraph(ctx)
|
||||
if len(events) != 1 || events[0].event != meshwants.EventAssignmentRevision || len(objects) == 0 {
|
||||
t.Fatalf("the pass kept %d objects and said %+v", len(objects), events)
|
||||
@@ -48,7 +61,20 @@ func TestThePassKeepsAnAssignmentGraphRevisionPerCatalogRevision(t *testing.T) {
|
||||
if len(events) != 1 {
|
||||
t.Fatalf("a pass of the same inputs said %d events", len(events))
|
||||
}
|
||||
if g := p.graph; !g.ok || g.kept.Revision != 1 || g.source != 9 {
|
||||
t.Errorf("kept %+v, source %d", g.kept, g.source)
|
||||
p.putWant(ctx, "ace", "web", want)
|
||||
p.putWant(ctx, "ace", "web", want) // unchanged: not written, not said
|
||||
if len(events) != 2 || kv.puts != 1 {
|
||||
t.Fatalf("a want put twice: %d events, %d puts", len(events), kv.puts)
|
||||
}
|
||||
if wantEvent := "wanted.ace.web"; events[1].event != wantEvent {
|
||||
t.Errorf("wanted said on %q, want %q", events[1].event, wantEvent)
|
||||
}
|
||||
var w meshwants.WantedEvent
|
||||
if err := json.Unmarshal(events[1].body, &w); err != nil || w.Node != "ace" || w.Module != "web" || w.Fp != fpTest || w.Removed || w.Revision != 1 || w.Source != 9 {
|
||||
t.Errorf("wanted = %+v (%v)", w, err)
|
||||
}
|
||||
p.putWant(ctx, "ace", "web", mwc.Want{Removed: true})
|
||||
if err := json.Unmarshal(events[len(events)-1].body, &w); err != nil || len(events) != 3 || !w.Removed || w.Fp != fpTest {
|
||||
t.Errorf("a removing want said %+v (%v), %d events", w, err, len(events))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -388,13 +388,7 @@ func (p *passer) wants(ctx context.Context) {
|
||||
p.recordAsk(ctx, name, fp, need)
|
||||
}
|
||||
for node, want := range out.Wants {
|
||||
key, err := mwc.WantKey(node, name)
|
||||
if err != nil {
|
||||
p.logf("no want of %s on %s is written: %v", name, node, err)
|
||||
continue
|
||||
}
|
||||
want := want
|
||||
p.put(ctx, buckets.Wants, key, func() ([]byte, error) { return mwc.EncodeWant(want) })
|
||||
p.putWant(ctx, node, name, want)
|
||||
}
|
||||
if len(out.Wants) > 0 {
|
||||
p.ends.wrote(name, fp, branches)
|
||||
@@ -645,21 +639,47 @@ func (p *passer) sayNeither(now, stale map[string]neitherOne, left map[string]st
|
||||
|
||||
// put writes one key of the assigner's own bucket; a write that fails is said and made again at the next pass.
|
||||
func (p *passer) put(ctx context.Context, bucket, key string, encode func() ([]byte, error)) {
|
||||
p.written(ctx, bucket, key, encode)
|
||||
}
|
||||
|
||||
// written is put, saying whether the bucket was written now: false when the value could not be encoded or written, or the
|
||||
// bucket already held it.
|
||||
func (p *passer) written(ctx context.Context, bucket, key string, encode func() ([]byte, error)) bool {
|
||||
value, err := encode()
|
||||
if err != nil {
|
||||
p.logf("%s %s is not written: %v", bucket, key, err)
|
||||
return
|
||||
return false
|
||||
}
|
||||
// A value the bucket already holds is not put again: every put is a change its watchers hear, and a want put unchanged
|
||||
// made its node compose again (issue 774, 2026-10-31: novox composed every 8 s, two asks of the vault each time).
|
||||
if held := p.w.value(bucket, key); held != nil && bytes.Equal(held, value) {
|
||||
return
|
||||
return false
|
||||
}
|
||||
if _, err := p.kvs[bucket].Put(ctx, key, value); err != nil && !errors.Is(err, context.Canceled) {
|
||||
p.logf("%s %s could not be written: %v", bucket, key, err)
|
||||
return
|
||||
return false
|
||||
}
|
||||
p.w.put(bucket, key, value)
|
||||
return true
|
||||
}
|
||||
|
||||
// putWant writes the want of module on node, and in the same write says `wanted` on the seat mesh-wants (design 47 G §693, A-61),
|
||||
// `removed` for a removing want with the fingerprint last wanted there; nothing is said when the put wrote nothing.
|
||||
func (p *passer) putWant(ctx context.Context, node, module string, want mwc.Want) {
|
||||
key, err := mwc.WantKey(node, module)
|
||||
if err != nil {
|
||||
p.logf("no want of %s on %s is written: %v", module, node, err)
|
||||
return
|
||||
}
|
||||
fp := want.Fp
|
||||
if want.Removed {
|
||||
if before, err := mwc.DecodeWant(p.w.value(buckets.Wants, key)); err == nil {
|
||||
fp = before.Fp
|
||||
}
|
||||
}
|
||||
if p.written(ctx, buckets.Wants, key, func() ([]byte, error) { return mwc.EncodeWant(want) }) {
|
||||
p.sayWanted(node, module, fp, want.Removed)
|
||||
}
|
||||
}
|
||||
|
||||
// holdAsk writes, once, the ask about a held fingerprint (ADR 0528 clause 6, ADR 0437 clause 10): the first ask that needs
|
||||
@@ -1005,11 +1025,8 @@ func (p *passer) backups(ctx context.Context) {
|
||||
haveChanges := p.w.changed(buckets.Have, key)
|
||||
if want.Backup != answer.Option || want.Words != words {
|
||||
want.Backup, want.Words = answer.Option, words
|
||||
if wkey, err := mwc.WantKey(node, module); err == nil {
|
||||
w := want
|
||||
p.put(ctx, buckets.Wants, wkey, func() ([]byte, error) { return mwc.EncodeWant(w) })
|
||||
p.answeredAt[currentAsk.ID] = haveChanges
|
||||
}
|
||||
p.putWant(ctx, node, module, want)
|
||||
p.answeredAt[currentAsk.ID] = haveChanges
|
||||
continue
|
||||
}
|
||||
if answer.Option != mwc.BackupAgain {
|
||||
|
||||
@@ -159,11 +159,9 @@ func (p *passer) puts(ctx context.Context) {
|
||||
}
|
||||
if next.Put.Step == puts.Wanted && put.Step != puts.Wanted {
|
||||
// The want is written in this pass too, before the next one would: Module.Puts writes the same.
|
||||
if wkey, err := mwc.WantKey(node, module); err == nil {
|
||||
want := assign.PutWant(next.Put)
|
||||
if before, ok := wanted[module][node]; !ok || !mwc.SameWant(normalWant(before), normalWant(want)) {
|
||||
p.put(ctx, buckets.Wants, wkey, func() ([]byte, error) { return mwc.EncodeWant(want) })
|
||||
}
|
||||
want := assign.PutWant(next.Put)
|
||||
if before, ok := wanted[module][node]; !ok || !mwc.SameWant(normalWant(before), normalWant(want)) {
|
||||
p.putWant(ctx, node, module, want)
|
||||
}
|
||||
if next.Warranted {
|
||||
p.acts.warrant(id, meshdeliveryclient.AskingID(next.Put.Ask, assign.PutAsking(next.Put)))
|
||||
|
||||
Reference in New Issue
Block a user