B11: a package's number newly reserved is said as version-reserved
The indexer re-pinned every importer at each publish; it re-pins once at the reservation when the builder says version-reserved, with the package's path and the indexer's revision name. Builds: design 47 H2 §805; H-A-420 (2)
This commit is contained in:
@@ -252,6 +252,11 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
reserved.say = func(ctx context.Context, p meshbuilds.PackagePublished) error {
|
||||
return emitSeatEvent(context.WithoutCancel(ctx), js, cred, meshbuilds.SubjectPackagePublished, "package-published-"+p.Module+"-"+p.Version+"-"+p.Artifact, p)
|
||||
}
|
||||
// A package's number reserved is said as the seat mesh-builds' version-reserved, so the indexer re-pins at the reservation (§805).
|
||||
reserved.names = versions.NamesFrom(versions.EntriesOf(branches))
|
||||
reserved.sayReserved = func(ctx context.Context, ev meshbuilds.VersionReservedEvent) error {
|
||||
return emitSeatEvent(context.WithoutCancel(ctx), js, cred, meshbuilds.SubjectVersionReserved, "version-reserved-"+ev.Module+"-"+ev.Version+"-"+ev.Artifact, ev)
|
||||
}
|
||||
b.Reserved = reserved
|
||||
// A take-over of a series' reservation by another fingerprint withdraws the older build (H-A-225).
|
||||
reserved.withdraw = b.Withdraw
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@@ -58,6 +59,47 @@ type reservations struct {
|
||||
rebuild func(ctx context.Context, module, fp, why string) error
|
||||
// say says package-published on the seat mesh-builds; nil says none.
|
||||
say func(context.Context, meshbuilds.PackagePublished) error
|
||||
// names is each package's name as its series key names it (for Go, its module path), and sayReserved says version-reserved on
|
||||
// the seat mesh-builds (design 47 H2 §805); nil says none.
|
||||
names versions.PackageNames
|
||||
sayReserved func(context.Context, meshbuilds.VersionReservedEvent) error
|
||||
}
|
||||
|
||||
// reservedSaid says version-reserved of each package a reservation newly numbers (design 47 H2 §805, H-A-420 (2)): its module,
|
||||
// artifact, the package's path, the version, the fingerprint and the catalog revision it was reserved at, as the indexer names
|
||||
// a revision, `<branch>.<n>`. A reservation that names no catalog revision is said in the journal, not on the seat: the indexer
|
||||
// re-pins at a revision, and there is none to name.
|
||||
func (rv *reservations) reservedSaid(ctx context.Context, v versions.ReservedVersion) {
|
||||
if rv.sayReserved == nil || rv.names == nil {
|
||||
return
|
||||
}
|
||||
refs := make([]string, 0, len(v.Artifacts))
|
||||
for ref := range v.Artifacts {
|
||||
refs = append(refs, ref)
|
||||
}
|
||||
slices.Sort(refs)
|
||||
for _, ref := range refs {
|
||||
_, artifact, _ := strings.Cut(ref, ":")
|
||||
path, known, err := rv.names(ctx, v.Module, artifact)
|
||||
if err != nil {
|
||||
rv.logf("version-reserved of %s at %s is not said: its package's name cannot be read: %v", ref, v.Version, err)
|
||||
continue
|
||||
}
|
||||
if !known {
|
||||
continue // no package: nothing imports it by a version
|
||||
}
|
||||
if v.Branch == "" || v.Revision == 0 {
|
||||
rv.logf("version-reserved of %s at %s is not said: the reservation names no catalog revision to re-pin at", ref, v.Version)
|
||||
continue
|
||||
}
|
||||
ev := meshbuilds.VersionReservedEvent{Module: v.Module, Artifact: ref, Path: path, Version: v.Version, Fingerprint: v.Fingerprint,
|
||||
Revision: fmt.Sprintf("%s.%d", v.Branch, v.Revision)}
|
||||
if err := rv.sayReserved(ctx, ev); err != nil {
|
||||
rv.logf("the version-reserved of %s at %s is not said: %v", ref, v.Version, err)
|
||||
} else {
|
||||
rv.logf("version-reserved said: %s (%s) at %s, revision %s", ref, path, v.Version, ev.Revision)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// newReservations makes the reserving over store; the released versions of a module are asked of the seat mesh-catalog's
|
||||
@@ -79,7 +121,7 @@ func newReservations(store versions.ReserveStore, call toolCaller, bounds func()
|
||||
}
|
||||
return out, nil
|
||||
}}
|
||||
rv.r.Took, rv.r.Logf = rv.took, logf
|
||||
rv.r.Took, rv.r.Logf, rv.r.Reserved = rv.took, logf, rv.reservedSaid
|
||||
return rv
|
||||
}
|
||||
|
||||
|
||||
@@ -214,6 +214,27 @@ func TestAReleasedVersionIsTaggedAtTheCommitItWasBuiltFrom(t *testing.T) {
|
||||
if release("pkg", "0.1.1"); len(tags) != 1 || tags[0].Commit != "b0b" {
|
||||
t.Fatalf("the newer build's version: tags %+v; want go/v0.1.1 at b0b", tags)
|
||||
}
|
||||
// Design 47 H2 §805, H-A-420 (2): a package's number newly reserved is said as version-reserved, its path the package's name
|
||||
// and its revision the indexer's `<branch>.<n>`; a reservation kept as it stood, an artifact that is no package and a
|
||||
// reservation naming no catalog revision say none.
|
||||
var said []meshbuilds.VersionReservedEvent
|
||||
rv.names = func(_ context.Context, module, artifact string) (string, bool, error) {
|
||||
return "git.example/o/r/" + artifact, module == "lib2" && artifact == "pkg", nil
|
||||
}
|
||||
rv.sayReserved = func(_ context.Context, ev meshbuilds.VersionReservedEvent) error { said = append(said, ev); return nil }
|
||||
at := versions.Source{Repository: "o/r", Commit: "c1", Fingerprint: "src2:l2", GoPackage: true, Branch: "main", CatalogRevision: 158}
|
||||
for range 2 {
|
||||
if _, err := rv.Reserve(ctx, "lib2", "0.3", []string{"lib2:pkg", "lib2:bin"}, at); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if _, err := rv.Reserve(ctx, "lib2", "0.4", []string{"lib2:pkg"}, versions.Source{Fingerprint: "src2:none"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := meshbuilds.VersionReservedEvent{Module: "lib2", Artifact: "lib2:pkg", Path: "git.example/o/r/pkg", Version: "0.3.0", Fingerprint: "src2:l2", Revision: "main.158"}
|
||||
if len(said) != 1 || said[0] != want {
|
||||
t.Errorf("version-reserved said %+v, want once %+v", said, want)
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 G A-415: a published heard before the build recorded its digests is kept on its reservation, and when the build
|
||||
|
||||
@@ -145,6 +145,9 @@ type Reserver struct {
|
||||
// Took is told when a build took over the series' reservation of an older build never released (design 47 G A-455): the
|
||||
// older reservation, which no want follows any more, is gone from the key, replaced by the newer's. Nil is told none.
|
||||
Took func(ctx context.Context, older, newer ReservedVersion)
|
||||
// Reserved is told each reservation written, a number newly reserved (never one kept as it stood), so the holder says
|
||||
// version-reserved of its packages (design 47 H2 §805). Nil is told none.
|
||||
Reserved func(ctx context.Context, v ReservedVersion)
|
||||
// Releases is the builder's own record of the versions it saw released, by module and fingerprint (design 47 G A-456a): the
|
||||
// reservation is deleted at release, so a rerun of a released build's step reads it here, never from the catalog. Nil keeps none.
|
||||
Releases ReserveStore
|
||||
@@ -302,6 +305,9 @@ func (r *Reserver) Reserve(ctx context.Context, module, series string, artifacts
|
||||
if found && r.Took != nil {
|
||||
r.Took(ctx, cur, out)
|
||||
}
|
||||
if r.Reserved != nil {
|
||||
r.Reserved(ctx, out)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user