From 21b0b2430e5fa7f2b9ab3fb1a3380b723eaaddb8 Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 23 Nov 2026 00:19:12 +0100 Subject: [PATCH] Read assignments: skip a key that does not read, say it once, answer the rest One versionless module key of a retired module refused every reader of the assigner's whole assignments state (mesh-config's set among them). The read of another owner's state now skips such a key, says key and reason once through the process's standard log, and answers the rest; a node whose keys disagree is still an error. Builds: design 47 H2 H-A-509 (and its addendum (a)) --- .../meshmoduleassignerclient/client_test.go | 19 ++++++++++++++++++ go/clients/meshmoduleassignerclient/keys.go | 20 ++++++++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/go/clients/meshmoduleassignerclient/client_test.go b/go/clients/meshmoduleassignerclient/client_test.go index cbc750a..9dac45e 100644 --- a/go/clients/meshmoduleassignerclient/client_test.go +++ b/go/clients/meshmoduleassignerclient/client_test.go @@ -3,6 +3,8 @@ package meshmoduleassignerclient import ( "errors" "fmt" + "log" + "os" "reflect" "strings" "testing" @@ -146,6 +148,23 @@ func TestAssignmentsClient(t *testing.T) { if err != nil || !SameAssignments(got["g14"], g14) || len(got) != 1 { t.Fatalf("AssignmentsOf = %+v, %v", got, err) } + // H-A-509: a module key of a retired module, written before the value carried a version, is skipped and said once per + // key; the rest is answered and the read not refused. + var said strings.Builder + log.SetOutput(&said) + defer log.SetOutput(os.Stderr) + stale := map[string][]byte{"g14.retired": []byte(`{"node":"g14"}`)} + for k, v := range values { + stale[k] = v + } + for range 2 { + if got, err := AssignmentsOf(stale); err != nil || !SameAssignments(got["g14"], g14) || len(got) != 1 { + t.Fatalf("AssignmentsOf with a versionless key = %+v, %v", got, err) + } + } + if n := strings.Count(said.String(), "the assignments key g14.retired is skipped"); n != 1 || !strings.Contains(said.String(), "unknown value version") { + t.Errorf("the skipped key is said %d times, want once with its reason: %q", n, said.String()) + } if got := InsideAddresses(map[string]seat.Assignments{"g14": g14, "novox": novox, "x": {Node: "x"}, "y": {Node: "y", Decided: seat.NodeDecided{Address: " 10.77.0.1"}}}); strings.Join(got, ",") != "10.77.0.1,10.77.0.2" { t.Errorf("InsideAddresses = %v", got) } diff --git a/go/clients/meshmoduleassignerclient/keys.go b/go/clients/meshmoduleassignerclient/keys.go index 72a5bfc..15a2bef 100644 --- a/go/clients/meshmoduleassignerclient/keys.go +++ b/go/clients/meshmoduleassignerclient/keys.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "log" "sort" "strings" "sync" @@ -179,8 +180,10 @@ type keysOf struct { func NewKeys() *Keys { return &Keys{nodes: map[string]*keysOf{}} } // AssignmentsOf is every node's assignments assembled from the state's keys as a reader holds them (key to value; a -// deleted key absent), and an error naming every key that did not read and every node whose keys do not agree (that -// node is then assembled from its module keys' values as they are). +// deleted key absent), and an error naming every node whose keys do not agree (that node is then assembled from its +// module keys' values as they are). It is the read of another owner's state: a key whose value does not read is skipped, +// said once per key and reason through the process's standard log, and the rest answered (design 47 H2 H-A-509), so one +// stale key does not stop every reader of the whole state. func AssignmentsOf(keys map[string][]byte) (map[string]seat.Assignments, error) { k := NewKeys() var errs []error @@ -192,7 +195,7 @@ func AssignmentsOf(keys map[string][]byte) (map[string]seat.Assignments, error) for _, key := range names { // A node key read before its module keys does not agree yet; whether the keys agree is asked once all are in. if _, readErr, _ := k.put(key, keys[key], 0, false); readErr != nil { - errs = append(errs, readErr) + sayUnread(key, readErr) } } k.mu.Lock() @@ -205,6 +208,17 @@ func AssignmentsOf(keys map[string][]byte) (map[string]seat.Assignments, error) return k.All(), errors.Join(errs...) } +// unread is every key and reason AssignmentsOf has said it skips, so each is said once (design 47 H2 H-A-509). +var unread sync.Map + +// sayUnread says through the process's standard log that the key is skipped and why, once per key and reason. +func sayUnread(key string, err error) { + if _, said := unread.LoadOrStore(key+"\x00"+err.Error(), true); said { + return + } + log.Printf("meshmoduleassignerclient: the assignments key %s is skipped, the rest read: %v", key, err) +} + // Put takes one key's value in (revision: the bus's revision of it, 0 when the reader has none; deleted: a delete or a // purge). It answers the node the key is of and an error for a key or a value that does not read, or for a node whose // keys do not agree; the node then keeps what it had.