disk-load reads the node-engine's data state through the node-engine client and the seat's types (B5e; ADR 0634 §1, §4; issue 1966)
Claude-Session: https://claude.ai/code/session_01NcbgfFSnn24M3GcqttoU7i
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
// Where disk-load learns the data items it measures (novox/hq ADR 0577 clause 2): the node-engine's state data
|
||||
// (delivery.EngineDataBucket), one key `<node>.<module>` per module placed on this node that declares data items, as the
|
||||
// (engineDataBucket), one key `<node>.<module>` per module placed on this node that declares data items, as the
|
||||
// engine composed them. disk-load watches its own node's keys and composes nothing: it reads no resolved values, no
|
||||
// manifests and no placement, so a manifest its mesh-sdk cannot judge never silences it, and a round reads one watched
|
||||
// map instead of several hundred keys over the tunnel (issue 1955).
|
||||
@@ -12,11 +12,30 @@ import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
engineclient "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
|
||||
nodeengine "git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
"git.novox.be/novox/mesh-sdk/go/delivery"
|
||||
)
|
||||
|
||||
// The node-engine's state data as the bus names it: the seat's local name under its holder (the one name of the holder
|
||||
// here, held equal to the manifest's `reads` by a unit row).
|
||||
const (
|
||||
engineHolder = "mesh-host"
|
||||
engineDataBucket = engineHolder + "_" + nodeengine.StateData
|
||||
engineDataRead = engineHolder + "." + nodeengine.StateData
|
||||
)
|
||||
|
||||
// itemsOf are the seat's data items as this module measures them.
|
||||
func itemsOf(in []nodeengine.PlacedDataItem) []catalogue.PlacedDataItem {
|
||||
out := make([]catalogue.PlacedDataItem, 0, len(in))
|
||||
for _, it := range in {
|
||||
out = append(out, catalogue.PlacedDataItem{Module: it.Module, ID: it.Item, Class: it.Class, Path: it.Path,
|
||||
CoveredBy: it.CoveredBy, Protection: it.Protection, Measure: it.Measure})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Watched is this node's data items as the engine's state data holds them, by module, kept from a watch of its keys.
|
||||
type Watched struct {
|
||||
Node string
|
||||
@@ -29,7 +48,7 @@ type Watched struct {
|
||||
|
||||
// ErrNotWatchedYet is a round asked before the watch handed over the engine's current keys: no item is known yet, and
|
||||
// none is taken for gone.
|
||||
var ErrNotWatchedYet = errors.New("the node-engine's state " + delivery.EngineDataBucket + " is not watched yet: " +
|
||||
var ErrNotWatchedYet = errors.New("the node-engine's state " + engineDataBucket + " is not watched yet: " +
|
||||
"no data item of this machine is known")
|
||||
|
||||
// Take keeps one change of a key and answers the module it is of and whether its items changed.
|
||||
@@ -48,21 +67,22 @@ func (w *Watched) Take(ch stdio.StateChange) (string, bool, error) {
|
||||
delete(w.byModule, module)
|
||||
return module, true, nil
|
||||
}
|
||||
d, err := delivery.DecodeEngineData(ch.Value)
|
||||
d, err := engineclient.DecodeData(ch.Value)
|
||||
if err != nil {
|
||||
return "", false, fmt.Errorf("%s: %w", ch.Key, err)
|
||||
}
|
||||
if d.Node != w.Node {
|
||||
return "", false, fmt.Errorf("%s names the machine %q, and this is %s", ch.Key, d.Node, w.Node)
|
||||
}
|
||||
for _, it := range d.Items {
|
||||
items := itemsOf(d.Items)
|
||||
for _, it := range items {
|
||||
if it.Module != d.Module {
|
||||
return "", false, fmt.Errorf("%s holds an item of %q, and is %s's", ch.Key, it.Module, d.Module)
|
||||
}
|
||||
}
|
||||
changed := !sameItems(w.byModule[d.Module], d.Items)
|
||||
changed := !sameItems(w.byModule[d.Module], items)
|
||||
w.byKey[ch.Key] = d.Module
|
||||
w.byModule[d.Module] = d.Items
|
||||
w.byModule[d.Module] = items
|
||||
return d.Module, changed, nil
|
||||
}
|
||||
|
||||
@@ -102,11 +122,11 @@ func sameItems(a, b []catalogue.PlacedDataItem) bool {
|
||||
// Follow watches this node's keys of the engine's state data, and asks the keeper to measure a module whose items changed
|
||||
// after the watch began; it returns once the current keys were handed over (stdio.KeptState.Follow).
|
||||
func (w *Watched) Follow(k *Keeper) error {
|
||||
pattern, err := delivery.EngineDataNodeKeys(w.Node)
|
||||
pattern, err := engineclient.DataNodeKeys(w.Node)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
stdio.State(delivery.EngineDataRead).Follow(pattern, func(ch stdio.StateChange) error {
|
||||
stdio.State(engineDataRead).Follow(pattern, func(ch stdio.StateChange) error {
|
||||
module, changed, err := w.Take(ch)
|
||||
if err != nil || !changed || ch.Current {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user