From 8baa3f5ada98b9584dae3834fb62abb87615e319 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 25 Nov 2026 17:16:13 +0100 Subject: [PATCH] mesh-provisioner: a read of a followed state before its copy is read is the fault away H-A-717's answer to DQ-55: the holder's handlers ask WatchedStates.Unread before they read the states it follows from its start; its own states, followed on first read, still wait. Builds: design 47 H2 H-A-708 (2), H-A-717 (DQ-55) --- .../cmd/mesh-provisioner/holder.go | 21 +++++++++++++++---- .../holder_integration_test.go | 4 ++++ .../cmd/mesh-provisioner/holder_test.go | 9 ++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/modules/mesh-provisioner/cmd/mesh-provisioner/holder.go b/modules/mesh-provisioner/cmd/mesh-provisioner/holder.go index 476dae2e5..963ad9157 100644 --- a/modules/mesh-provisioner/cmd/mesh-provisioner/holder.go +++ b/modules/mesh-provisioner/cmd/mesh-provisioner/holder.go @@ -1738,13 +1738,23 @@ 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 { + if !slices.Contains(WatchedReads, state) { + return nil + } + return w.ws.Unread(state) +} + func (w watchingStore) Get(state, key string) (*Entry, error) { - get := w.ws.Get - switch { - case !w.copied(state): + if !w.copied(state) { return w.Store.Get(state, key) } - v, found, err := 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 } @@ -1755,6 +1765,9 @@ 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) } diff --git a/modules/mesh-provisioner/cmd/mesh-provisioner/holder_integration_test.go b/modules/mesh-provisioner/cmd/mesh-provisioner/holder_integration_test.go index 5c529a0eb..2242eab4d 100644 --- a/modules/mesh-provisioner/cmd/mesh-provisioner/holder_integration_test.go +++ b/modules/mesh-provisioner/cmd/mesh-provisioner/holder_integration_test.go @@ -203,6 +203,10 @@ func TestTheHolderPlansProvidesAndAsksOnTheBus(t *testing.T) { return p } key := node + ".restic.postgres-database" + // The holder follows its states from its start (main.go), so a read finds its copies read (H-A-708 (2)). + for _, r := range WatchedReads { + ws.Follow(r, nil) + } if _, err := h.ComposeNode(ctx, node); err != nil { t.Fatal(err) } diff --git a/modules/mesh-provisioner/cmd/mesh-provisioner/holder_test.go b/modules/mesh-provisioner/cmd/mesh-provisioner/holder_test.go index dcd74f76f..e851efd0b 100644 --- a/modules/mesh-provisioner/cmd/mesh-provisioner/holder_test.go +++ b/modules/mesh-provisioner/cmd/mesh-provisioner/holder_test.go @@ -21,6 +21,7 @@ import ( oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel" "git.novox.be/novox/mesh-contracts/provisioning/go/clients/meshprovisionerclient" stdio "git.novox.be/novox/mesh-sdk/go" + "git.novox.be/novox/mesh-sdk/go/busretry" "git.novox.be/novox/mesh-sdk/go/catalogue" ) @@ -486,6 +487,14 @@ func TestAModuleHeldWithoutAWantIsComposedAtTheBuildItRuns(t *testing.T) { }, func(string, string) ([]byte, bool, error) { return nil, false, nil }) m.h.Store = Watching(bus, ws) 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) + } + for _, r := range []string{AssignmentsRead, WantsRead} { + ws.Follow(r, nil) + } for _, r := range []string{ComposedRead, HaveRead} { ws.Follow(r, func(c stdio.StateChange) error { wk.add(NodesOfNodeKey(c.Key)...); return nil }) }