Find the delivery's owner on the controller's own path by the seat's claim, not its name (issue 1210)
This commit is contained in:
@@ -42,13 +42,53 @@ import (
|
||||
// `delivery order` (a group's order from the graph), `delivery check` (a group's heads composed), `delivery
|
||||
// go`, `delivery stop` and `delivery walks`.
|
||||
|
||||
// onTheControllersPath are the modules whose walk never waits for the delivery's owner, and what each is.
|
||||
// onTheControllersPath are the modules, by name, whose walk never waits for the delivery's owner, and what each is.
|
||||
// The delivery's owner is not among them: it is whichever module claims the seat (ownPathOf, novox/hq ADR 0437 §3).
|
||||
var onTheControllersPath = map[string]string{
|
||||
"mesh-controller": "the controller",
|
||||
"mesh-host": "the node-engine",
|
||||
"node-tools": "the node tools",
|
||||
"nats": "the bus",
|
||||
catalogue.DeliverySeat: "the delivery's owner",
|
||||
"mesh-controller": "the controller",
|
||||
"mesh-host": "the node-engine",
|
||||
"node-tools": "the node tools",
|
||||
"nats": "the bus",
|
||||
}
|
||||
|
||||
// claimantsOf are the modules among the catalogued entries that claim a seat, each once, in name order.
|
||||
func claimantsOf(entries []inventory.Entry, seat string) []string {
|
||||
var out []string
|
||||
for _, e := range entries {
|
||||
if e.Manifest.ClaimsSeat(seat) && !slices.Contains(out, e.Manifest.Module) {
|
||||
out = append(out, e.Manifest.Module)
|
||||
}
|
||||
}
|
||||
sort.Strings(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// ownPathOf is the controller's own path among these entries: the modules by name, and the modules that claim
|
||||
// the delivery seat, which is how the delivery's owner is found (novox/hq ADR 0437 §3).
|
||||
func ownPathOf(entries []inventory.Entry) map[string]string {
|
||||
own := make(map[string]string, len(onTheControllersPath)+1)
|
||||
for m, what := range onTheControllersPath {
|
||||
own[m] = what
|
||||
}
|
||||
for _, m := range claimantsOf(entries, catalogue.DeliverySeat) {
|
||||
own[m] = "the delivery's owner"
|
||||
}
|
||||
return own
|
||||
}
|
||||
|
||||
// onTheOwnPath is whether one module, with its manifest at hand, is on the controller's own path.
|
||||
func onTheOwnPath(module string, m catalogue.Manifest) bool {
|
||||
_, named := onTheControllersPath[module]
|
||||
return named || m.ClaimsSeat(catalogue.DeliverySeat)
|
||||
}
|
||||
|
||||
// ownPathNow is ownPathOf the catalogue as it is.
|
||||
func ownPathNow(ctx context.Context, inv *inventory.Inventory) (map[string]string, error) {
|
||||
entries, err := inv.Catalogued(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ownPathOf(entries), nil
|
||||
}
|
||||
|
||||
// deliverySeatHeld is whether a module claiming the delivery seat is assigned somewhere: the seat has a
|
||||
@@ -69,8 +109,9 @@ func awaitsFor(entries []inventory.Entry, modules []string) *inventory.PlanDeliv
|
||||
if !deliverySeatHeld(entries) {
|
||||
return nil
|
||||
}
|
||||
onPath := ownPathOf(entries)
|
||||
for _, m := range modules {
|
||||
if _, own := onTheControllersPath[m]; own {
|
||||
if _, own := onPath[m]; own {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -327,16 +368,17 @@ func stopInBatch(ctx context.Context, inv *inventory.Inventory, b *inventory.Pla
|
||||
// the stop's one act. The kind is read from what the merges moved; the stopped walk itself is no walk a cut folds.
|
||||
func batchToWalkAgain(ctx context.Context, inv *inventory.Inventory, stopping string, again []inventory.BatchedMerge,
|
||||
now time.Time) (inventory.Plan, []*inventory.Plan, []inventory.MergeMove, error) {
|
||||
own := false
|
||||
for _, n := range movesOf(again) {
|
||||
if _, on := onTheControllersPath[n]; on {
|
||||
own = true
|
||||
}
|
||||
}
|
||||
entries, read, edges, err := theGraph(ctx, inv)
|
||||
if err != nil {
|
||||
return inventory.Plan{}, nil, nil, err
|
||||
}
|
||||
own := false
|
||||
onPath := ownPathOf(entries)
|
||||
for _, n := range movesOf(again) {
|
||||
if _, on := onPath[n]; on {
|
||||
own = true
|
||||
}
|
||||
}
|
||||
joins, _, _, err := relatedBatches(ctx, inv, again, own, stopping, entries, read, edges)
|
||||
if err != nil {
|
||||
return inventory.Plan{}, nil, nil, err
|
||||
@@ -935,7 +977,7 @@ func deliveryCommand(ctx context.Context, args []string) error {
|
||||
walks[i].Phases = walks[i].WalkPhases(now, appliedFrom(ctx, inv))
|
||||
}
|
||||
return answer(map[string]any{"held": deliverySeatHeld(entries), "walks": walks,
|
||||
"own-path": sortedKeysOf(ownPathWords())})
|
||||
"own-path": sortedKeysOf(ownPathOf(entries))})
|
||||
}
|
||||
return fmt.Errorf("delivery %s: plan, order, check, go, stop, backups-again or walks", sub)
|
||||
}
|
||||
@@ -1006,9 +1048,6 @@ func recordWalkPhases(ctx context.Context, inv *inventory.Inventory, now time.Ti
|
||||
return nil
|
||||
}
|
||||
|
||||
// ownPathWords is the controller's own path as words, for an answer.
|
||||
func ownPathWords() map[string]string { return onTheControllersPath }
|
||||
|
||||
// theGraph is what the planner reads.
|
||||
func theGraph(ctx context.Context, inv *inventory.Inventory) ([]inventory.Entry, map[string][]inventory.ReadRepository,
|
||||
[]inventory.Edge, error) {
|
||||
|
||||
Reference in New Issue
Block a user