Builder: the finding version-unreleased is timed by publish-ack-minutes, the constant UnreleasedBound goes

Builds: design 47 H2 H-A-613 (3), principle 11
This commit is contained in:
2026-11-25 20:00:49 +01:00
parent f6c8fa46e0
commit 7614f74414
6 changed files with 71 additions and 18 deletions
@@ -235,6 +235,11 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
// heard (design 47 H2 H-A-552: no fill is waited for).
reservedKV := process.AwaitBucket(ctx, js, conn, own.reserved, "no version is reserved: builds are made unreserved", logger.Printf)
reserved := newReservations(awaitedReserved{awaitedState{b: reservedKV, bucket: own.reserved}}, calls.Call, pubBoundsKV.KV, found, logger.Printf)
publishAck, err := numberFile(getenv("MESH_BUILDER_PUBLISH_ACK_FILE"), defaultPublishAckMinutes)
if err != nil {
return err
}
reserved.setBound(time.Duration(publishAck) * time.Minute) // the finding version-unreleased is timed by the same setting (H-A-613 (3))
// The index by digest and by version beside the reservations is written again once the state is bound (H-A-269 (1), H-A-271).
reservedKV.Ready(func(jetstream.KeyValue) { reserved.reindex(ctx) })
// Each artifact the holder says published at a reserved version is said as the seat mesh-builds' package-published (design 47 G §52).
@@ -289,10 +294,6 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
reserved.r.HeldElsewhere = func(ctx context.Context, module string, skipped []string) {
reserved.heldElsewhere(ctx, module, "the registries hold "+strings.Join(skipped, ", ")+", so the reserve skipped them")
}
publishAck, err := numberFile(getenv("MESH_BUILDER_PUBLISH_ACK_FILE"), defaultPublishAckMinutes)
if err != nil {
return err
}
republishMax, err := numberFile(getenv("MESH_BUILDER_REPUBLISH_MAX_FILE"), versions.DefaultRepublishMaxVersions)
if err != nil {
return err
@@ -119,7 +119,7 @@ func sayReservedOn(js jetstream.JetStream, cred process.Account) func(context.Co
// newReservations makes the reserving over store; the released versions of a module are asked of the seat mesh-catalog's
// verb versions through call (design 47 G §348), the only source numbering reads them from.
func newReservations(store versions.ReserveStore, call toolCaller, bounds func() jetstream.KeyValue, found *findings, logf func(string, ...any)) *reservations {
rv := &reservations{bounds: bounds, found: found, bound: versions.UnreleasedBound, logf: logf}
rv := &reservations{bounds: bounds, found: found, bound: defaultPublishAckMinutes * time.Minute, logf: logf}
rv.r = &versions.Reserver{Store: store, ReleasedOf: func(_ context.Context, module string) ([]string, error) {
raw, err := call("seat:"+meshcatalog.Seat+".versions", meshcatalog.VersionsInput{Module: module})
if err != nil {
@@ -136,9 +136,17 @@ func newReservations(store versions.ReserveStore, call toolCaller, bounds func()
return out, nil
}}
rv.r.Took, rv.r.Logf, rv.r.Reserved = rv.took, logf, rv.reservedSaid
rv.setBound(rv.bound)
return rv
}
// setBound sets the publish's bound, the setting publish-ack-minutes (design 47 H2 H-A-613 (3)): past it a built reservation
// with an artifact unpublished is the finding version-unreleased, armed and judged by this one value.
func (rv *reservations) setBound(d time.Duration) {
rv.bound = d
rv.r.Bound = d
}
// reindex writes the reservations' index again from the reservations, once at the builder's start (H-A-269 (1), H-A-271), and
// says so.
func (rv *reservations) reindex(ctx context.Context) {
@@ -495,13 +495,27 @@ func TestABuiltReservationIsTakenInFromItsState(t *testing.T) {
if !slices.Equal(said, []string{"look:a@" + v.Version + " sha256:looka"}) || !slices.Equal(asked, []string{"look " + v.Version}) {
t.Errorf("at a look: said %v, publish items asked %v; want look:a's package-published said and its item asked", said, asked)
}
if ends := boundEnds("look"); !ends.Equal(v.BuiltAt.Add(versions.UnreleasedBound)) {
t.Errorf("the bound armed at a look ends %v, want %v: counted from the build's end", ends, v.BuiltAt.Add(versions.UnreleasedBound))
if ends := boundEnds("look"); !ends.Equal(v.BuiltAt.Add(defaultPublishAckMinutes*time.Minute)) {
t.Errorf("the bound armed at a look ends %v, want %v: counted from the build's end", ends, v.BuiltAt.Add(defaultPublishAckMinutes*time.Minute))
}
if cur, _, _ := rv.r.Of(ctx, "look", v.Version); len(cur.Kept) != 0 || !cur.Published["look:a"] {
t.Errorf("after the look: kept %v, published %v; want the kept published taken in", cur.Kept, cur.Published)
}
})
t.Run("at a look with publish-ack-minutes at 30", func(t *testing.T) {
rv.setBound(30 * time.Minute)
defer rv.setBound(defaultPublishAckMinutes * time.Minute)
v := recordedLost("thirty", now.Add(-5*time.Minute), "a")
if err := rv.Built(ctx, "thirty", v.Version, v.Artifacts, nil); err != nil {
t.Fatal(err)
}
if ends := boundEnds("thirty"); !ends.Equal(v.BuiltAt.Add(30 * time.Minute)) {
t.Errorf("the bound armed ends %v, want %v: the setting's 30 minutes, not 10", ends, v.BuiltAt.Add(30*time.Minute))
}
if unreleased("thirty") != "" {
t.Errorf("a build 5 minutes old raised %s with the bound at 30 minutes", unreleased("thirty"))
}
})
t.Run("at the start", func(t *testing.T) {
v := recordedLost("start", now.Add(-time.Minute), "a")
said = nil
@@ -516,7 +530,7 @@ func TestABuiltReservationIsTakenInFromItsState(t *testing.T) {
t.Run("past its bound", func(t *testing.T) {
for _, when := range []string{"a look", "the start"} {
module := map[string]string{"a look": "pastlook", "the start": "paststart"}[when]
v := recordedLost(module, now.Add(-versions.UnreleasedBound-time.Minute), "a")
v := recordedLost(module, now.Add(-defaultPublishAckMinutes*time.Minute-time.Minute), "a")
takeIn := func() {
if when == "a look" {
if err := rv.Built(ctx, module, v.Version, v.Artifacts, nil); err != nil {
@@ -543,7 +557,7 @@ func TestABuiltReservationIsTakenInFromItsState(t *testing.T) {
// Note 8's own case: every artifact's published kept on it is taken in before its bound is judged, so nothing is
// unpublished and nothing is raised; each is said as package-published.
module = map[string]string{"a look": "keptlook", "the start": "keptstart"}[when]
v = recordedLost(module, now.Add(-versions.UnreleasedBound-time.Minute), "a", "b")
v = recordedLost(module, now.Add(-defaultPublishAckMinutes*time.Minute-time.Minute), "a", "b")
said = nil
takeIn()
if got := unreleased(module); got != "" {
@@ -47,7 +47,7 @@ type republishBed struct {
func newRepublishBed(t *testing.T) *republishBed {
t.Helper()
b := &republishBed{reserved: &reserveMem{mem: newMem()}, now: time.Date(2026, 11, 11, 12, 0, 0, 0, time.UTC), ids: map[string]bool{}}
res := &Reserver{Store: b.reserved, Now: func() time.Time { return b.now }, ReleasedOf: func(context.Context, string) ([]string, error) { return nil, nil }}
res := &Reserver{Store: b.reserved, Bound: testBound, Now: func() time.Time { return b.now }, ReleasedOf: func(context.Context, string) ([]string, error) { return nil, nil }}
b.Republisher = &Republisher{Reserved: res, Now: func() time.Time { return b.now },
Entry: func(_ context.Context, fp string) (meshcatalog.CatalogEntry, error) {
if fp == "src2:holder" {
@@ -112,7 +112,7 @@ func (b *republishBed) reserve(t *testing.T, module string) ReservedVersion {
if _, _, err := b.Reserved.Built(ctx, module, v.Version, map[string]string{module + ":prog": "sha256:aa", module + ":lib": "sha256:bb"}, nil); err != nil {
t.Fatal(err)
}
b.now = b.now.Add(UnreleasedBound + time.Minute)
b.now = b.now.Add(testBound + time.Minute)
return v
}
@@ -31,9 +31,6 @@ const (
// ReservedTool is builder_reserved, ReservedDropTool builder_reserved_drop.
ReservedTool = "builder_reserved"
ReservedDropTool = "builder_reserved_drop"
// UnreleasedBound is the publish's bound: past it a built reservation with an artifact unpublished is the finding
// version-unreleased (§369).
UnreleasedBound = 10 * time.Minute
// VersionUnreleased is that finding.
VersionUnreleased = "version-unreleased"
// VersionHeldElsewhere is the finding of a number a registry seat already holds, skipped at reserving or moved from (design 47
@@ -151,6 +148,9 @@ type ReserveStore interface {
// Reserver reserves versions.
type Reserver struct {
Store ReserveStore
// Bound is the publish's bound, the setting publish-ack-minutes (design 47 H2 H-A-613 (3)): past it a built reservation with an
// artifact unpublished is the finding version-unreleased (§369).
Bound time.Duration
// ReleasedOf are the patch versions (MAJOR.MINOR.PATCH) the catalog holds released for module, from its verb versions.
ReleasedOf func(ctx context.Context, module string) ([]string, error)
// Took is told when a build took over the series' reservation of an older build never released (design 47 G A-455): the
@@ -718,7 +718,7 @@ func (r *Reserver) Released(ctx context.Context, module, version string) ([]stri
return gone, nil
}
// Unreleased are the reservations whose build ended more than UnreleasedBound before now with an artifact unpublished:
// Unreleased are the reservations whose build ended more than Reserver.Bound before now with an artifact unpublished:
// the finding version-unreleased, naming the module, the version and the artifacts missing (published says whether an
// artifact is). A reservation whose build has not ended is not one.
type Unreleased struct {
@@ -739,7 +739,7 @@ func (r *Reserver) Overdue(ctx context.Context, published func(module, version,
if err != nil {
return nil, err
}
if !found || cur.BuiltAt.IsZero() || r.now().Sub(cur.BuiltAt) < UnreleasedBound {
if !found || cur.BuiltAt.IsZero() || r.now().Sub(cur.BuiltAt) < r.Bound {
continue
}
var missing []string
@@ -39,7 +39,7 @@ func TestReservation(t *testing.T) {
now := time.Date(2026, 11, 11, 12, 0, 0, 0, time.UTC)
released := []string{"0.1.18", "0.1.19", "0.2.7"}
store := &reserveMem{mem: newMem()}
r := &Reserver{Store: store, Now: func() time.Time { return now },
r := &Reserver{Store: store, Bound: testBound, Now: func() time.Time { return now },
ReleasedOf: func(context.Context, string) ([]string, error) { return released, nil }}
arts := []string{"m:a", "m:b"}
@@ -83,7 +83,7 @@ func TestReservation(t *testing.T) {
if got, _ := r.Overdue(ctx, published); len(got) != 0 {
t.Fatalf("unreleased before the bound: %v", got)
}
now = now.Add(UnreleasedBound)
now = now.Add(testBound)
got, err := r.Overdue(ctx, published)
want := []Unreleased{{Module: "m", Version: "0.1.23", Missing: []string{"m:b"}}}
if err != nil || !reflect.DeepEqual(got, want) {
@@ -530,3 +530,33 @@ func TestANumberARegistryHoldsIsNeverReserved(t *testing.T) {
}
}
}
// testBound is the publish bound the tests set, the setting publish-ack-minutes at its default.
const testBound = 10 * time.Minute
// TestOverdueTakesTheSettingsBound: design 47 H2 H-A-613 (3): the finding version-unreleased is timed by the setting
// publish-ack-minutes, whatever its value, not by a constant of 10 minutes.
func TestOverdueTakesTheSettingsBound(t *testing.T) {
ctx := context.Background()
now := time.Date(2026, 11, 25, 12, 0, 0, 0, time.UTC)
r := &Reserver{Store: &reserveMem{mem: newMem()}, Bound: 30 * time.Minute, Now: func() time.Time { return now },
ReleasedOf: func(context.Context, string) ([]string, error) { return nil, nil }}
v, err := r.Reserve(ctx, "m", "0.1", []string{"m:a"}, Source{})
if err != nil {
t.Fatal(err)
}
if _, _, err := r.Built(ctx, "m", v.Version, map[string]string{"m:a": "sha256:a"}, nil); err != nil {
t.Fatal(err)
}
for _, c := range []struct {
after time.Duration
want int
}{{15 * time.Minute, 0}, {29 * time.Minute, 0}, {30 * time.Minute, 1}} {
cur := time.Date(2026, 11, 25, 12, 0, 0, 0, time.UTC).Add(c.after)
now = cur
got, err := r.Overdue(ctx, func(_, _, _ string) bool { return false })
if err != nil || len(got) != c.want {
t.Errorf("%v after the build with the bound at 30 minutes: %v (%v), want %d findings", c.after, got, err, c.want)
}
}
}