diff --git a/modules/mesh-delivery-builder/internal/build/run.go b/modules/mesh-delivery-builder/internal/build/run.go index d62ca36c..155aafa6 100644 --- a/modules/mesh-delivery-builder/internal/build/run.go +++ b/modules/mesh-delivery-builder/internal/build/run.go @@ -724,8 +724,9 @@ func (b *Builder) try(ctx context.Context, module string, m meshcatalog.ModulesB var reserved versions.ReservedVersion hasReserved := false if rebuild && cl.Build.State == builds.BuildBuilding { - // Reserved afresh, above the highest the catalog's versions answers, taking over the older unreleased reservation of this - // fingerprint (A-455), never its standing number kept (A-490b); the build's own publish then runs. + // Reserved as A-490b amended by H-A-225 has it: this fingerprint's standing reservation is kept while it is unreleased + // and above the highest the catalog's versions answers, else the next above that highest is taken (A-455); the build's + // own publish then runs. if b.Reserved.Filled() { reserved, hasReserved = b.reserve(ctx, module, m, plan, b.originOf(key), true) } diff --git a/modules/mesh-delivery-builder/internal/versions/reserve.go b/modules/mesh-delivery-builder/internal/versions/reserve.go index da6a8a51..caaa9923 100644 --- a/modules/mesh-delivery-builder/internal/versions/reserve.go +++ b/modules/mesh-delivery-builder/internal/versions/reserve.go @@ -202,12 +202,22 @@ func (r *Reserver) Reserve(ctx context.Context, module, series string, artifacts for _, a := range artifacts { out.Artifacts[a] = "" } - if found && cur.Fingerprint != src.Fingerprint { + if found { out.Withdrawn = maps.Clone(cur.Withdrawn) - if out.Withdrawn == nil { - out.Withdrawn = map[string]string{} + if cur.Fingerprint != src.Fingerprint { + if out.Withdrawn == nil { + out.Withdrawn = map[string]string{} + } + out.Withdrawn[cur.Version] = cur.Fingerprint // a dropped number stays a gap (H-A-226) + } + // One at or below the catalog's highest released is refused by the plain rule anyway: the map never grows without end. + maps.DeleteFunc(out.Withdrawn, func(v, _ string) bool { + _, p, err := SplitVersion(v) + return err != nil || p <= high + }) + if len(out.Withdrawn) == 0 { + out.Withdrawn = nil } - out.Withdrawn[cur.Version] = cur.Fingerprint } raw, _ := json.Marshal(out) if found { diff --git a/modules/mesh-delivery-builder/internal/versions/reserve_test.go b/modules/mesh-delivery-builder/internal/versions/reserve_test.go index 099e0859..e5850184 100644 --- a/modules/mesh-delivery-builder/internal/versions/reserve_test.go +++ b/modules/mesh-delivery-builder/internal/versions/reserve_test.go @@ -221,6 +221,31 @@ func TestAReleaseIsRecordedByFingerprintBeforeItsReservationGoes(t *testing.T) { } } +// TestTheWithdrawnVersionsAreDroppedOnceReleasedPast: design 47 H H-A-225, H-A-226 — a dropped number stays a gap, kept in +// the series key's Withdrawn while it is above the catalog's highest released; at each write those at or below it go, so the +// map never grows without end. +func TestTheWithdrawnVersionsAreDroppedOnceReleasedPast(t *testing.T) { + ctx := context.Background() + store := &reserveMem{mem: newMem()} + highest := "0.1.3" + r := &Reserver{Store: store, Filled: func() bool { return true }, + ReleasedOf: func(context.Context, string) ([]string, error) { return []string{highest}, nil }} + for _, fp := range []string{"src2:a", "src2:b", "src2:c"} { + if _, err := r.Reserve(ctx, "m", "0.1", []string{"m:a"}, Source{Fingerprint: fp}); err != nil { + t.Fatal(err) + } + } + cur, _, _, _ := r.get(ctx, ReservedKey("m", "0.1")) + if cur.Version != "0.1.6" || len(cur.Withdrawn) != 2 || cur.Withdrawn["0.1.4"] != "src2:a" || cur.Withdrawn["0.1.5"] != "src2:b" { + t.Fatalf("reservation %+v; want 0.1.6 with 0.1.4 and 0.1.5 withdrawn", cur) + } + highest = "0.1.5" // the catalog released past both withdrawn numbers but the newest + got, err := r.Reserve(ctx, "m", "0.1", []string{"m:a"}, Source{Fingerprint: "src2:d"}) + if err != nil || got.Version != "0.1.7" || len(got.Withdrawn) != 1 || got.Withdrawn["0.1.6"] != "src2:c" { + t.Errorf("reserved %+v (%v); want 0.1.7 keeping only 0.1.6 withdrawn", got, err) + } +} + // TestARebuildReservesAboveTheCatalogsHighestWhateverItsStandingNumberWas: design 47 G A-490b as H-A-225 amends it — a build again // of a done key, or a re-run after a restart, keeps its fingerprint's standing reservation while it is unreleased and above the // catalog's highest; one at or below it is replaced (Took told) by the next above the catalog's highest alone; another