From 499bb15eae7481bac2dca93315303ee64353a3d5 Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 27 Nov 2026 03:01:31 +0100 Subject: [PATCH] I1 wants-heard-in-order: the indexer orders a wanted by its want-revision MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit HearWanted keeps the want-revision beside at for each member: a wanted at a want-revision below the one held changes nothing whatever its time, a repeat writes nothing new, and a removal is ordered against a later want by it. An event naming none is ordered by at as before. A row holds that a tier-late said after its running changes nothing. Builds: design 47 H2b §832 5., H-A-832 --- .../internal/index/named.go | 44 +++++++++++++------ .../internal/index/pins_test.go | 2 + .../internal/index/wanted_names_test.go | 14 +++++- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/modules/mesh-delivery-indexer/internal/index/named.go b/modules/mesh-delivery-indexer/internal/index/named.go index 0de600627..d77d8fde4 100644 --- a/modules/mesh-delivery-indexer/internal/index/named.go +++ b/modules/mesh-delivery-indexer/internal/index/named.go @@ -44,10 +44,13 @@ func NamedKey(fingerprint string) string { return keys.EscapeName(fingerprint) } // NamedMember is the member of a node's module in a set. func NamedMember(node, module string) string { return node + "." + module } -// namedAt is the fingerprint one source last named for a member, and when it said so. +// namedAt is the fingerprint one source last named for a member, and when it said so. rev is the `want-revision` a want +// carried (0 when it carried none, as an older event or a running build): a want is ordered by it, never by a say's time +// (design 47 H2b §832 5.). type namedAt struct { - fp string - at time.Time + fp string + at time.Time + rev int64 } // Named keeps the sets. What each member's want and running last named is held in memory only, read again at every start from @@ -65,6 +68,7 @@ type Named struct { want map[string]namedAt run map[string]namedAt gone map[string]time.Time // the want of a member removed (§693), when + goneR map[string]int64 // the `want-revision` of the write that removal removed, 0 when it named none reads map[string]bool // the streams read whole at the start ready bool // failed holds the first event that could not be applied while the start read ran: what it named is unknown, so the @@ -77,7 +81,7 @@ func NewNamed(store Store, logf func(string, ...any)) *Named { if logf == nil { logf = func(string, ...any) {} } - return &Named{Store: store, Logf: logf, want: map[string]namedAt{}, run: map[string]namedAt{}, gone: map[string]time.Time{}, reads: map[string]bool{}} + return &Named{Store: store, Logf: logf, want: map[string]namedAt{}, run: map[string]namedAt{}, gone: map[string]time.Time{}, goneR: map[string]int64{}, reads: map[string]bool{}} } // Ready says the two streams were read whole and the sets reconciled with them: until then no entry object is removed, so a @@ -102,7 +106,7 @@ func (n *Named) HearWanted(ctx context.Context, data []byte) error { if e.At != nil { at = *e.At } - return n.apply(ctx, NamedMember(e.Node, e.Module), true, e.Fp, at, e.Removed) + return n.apply(ctx, NamedMember(e.Node, e.Module), true, e.Fp, at, e.WantRevision, e.Removed) } // HearRunning applies one running event: the build it names; a stopped one, or one with no fingerprint, names none (design 47 @@ -119,14 +123,14 @@ func (n *Named) HearRunning(ctx context.Context, data []byte) error { if r.Stopped { fp = "" } - return n.apply(ctx, NamedMember(r.Node, r.Module), false, fp, r.At, false) + return n.apply(ctx, NamedMember(r.Node, r.Module), false, fp, r.At, 0, false) } // apply changes what one source names for the member and writes the sets it moves; one at a time, so the two sources never // write one set from a stale view of each other. -func (n *Named) apply(ctx context.Context, member string, wanted bool, fp string, at time.Time, removed bool) error { +func (n *Named) apply(ctx context.Context, member string, wanted bool, fp string, at time.Time, rev int64, removed bool) error { n.mu.Lock() - moved, err := n.applyLocked(ctx, member, wanted, fp, at, removed) + moved, err := n.applyLocked(ctx, member, wanted, fp, at, rev, removed) if err != nil && !n.ready && n.failed == nil { n.failed = err } @@ -137,13 +141,17 @@ func (n *Named) apply(ctx context.Context, member string, wanted bool, fp string return err } -func (n *Named) applyLocked(ctx context.Context, member string, wanted bool, fp string, at time.Time, removed bool) (bool, error) { +func (n *Named) applyLocked(ctx context.Context, member string, wanted bool, fp string, at time.Time, rev int64, removed bool) (bool, error) { src := n.run if wanted { src = n.want } old, had := src[member] - if had && at.Before(old.at) { + // A want that names its `want-revision` is ordered by it against one that names its own, never by the time it was said + // (design 47 H2b §832 5.): one at a revision below the held want's changes nothing, and a repeat of it writes nothing new. + // An event that names none, or a held one that named none, is ordered by `at`, as a running build is. + byRev := wanted && had && rev > 0 && old.rev > 0 + if byRev && rev < old.rev || !byRev && had && at.Before(old.at) { return false, nil // an event older than the one heard changes nothing } var touched []string @@ -158,22 +166,32 @@ func (n *Named) applyLocked(ctx context.Context, member string, wanted bool, fp delete(n.run, member) } delete(n.want, member) - n.gone[member] = at + n.gone[member], n.goneR[member] = at, rev touched = append(touched, fp) - case !n.gone[member].IsZero() && !at.After(n.gone[member]): + case !n.gone[member].IsZero() && n.goneRemoved(member, wanted, at, rev): return false, nil // an event older than the removal of the want it belongs to case fp == "": delete(src, member) default: if wanted { delete(n.gone, member) + delete(n.goneR, member) } - src[member] = namedAt{fp: fp, at: at} + src[member] = namedAt{fp: fp, at: at, rev: rev} touched = append(touched, fp) } return n.writeSets(ctx, member, touched) } +// goneRemoved says whether an event is older than the removal of the member's want: a want that names its `want-revision` +// is older when its revision does not pass the removed write's, any other event when it was said before the removal. +func (n *Named) goneRemoved(member string, wanted bool, at time.Time, rev int64) bool { + if wanted && rev > 0 && n.goneR[member] > 0 { + return rev <= n.goneR[member] + } + return !at.After(n.gone[member]) +} + // holds says whether either source names fp for the member. func (n *Named) holds(member, fp string) bool { return n.want[member].fp == fp || n.run[member].fp == fp diff --git a/modules/mesh-delivery-indexer/internal/index/pins_test.go b/modules/mesh-delivery-indexer/internal/index/pins_test.go index 42ef466a8..208d6a084 100644 --- a/modules/mesh-delivery-indexer/internal/index/pins_test.go +++ b/modules/mesh-delivery-indexer/internal/index/pins_test.go @@ -245,6 +245,8 @@ func TestTheIndexerRemovesARevisionOnlyWhenNoRecordPinsItAndItIsNotCurrent(t *te wanted(7, meshwants.PipelineWantedOutcomeRunning) wanted(7, meshwants.PipelineWantedOutcomeRunning) // heard twice: changes nothing more want("the newer release written everywhere", "main.7") + wanted(7, meshwants.PipelineWantedOutcomeTierLate) // 1984/AC-832l (design 47 H2b §832 5.): said again after its running, it changes nothing + want("a tier-late after its running", "main.7") if v, _, _, _ := ix.Pins.Get(ctx, "main.7"); !slices.Equal(mustRecords(t, v), []string{ReleaseRecord("main", "reader")}) { t.Errorf("the pin of main.7 holds %s, want its release alone", v) } diff --git a/modules/mesh-delivery-indexer/internal/index/wanted_names_test.go b/modules/mesh-delivery-indexer/internal/index/wanted_names_test.go index d7a136cd5..dd26653ee 100644 --- a/modules/mesh-delivery-indexer/internal/index/wanted_names_test.go +++ b/modules/mesh-delivery-indexer/internal/index/wanted_names_test.go @@ -27,6 +27,7 @@ type namedEvent struct { module string fp string min int + rev int64 // the want-revision a wanted names, 0 for none removed bool stopped bool } @@ -37,7 +38,7 @@ func (e namedEvent) apply(t *testing.T, n *Named) { var data []byte var err error if e.wanted { - data, err = json.Marshal(meshwants.WantedEvent{V: 1, Node: e.node, Module: e.module, Fp: e.fp, Revision: 1, Removed: e.removed, At: &at}) + data, err = json.Marshal(meshwants.WantedEvent{V: 1, Node: e.node, Module: e.module, Fp: e.fp, Revision: 1, WantRevision: e.rev, Removed: e.removed, At: &at}) if err == nil { err = n.HearWanted(context.Background(), data) } @@ -77,6 +78,17 @@ func TestNamedHoldsTheMembersWhoseWantOrRunningBuildNamesAFingerprint(t *testing {wanted: true, node: "n1", module: "m", fp: a, min: 1, removed: true}, {node: "n1", module: "m", fp: a, min: 0}}, map[string][]string{a: nil}}, {"an event older than the one heard changes nothing", []namedEvent{ {wanted: true, node: "n1", module: "m", fp: b, min: 5}, {wanted: true, node: "n1", module: "m", fp: a, min: 4}}, map[string][]string{a: nil, b: {"n1.m"}}}, + // 1984/AC-832l, AC-832t (design 47 H2b §832 5., H-A-832): a want is ordered by its want-revision, never by a say's time. + {"a want at a lower want-revision changes nothing, whatever its time", []namedEvent{ + {wanted: true, node: "n1", module: "m", fp: b, min: 1, rev: 5}, {wanted: true, node: "n1", module: "m", fp: a, min: 9, rev: 4}}, map[string][]string{a: nil, b: {"n1.m"}}}, + {"a want at a higher want-revision wins over a later time", []namedEvent{ + {wanted: true, node: "n1", module: "m", fp: a, min: 9, rev: 4}, {wanted: true, node: "n1", module: "m", fp: b, min: 1, rev: 5}}, map[string][]string{a: nil, b: {"n1.m"}}}, + {"a repeat of an applied want writes nothing new, under any time", []namedEvent{ + {wanted: true, node: "n1", module: "m", fp: a, min: 1, rev: 3}, {wanted: true, node: "n1", module: "m", fp: a, min: 8, rev: 3}}, map[string][]string{a: {"n1.m"}, b: nil}}, + {"a removal of a write below the held want's changes nothing", []namedEvent{ + {wanted: true, node: "n1", module: "m", fp: a, min: 1, rev: 6}, {wanted: true, node: "n1", module: "m", fp: a, min: 9, rev: 5, removed: true}}, map[string][]string{a: {"n1.m"}}}, + {"a want written after a removal at a higher want-revision brings the member back, whatever its time", []namedEvent{ + {wanted: true, node: "n1", module: "m", fp: a, min: 5, rev: 6, removed: true}, {wanted: true, node: "n1", module: "m", fp: a, min: 1, rev: 7}}, map[string][]string{a: {"n1.m"}}}, } { t.Run(c.name, func(t *testing.T) { st := newMem()