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:
@@ -1738,22 +1738,38 @@ func (w watchingStore) copied(state string) bool {
|
||||
return slices.Contains(WatchedReads, state) || slices.Contains(OwnStates, state)
|
||||
}
|
||||
|
||||
// unread is the fault `away` while the copy of a state the holder follows from its start is not read yet (design 47 H2
|
||||
// H-A-708 (2), H-A-717 DQ-55): a call made then is answered at once, never waits for the copy.
|
||||
func (w watchingStore) unread(state string) error {
|
||||
// Unread is the fault `away` while the copy of a state the holder follows from its start is not read yet (design 47 H2
|
||||
// H-A-708 (2), H-A-717 DQ-55). A verb or tool handler asks it (Holder.Away) so a call made then is answered at once; the
|
||||
// store's own reads, the passes' and the start's, wait for the copy.
|
||||
func (w watchingStore) Unread(state string) error {
|
||||
if !slices.Contains(WatchedReads, state) {
|
||||
return nil
|
||||
}
|
||||
return w.ws.Unread(state)
|
||||
}
|
||||
|
||||
// Away is the fault `away` when the copy of any of these states, or of every followed state when none is named, is not
|
||||
// read yet: a verb or tool handler asks it before it reads, never the passes (design 47 H2 H-A-708 (2)).
|
||||
func (h *Holder) Away(states ...string) error {
|
||||
u, ok := h.Store.(interface{ Unread(string) error })
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
if len(states) == 0 {
|
||||
states = WatchedReads
|
||||
}
|
||||
for _, state := range states {
|
||||
if err := u.Unread(state); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w watchingStore) Get(state, key string) (*Entry, error) {
|
||||
if !w.copied(state) {
|
||||
return w.Store.Get(state, key)
|
||||
}
|
||||
if err := w.unread(state); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v, found, err := w.ws.Get(state, key)
|
||||
if err != nil || !found {
|
||||
return nil, err
|
||||
@@ -1765,9 +1781,6 @@ func (w watchingStore) Keys(state string) ([]string, error) {
|
||||
if !w.copied(state) {
|
||||
return w.Store.Keys(state)
|
||||
}
|
||||
if err := w.unread(state); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return w.ws.Keys(state)
|
||||
}
|
||||
|
||||
|
||||
@@ -489,8 +489,16 @@ func TestAModuleHeldWithoutAWantIsComposedAtTheBuildItRuns(t *testing.T) {
|
||||
wk := &work{pending: map[string]bool{}, wake: make(chan struct{}, 1)}
|
||||
// H-A-708 (2): a state the holder follows from its start, asked before its copy is read, is the fault `away` at once.
|
||||
var away *busretry.Away
|
||||
if _, err := m.h.Store.Keys(WantsRead); !errors.As(err, &away) || !strings.HasPrefix(away.Words, "not read yet since ") || len(watches) != 0 {
|
||||
t.Fatalf("a read before the copy: %v, watches %v", err, watches)
|
||||
// A handler asks Away and is answered at once; the holder's own reads (the passes, the start) wait, so the first read
|
||||
// starts the watch and is answered from it, never `away`.
|
||||
if err := m.h.Away(); !errors.As(err, &away) || !strings.HasPrefix(away.Words, "not read yet since ") || len(watches) != 0 {
|
||||
t.Fatalf("a handler's ask before the copy: %v, watches %v", err, watches)
|
||||
}
|
||||
if _, err := m.h.Store.Keys(WantsRead); err != nil || watches[WantsRead] != 1 {
|
||||
t.Fatalf("the holder's own read before the copy is read: %v, watches %v", err, watches)
|
||||
}
|
||||
if _, err := m.h.read(WantsRead, "", "", ""); err != nil {
|
||||
t.Fatalf("a handler's read of a state whose copy is read: %v", err)
|
||||
}
|
||||
for _, r := range []string{AssignmentsRead, WantsRead} {
|
||||
ws.Follow(r, nil)
|
||||
|
||||
@@ -79,6 +79,9 @@ func holderTools(h *Holder) []stdio.Tool {
|
||||
if arg(a, "node") == "" {
|
||||
return nil, fmt.Errorf("compose names the node")
|
||||
}
|
||||
if err := h.Away(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
many, _ := a["retire-many"].(bool)
|
||||
return h.ComposeNodeWith(context.Background(), arg(a, "node"), many)
|
||||
}},
|
||||
@@ -118,6 +121,9 @@ func (h *Holder) health() health.Answer {
|
||||
|
||||
// read is a state's keys narrowed, or one whole, with the state's fill.
|
||||
func (h *Holder) read(state, key, node, want string) (any, error) {
|
||||
if err := h.Away(state); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if key != "" {
|
||||
e, err := h.Store.Get(state, key)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user