mesh-config, mesh-provisioner: Unread is asked in the verb and tool handlers only, the module's own start keeps the waiting read (review r1 finding 3)
Builds: design 47 H2 H-A-708 (2)
This commit is contained in:
@@ -58,6 +58,30 @@ func (r runtimeStore) Get(state, key string) (*Entry, error) {
|
||||
return &Entry{Key: e.Key, Value: e.Value, Revision: e.Revision}, nil
|
||||
}
|
||||
|
||||
// Away is the fault `away` while a copy of this module's own states is not read yet: a verb or tool handler asks it
|
||||
// (asking), the module's own start never does (design 47 H2 H-A-708 (2)). The first views of the owners stay the fault
|
||||
// `away` at the read itself, since a picture not answered yet is no answer for a pass to resolve from.
|
||||
func (r runtimeStore) Away() error {
|
||||
if r.own == nil {
|
||||
return nil
|
||||
}
|
||||
return r.own.Unread()
|
||||
}
|
||||
|
||||
// asking is a tool whose handler answers `away` at once while what it reads is not read yet (design 47 H2 H-A-708 (2)).
|
||||
func asking(c *Config, t stdio.Tool) stdio.Tool {
|
||||
run := t.Run
|
||||
t.Run = func(a map[string]any) (any, error) {
|
||||
if s, ok := c.Store.(interface{ Away() error }); ok {
|
||||
if err := s.Away(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return run(a)
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
func (r runtimeStore) Put(state, key string, value any) error {
|
||||
if r.own != nil && ownStates[state] {
|
||||
return r.own.write(state, key, value)
|
||||
@@ -418,7 +442,11 @@ func Tools(c *Config) []stdio.Tool {
|
||||
rows, err := c.Renames(strings.TrimSpace(m), true)
|
||||
return map[string]any{"renames": seatRenames(rows)}, err
|
||||
}}
|
||||
return append(append(switchTools(c), viewTools(c, func() *ownerViews { return theViews })...), renames, stdio.Tool{
|
||||
var own []stdio.Tool
|
||||
for _, t := range switchTools(c) {
|
||||
own = append(own, asking(c, t))
|
||||
}
|
||||
return append(append(own, viewTools(c, func() *ownerViews { return theViews })...), asking(c, renames), asking(c, stdio.Tool{
|
||||
Name: Seat + "." + Verb,
|
||||
Description: "Set, clear, list or read the history of config values (novox/hq ADR 0348). A value is set at " +
|
||||
"one level: mesh config (no module, no node) or node config (a node) for a predefined key, or a " +
|
||||
@@ -452,7 +480,7 @@ func Tools(c *Config) []stdio.Tool {
|
||||
call.Caller = stdio.CallerOf(args)
|
||||
return c.Do(call)
|
||||
},
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
// callOf reads a call's arguments strictly: an argument it does not know is refused, not ignored.
|
||||
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"sort"
|
||||
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
)
|
||||
@@ -36,10 +37,8 @@ func newOwnCopy() *ownCopy {
|
||||
}
|
||||
|
||||
func (o *ownCopy) get(state, key string) (*Entry, error) {
|
||||
// A state whose copy is not read yet is the fault `away` at once, never a wait (design 47 H2 H-A-708 (2)).
|
||||
if err := o.copy.Unread(state); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// A read waits for a state whose copy is not read yet: the module's own start (the first decision, the deadline, the
|
||||
// start judgement) is one. A verb or tool handler asks Unread first (design 47 H2 H-A-708 (2)).
|
||||
raw, ok, err := o.copy.Get(state, key)
|
||||
if err != nil || !ok {
|
||||
return nil, err
|
||||
@@ -48,14 +47,28 @@ func (o *ownCopy) get(state, key string) (*Entry, error) {
|
||||
}
|
||||
|
||||
func (o *ownCopy) keys(state string) ([]string, error) {
|
||||
if err := o.copy.Unread(state); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return o.copy.Keys(state)
|
||||
}
|
||||
|
||||
// follow starts the watch of every state the copy holds, each on its goroutine, so a read asked before one is in is
|
||||
// answered `away` and the copy is read by the time it is asked again (Unread; design 47 H2 H-A-708 (2)).
|
||||
// Unread is the fault `away` naming the first state, in name order, whose copy is not read yet, nil when every one is: a
|
||||
// verb or tool handler asks it before it reads, so a call made while the module starts is answered at once (design 47 H2
|
||||
// H-A-708 (2)); the module's own reads wait for the copy.
|
||||
func (o *ownCopy) Unread() error {
|
||||
states := make([]string, 0, len(ownStates))
|
||||
for state := range ownStates {
|
||||
states = append(states, state)
|
||||
}
|
||||
sort.Strings(states)
|
||||
for _, state := range states {
|
||||
if err := o.copy.Unread(state); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// follow starts the watch of every state the copy holds, each on its goroutine, so a handler's ask is answered `away` until
|
||||
// the copy is read (Unread; design 47 H2 H-A-708 (2)).
|
||||
func (o *ownCopy) follow() {
|
||||
for state := range ownStates {
|
||||
go o.copy.Follow(state, nil)
|
||||
|
||||
@@ -204,15 +204,24 @@ func TestAnOwnStateIsReadFromItsWatchedCopyNotKeyByKey(t *testing.T) {
|
||||
}
|
||||
n := len(b.held[ValuesState])
|
||||
own := b.ownCopy()
|
||||
// H-A-708 (2): before the state's copy is read a read is the fault `away` at once, naming the state; the start's watch reads it.
|
||||
// H-A-708 (2): a handler asks Unread and is answered `away` at once, naming the state; the module's own read waits for the
|
||||
// copy, which the start's watch reads, so its first decision and its deadline are never lost to `away`.
|
||||
var away *busretry.Away
|
||||
if _, err := own.keys(ValuesState); !errors.As(err, &away) || away.Part != "the state "+ValuesState || !strings.HasPrefix(away.Words, "not read yet since ") {
|
||||
if err := own.Unread(); !errors.As(err, &away) || !strings.HasPrefix(away.Part, "the state ") || !strings.HasPrefix(away.Words, "not read yet since ") {
|
||||
t.Fatalf("before the copy is read: %v", err)
|
||||
}
|
||||
if _, err := own.get(ValuesState, "mesh.key-0s"); !errors.As(err, &away) {
|
||||
t.Fatalf("a get before the copy is read: %v", err)
|
||||
c := &Config{Store: runtimeStore{own: own}}
|
||||
ran := false
|
||||
tool := asking(c, stdio.Tool{Name: "t", Run: func(map[string]any) (any, error) { ran = true; return nil, nil }})
|
||||
if _, err := tool.Run(nil); !errors.As(err, &away) || ran {
|
||||
t.Fatalf("a tool's handler before the copy is read: ran %v, %v", ran, err)
|
||||
}
|
||||
waited := make(chan error, 1)
|
||||
go func() { _, err := own.keys(ValuesState); waited <- err }()
|
||||
own.copy.Follow(ValuesState, nil)
|
||||
if err := <-waited; err != nil {
|
||||
t.Fatalf("the module's own read before the copy is read must wait for it, not answer away: %v", err)
|
||||
}
|
||||
for pass := 0; pass < 3; pass++ {
|
||||
keys, err := own.keys(ValuesState)
|
||||
if err != nil || len(keys) != n {
|
||||
|
||||
Reference in New Issue
Block a user