Assigner: a seat no assignments holds is written in seat-holders as held by the assigned module whose manifest claims it, and said (A-400): the indexer waited for a holder of mesh-module-assigner for ever

This commit is contained in:
2026-11-14 20:21:17 +01:00
parent 4a83418c02
commit ddee3bf9af
4 changed files with 101 additions and 7 deletions
@@ -87,6 +87,7 @@ type passer struct {
// laid again is not ended on a seat it does not name (ADR 0636 §1). Nil reads nothing.
seats *seatlist.Part
seatWaitSaid sync.Once
derivedSaid map[string]bool // each seat-holders key last written as derived from a claim (A-400), so each is said once
publish publisher
saidProposed map[string]bool
// copied says the retired state was copied into `assignments` by this process, or found empty (copyRetired).
@@ -276,7 +277,7 @@ func (p *passer) wants(ctx context.Context) {
missing := map[string]bool{}
defer func() { p.provisionsMissing(ctx, missing) }()
defer p.unplacedFindings()
defer p.seatHolders(ctx)
defer func() { p.seatHolders(ctx, viewOf(p.w.trunkName()).manifests) }()
p.clearStaleCalls()
placed := p.w.placedNodes()
puts := p.putsByModule()
@@ -1319,7 +1320,10 @@ func (p *passer) unplacedFindings() {
// seat held once, `<seat>`, and one per node of a node seat, `<seat>.<node>`, written only where it differs, and a key no
// assignments holds any more deleted. A pass follows each assignments change and each manifest the indexer takes in, so no
// timer writes it.
func (p *passer) seatHolders(ctx context.Context) {
//
// A seat no assignments holds is held by the first assigned module whose manifest of the trunk claims it (lead answer A-400):
// manifests is the trunk's, by module. Each holder so derived is said once while it stays derived.
func (p *passer) seatHolders(ctx context.Context, manifests map[string]catalogue.Manifest) {
kv := p.kvs[plc.SeatHoldersBucket()]
if kv == nil {
return
@@ -1336,7 +1340,20 @@ func (p *passer) seatHolders(ctx context.Context) {
}
return
}
want := plc.SeatHoldersOf(assignments)
want, derived := plc.SeatHoldersWithClaimants(assignments, manifests)
now := map[string]bool{}
for _, d := range derived {
now[d] = true
if !p.derivedSaid[d] {
p.logf("seat-holders: the seat %s: no holding on record, written as held by the assigned module whose manifest claims it (A-400)", d)
}
}
for d := range p.derivedSaid {
if !now[d] {
p.logf("seat-holders: the seat %s is no longer derived (a holding is on record, or nobody assigned claims it)", d)
}
}
p.derivedSaid = now
have := p.w.read(plc.SeatHoldersBucket())
for key, sh := range want {
value, err := json.Marshal(sh)
@@ -325,11 +325,11 @@ func TestTheSeatsVerbs(t *testing.T) {
place("ace", mma.Holding{Claim: "mesh-broker", Scope: "mesh", Module: "nats"}, mma.Holding{Claim: "node-shell", Scope: "node", Module: "web"})
place("g14", mma.Holding{Claim: "node-shell", Scope: "node", Module: "web"})
ctx := context.Background()
if p.seatHolders(ctx); writes != 0 {
if p.seatHolders(ctx, nil); writes != 0 {
t.Fatalf("seat-holders was written from an unread seat list: %v", kv.values)
}
p.seats = gateOver(t, false)
p.seatHolders(ctx)
p.seatHolders(ctx, nil)
var broker mma.SeatHolders
if err := json.Unmarshal(kv.values["mesh-broker"], &broker); err != nil || broker.Outside {
t.Errorf("mesh-broker's holders %+v, %v: a seat the list names is no seat outside it", broker, err)
@@ -337,12 +337,12 @@ func TestTheSeatsVerbs(t *testing.T) {
if writes != 3 || kv.values["mesh-broker"] == nil || kv.values["node-shell.ace"] == nil || kv.values["node-shell.g14"] == nil {
t.Fatalf("%d writes: %v", writes, kv.values)
}
p.seatHolders(ctx)
p.seatHolders(ctx, nil)
if writes != 3 {
t.Errorf("an unchanged assignments wrote %d keys", writes-3)
}
place("g14") // g14 holds nothing now
p.seatHolders(ctx)
p.seatHolders(ctx, nil)
if writes != 3 || kv.values["node-shell.g14"] != nil || kv.values["node-shell.ace"] == nil {
t.Errorf("after g14's change: %d writes, %v", writes, kv.values)
}
@@ -11,6 +11,7 @@ import (
client "git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient"
seat "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
"git.novox.be/novox/mesh-sdk/go/catalogue"
"git.novox.be/novox/mesh-sdk/go/keys"
)
@@ -356,5 +357,30 @@ func TestAssignments(t *testing.T) {
if h, _ := client.HoldersOf(keyed, "node-files", "novox"); h != nil {
t.Errorf("a node seat nobody holds there is held by %v", h)
}
// A-400: a seat no holding names is held by the first assigned module whose manifest claims it; a holding on record wins.
assigned := map[string]seat.Assignments{
"ace": {Node: "ace", Modules: []seat.PlacedModule{{Module: "mesh-delivery-assigner"}, {Module: "mesh-files"}}},
"novox": {Node: "novox", Modules: []seat.PlacedModule{{Module: "nats"}, {Module: "mesh-files"}}, Holds: []seat.Holding{{Claim: "mesh-broker", Scope: "mesh", Module: "nats"}}},
}
manifests := map[string]catalogue.Manifest{
"mesh-delivery-assigner": {Claims: []catalogue.Claim{{Name: "mesh-module-assigner", Scope: "mesh"}}},
"nats": {Claims: []catalogue.Claim{{Name: "mesh-broker", Scope: "mesh"}}},
"mesh-files": {Claims: []catalogue.Claim{{Name: "node-files"}}},
}
with, derived := SeatHoldersWithClaimants(assigned, manifests)
keyed = map[string][]byte{}
for k, v := range with {
keyed[k], _ = json.Marshal(v)
}
if h, err := client.HoldersOf(keyed, "mesh-module-assigner", ""); err != nil || len(h) != 1 || h[0].Module != "mesh-delivery-assigner" || h[0].Node != "ace" {
t.Errorf("an unheld seat's claimant is %v, %v", h, err)
}
if h, _ := client.HoldersOf(keyed, "node-files", "novox"); len(h) != 1 || h[0].Module != "mesh-files" {
t.Errorf("a node seat's claimant on novox is %v", h)
}
if h, _ := client.HoldersOf(keyed, "mesh-broker", ""); len(h) != 1 || h[0].Node != "novox" || len(derived) != 3 {
t.Errorf("a held seat is %v; derived %v", h, derived)
}
})
}
@@ -252,3 +252,54 @@ func sortedKeys[V any](m map[string]V) []string {
sort.Strings(out)
return out
}
// SeatHoldersWithClaimants is SeatHoldersOf over the assignments with, for each seat no holding names (a seat held once:
// on no node; a seat of every node: on that node), the first module assigned to a node (nodes and modules in order) whose
// manifest claims it, as its holder (lead answer A-400, the same rule as grants' A-398; the operator, 2026-11-14: who holds
// a seat follows from the module graph and the assignments). derived lists each key so held, for its writer to say. Pure.
func SeatHoldersWithClaimants(assignments map[string]seat.Assignments, manifests map[string]catalogue.Manifest) (out map[string]seat.SeatHolders, derived []string) {
held := map[string]bool{} // "<seat>" for a seat held once, "<seat>.<node>" for a seat of every node
keyOf := func(claim, scope, node string) string {
name := claim
if s, ok := catalogue.SeatNamed(claim); ok {
name = s.Name
}
if scope == catalogue.ScopeNode {
return name + "." + node
}
return name
}
for _, n := range sortedKeys(assignments) {
for _, h := range assignments[n].Holds {
held[keyOf(h.Claim, h.Scope, n)] = true
}
}
with := map[string]seat.Assignments{}
var added []string
for _, n := range sortedKeys(assignments) {
a := assignments[n]
a.Holds = append([]seat.Holding(nil), a.Holds...)
modules := make([]string, 0, len(a.Modules))
for _, m := range a.Modules {
modules = append(modules, m.Module)
}
sort.Strings(modules)
for _, module := range modules {
m, ok := manifests[module]
if !ok {
continue
}
for _, c := range m.Claims {
k := keyOf(c.Name, c.At(), n)
if held[k] {
continue
}
held[k] = true
a.Holds = append(a.Holds, seat.Holding{Claim: c.Name, Module: module, Scope: c.At()})
added = append(added, k+" by "+module+" on "+n)
}
}
with[n] = a
}
return SeatHoldersOf(with), added
}