The readers of the newest trunk revision read the newest again when it is removed under them

ModuleInNewestView, SeedEntryHeld, entryOf, SeedModulesFrom, the first fill of the versions, the outdated tool's trunk read and the verb
revision without a kept view use readNewestOf; none of them holds keepMu.

Builds: design 47 G A-487d (hq 61bf1215)
Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
2026-11-19 12:48:14 +01:00
parent e952ab721b
commit 00b452e57b
7 changed files with 49 additions and 37 deletions
@@ -229,3 +229,43 @@ func TestTrunkViewReadsTheNewerRevisionWhenTheOneNamedIsRemovedUnderIt(t *testin
t.Errorf("TrunkView read revision %d (%v), want 2", at, err)
}
}
// A-487d: the readers of the newest trunk revision in the indexer program (ModuleInNewestView, SeedEntryHeld, entryOf, the verb
// revision without a kept view) read the newest again when the revision they named is removed under them.
func TestTheNewestTrunkReadersReadAgainWhenTheRevisionIsRemovedUnderThem(t *testing.T) {
cases := map[string]func(ix *Indexer) (bool, error){
"ModuleInNewestView": func(ix *Indexer) (bool, error) { return ix.ModuleInNewestView(context.Background(), "avahi") },
"SeedEntryHeld": func(ix *Indexer) (bool, error) { return ix.SeedEntryHeld(context.Background(), "avahi", "fp2") },
"entryOf": func(ix *Indexer) (bool, error) {
e, err := ix.entryOf(context.Background(), "avahi")
return e.Fp == "fp2", err
},
"Revision": func(ix *Indexer) (bool, error) {
a, err := Revision(context.Background(), ix.Revisions, nil, "avahi", "avahi", meshcatalog.RevisionInput{})
return a.Revision.Revision == 2, err
},
}
for name, read := range cases {
t.Run(name, func(t *testing.T) {
mem := newMemObjects(0)
keep := func(revision int64) {
data, _ := json.Marshal(meshcatalog.CatalogEntry{Module: "avahi", Repository: catalogueRepo, None: "not built", Fp: fmt.Sprintf("fp%d", revision)})
digest := fmt.Sprintf("d%d", revision)
rev := meshcatalog.CatalogRevision{Revision: revision, Kind: "trunk", Entries: []meshcatalog.EntryRef{{Module: "avahi", Digest: digest}}}
if err := KeepRevision(context.Background(), mem, rev, map[string][]byte{digest: data}); err != nil {
t.Fatal(err)
}
}
keep(1)
objects := &goneUnderRead{memObjects: mem}
objects.prune = func() {
keep(2)
_ = mem.Delete(context.Background(), RevisionObject(meshcatalog.CatalogRevision{Revision: 1, Kind: "trunk"}))
_ = mem.Delete(context.Background(), EntryObject("d1"))
}
if ok, err := read(&Indexer{Revisions: objects}); err != nil || !ok {
t.Errorf("answered %v (%v), want revision 2's entry", ok, err)
}
})
}
}
@@ -3,7 +3,6 @@ package index
import (
"context"
"errors"
"fmt"
"slices"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
@@ -51,14 +50,10 @@ func (ix *Indexer) SeedEntryHeld(ctx context.Context, module, fp string) (bool,
if ctx.Err() != nil || ix.Revisions == nil {
return false, ctx.Err()
}
rev, found, err := newestTrunk(ctx, ix.Revisions)
_, entries, found, err := readNewestOf(ctx, ix.Revisions, TrunkBranch)
if err != nil || !found {
return false, err
}
_, entries, err := ReadRevision(ctx, ix.Revisions, fmt.Sprintf("trunk.%d", rev.Revision))
if err != nil {
return false, err
}
return slices.ContainsFunc(entries, func(e meshcatalog.CatalogEntry) bool { return e.Module == module && e.Fp == fp }), nil
}
@@ -67,14 +62,10 @@ func (ix *Indexer) ModuleInNewestView(ctx context.Context, module string) (bool,
if ctx.Err() != nil || ix.Revisions == nil {
return false, ctx.Err()
}
rev, found, err := newestTrunk(ctx, ix.Revisions)
_, entries, found, err := readNewestOf(ctx, ix.Revisions, TrunkBranch)
if err != nil || !found {
return false, err
}
_, entries, err := ReadRevision(ctx, ix.Revisions, fmt.Sprintf("trunk.%d", rev.Revision))
if err != nil {
return false, err
}
return slices.ContainsFunc(entries, func(e meshcatalog.CatalogEntry) bool { return e.Module == module }), nil
}
@@ -77,7 +77,7 @@ func Revision(ctx context.Context, o Objects, kept *KeptTrunk, holder, caller st
if kept != nil {
newest, trunkEntries, ok, err = kept.Newest(ctx, o)
} else {
newest, ok, err = newestTrunk(ctx, o)
newest, trunkEntries, ok, err = readNewestOf(ctx, o, TrunkBranch)
}
if err != nil {
return out, fmt.Errorf("the catalog graph revisions cannot be read: %w", err)
@@ -86,11 +86,6 @@ func Revision(ctx context.Context, o Objects, kept *KeptTrunk, holder, caller st
// An answer is told by its fields (design 47 G §530): no trunk revision kept yet is `none-yet`, no error.
return meshcatalog.RevisionAnswer{NoneYet: true}, nil
}
if kept == nil {
if _, trunkEntries, err = ReadRevision(ctx, o, RevisionObject(newest)); err != nil {
return out, err
}
}
caller = CallerModule(trunkEntries, caller)
if err := views.Refusal(meshcatalog.Seat+"."+meshcatalog.VerbRevision, RevisionCallers(trunkEntries, holder), caller); err != nil {
return out, fmt.Errorf("%w (novox/hq ADR 0663 §2: a part reads it by declaring %s in invokes)", err, RevisionInvoke)
@@ -63,17 +63,13 @@ func (ix *Indexer) SeedModulesFrom(ctx context.Context, defs map[string]seatdef.
if ix.Revisions == nil {
return nil, fmt.Errorf("the catalog graph is not kept here: no trunk revision to seed from")
}
rev, found, err := newestTrunk(ctx, ix.Revisions)
_, entries, found, err := readNewestOf(ctx, ix.Revisions, TrunkBranch)
if err != nil {
return nil, err
}
if !found {
return nil, fmt.Errorf("the indexer keeps no trunk revision yet: the seed waits for its first")
}
_, entries, err := ReadRevision(ctx, ix.Revisions, fmt.Sprintf("trunk.%d", rev.Revision))
if err != nil {
return nil, err
}
seatOf := map[string]string{} // artifact reference -> its build seat, all found before any call is made
unbuilt := map[string][]string{} // module -> each artifact of it no build seat builds, with its language or kind
for _, e := range entries {
@@ -177,17 +177,13 @@ func (ix *Indexer) entryOf(ctx context.Context, module string) (meshcatalog.Cata
if ix.Revisions == nil {
return meshcatalog.CatalogEntry{}, errors.New("the catalog graph is not kept here: no entry names the module's artifacts")
}
rev, found, err := newestTrunk(ctx, ix.Revisions)
_, entries, found, err := readNewestOf(ctx, ix.Revisions, TrunkBranch)
if err != nil {
return meshcatalog.CatalogEntry{}, err
}
if !found {
return meshcatalog.CatalogEntry{}, errors.New("the indexer keeps no trunk revision yet")
}
_, entries, err := ReadRevision(ctx, ix.Revisions, fmt.Sprintf("trunk.%d", rev.Revision))
if err != nil {
return meshcatalog.CatalogEntry{}, err
}
for _, e := range entries {
if e.Module == module {
return e, nil
@@ -194,11 +194,9 @@ func (ix *Indexer) Outdated(ctx context.Context, in meshcatalog.OutdatedInput) (
}
trunk := map[string]meshcatalog.CatalogEntry{} // the newest trunk revision's entries, read where a kind needs them
if ix.Revisions != nil {
if rev, found, err := newestTrunk(ctx, ix.Revisions); err == nil && found {
if _, entries, err := ReadRevision(ctx, ix.Revisions, fmt.Sprintf("trunk.%d", rev.Revision)); err == nil {
for _, e := range entries {
trunk[e.Module] = e
}
if _, entries, found, err := readNewestOf(ctx, ix.Revisions, TrunkBranch); err == nil && found {
for _, e := range entries {
trunk[e.Module] = e
}
}
}
@@ -79,17 +79,13 @@ func (ix *Indexer) FillVersions(ctx context.Context, ask VersionsAsker) error {
if ix.Revisions == nil {
return errors.New("the catalog graph is not kept here: no entry names the modules' artifacts")
}
rev, found, err := newestTrunk(ctx, ix.Revisions)
_, entries, found, err := readNewestOf(ctx, ix.Revisions, TrunkBranch)
if err != nil {
return err
}
if !found {
return errors.New("the indexer keeps no trunk revision yet: the first fill of the versions waits for its first")
}
_, entries, err := ReadRevision(ctx, ix.Revisions, fmt.Sprintf("trunk.%d", rev.Revision))
if err != nil {
return err
}
type found1 struct {
v BuilderVersion
name string