B6 drop-names-its-version: builder_reserved_drop takes the version, refuses another or a building one, and names what it forgot

Builds: design 47 H2 H-A-592 (1) (2) (3)
This commit is contained in:
2026-11-25 17:15:05 +01:00
parent b7dc1dc3e1
commit 6af989cece
10 changed files with 89 additions and 29 deletions
@@ -25,16 +25,17 @@ func reservedTools(rr versions.Reader, ask queueAsker, now func() time.Time, act
"module": map[string]any{"type": "string", "description": "only this module's reservations"}}},
Run: func(args map[string]any) (any, error) { return versions.AnswerReserved(rr, str(args, "module")) }},
{Name: versions.ReservedDropTool, Description: versions.ReservedDropDescription,
Input: map[string]any{"type": "object", "required": []string{"module", "series", "why"}, "properties": map[string]any{
"module": map[string]any{"type": "string", "description": "the module"},
"series": map[string]any{"type": "string", "description": "its MAJOR.MINOR"},
"why": map[string]any{"type": "string", "description": "why, in plain words"}}},
Input: map[string]any{"type": "object", "required": []string{"module", "series", "version", "why"}, "properties": map[string]any{
"module": map[string]any{"type": "string", "description": "the module"},
"series": map[string]any{"type": "string", "description": "its MAJOR.MINOR"},
"version": map[string]any{"type": "string", "description": "the MAJOR.MINOR.PATCH the reservation stands at, as builder_reserved shows it: a newer one is never dropped"},
"why": map[string]any{"type": "string", "description": "why, in plain words"}}},
Run: func(args map[string]any) (any, error) {
key, value, err := build.NewReservedDrop(str(args, "module"), str(args, "series"), str(args, "why"), stdio.CallerOf(args), now())
key, value, err := build.NewReservedDrop(str(args, "module"), str(args, "series"), str(args, "version"), str(args, "why"), stdio.CallerOf(args), now())
if err != nil {
return nil, err
}
if _, err := acts.Record(meshhandactsclient.Request{What: fmt.Sprintf("dropped the reservation of %s %s by hand", str(args, "module"), str(args, "series")),
if _, err := acts.Record(meshhandactsclient.Request{What: fmt.Sprintf("dropped the reservation of %s %s by hand", str(args, "module"), str(args, "version")),
Why: str(args, "why"), Cause: versions.ReservedDropTool, Verb: "reserved-drop"}); err != nil {
return nil, fmt.Errorf("the hand act was not recorded through mesh-hand-acts, so nothing was dropped: %w", err)
}
@@ -247,6 +247,10 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
b.Reserved = reserved
// A take-over of a series' reservation by another fingerprint withdraws the older build (H-A-225).
reserved.withdraw = b.Withdraw
reserved.looking = func(module, fp string) bool {
key, err := builds.BuilderBuildKey(module, fp)
return err == nil && b.Looking(key)
}
reserved.recordAgain = b.RecordAgain // a done build's digests its end did not record are recorded at the start (H-A-492)
// The versions' hand acts (builder_publish_again, builder_reserved_drop) come through reasks, as builder_build_again.
acts := versions.Acts{DropReserved: reserved.dropped}
@@ -352,8 +352,18 @@ func TestThePublishItemsAreWiredToTheReservationsAndTheReAskWatch(t *testing.T)
}
// A drop deletes the item too.
third := done("src2:three")
if _, err := rv.dropped(ctx, "m", "0.1", "op", "never", time.Unix(0, 0)); err != nil {
t.Fatal(err)
// H2 H-A-592 (1): another version than the one standing is refused naming the standing one; so is a drop while its fingerprint builds
if _, err := rv.dropped(ctx, "m", "0.1", "0.1.99", "op", "never", time.Unix(0, 0)); err == nil || !strings.Contains(err.Error(), third.Version) {
t.Errorf("a drop naming another version answered %v, want a refusal naming %s", err, third.Version)
}
rv.looking = func(module, fp string) bool { return module == "m" && fp == "src2:three" }
if _, err := rv.dropped(ctx, "m", "0.1", third.Version, "op", "never", time.Unix(0, 0)); err == nil || !strings.Contains(err.Error(), "building") {
t.Errorf("a drop while the fingerprint builds answered %v, want a refusal", err)
}
rv.looking = nil
answer, err := rv.dropped(ctx, "m", "0.1", third.Version, "op", "never", time.Unix(0, 0))
if err != nil || !strings.Contains(answer, third.Version) || !strings.Contains(answer, "src2:three") {
t.Fatalf("the drop answered %q (%v), want it to name the version and the fingerprint it forgot", answer, err)
}
if kv.has(versions.PublishItemKey("m", third.Version)) {
t.Errorf("a dropped reservation kept its item")
@@ -225,7 +225,7 @@ func versionActed(ctx context.Context, acts versions.Acts, kv jetstream.KeyValue
if acts.DropReserved == nil {
err = errors.New("this builder keeps no reservations")
} else {
r.Answer, err = acts.DropReserved(ctx, r.Name, r.FP, r.By, r.Why, r.At)
r.Answer, err = acts.DropReserved(ctx, r.Name, r.FP, r.Version, r.By, r.Why, r.At)
}
} else if acts.DropOldForm == nil {
err = errors.New("this builder keeps no old-form window")
@@ -7,6 +7,7 @@ import (
"fmt"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
"slices"
"sort"
"strings"
"time"
@@ -58,6 +59,8 @@ type reservations struct {
recordAgain func(ctx context.Context, module, fp, when string) (string, error)
// rebuild builds a done key of module at fp again (the build-again path, A-490; H-A-279); nil builds none.
rebuild func(ctx context.Context, module, fp, why string) error
// looking says a look of the builder holds the build key of module at fp now (builder_reserved_drop refuses it); nil says none.
looking func(module, fp string) bool
// judge reads the registries' record of a reservation's artifacts at its version (the republisher's Held); nil reads none.
judge func(ctx context.Context, v versions.ReservedVersion) (versions.Judged, error)
// say says package-published on the seat mesh-builds; nil says none.
@@ -503,22 +506,55 @@ func (rv *reservations) sayPublished(ctx context.Context, m versions.Marked, dig
}
}
// dropped is builder_reserved_drop: the reservation is deleted and its bound ended.
func (rv *reservations) dropped(ctx context.Context, module, series, by, why string, at time.Time) (string, error) {
cur, held, _ := rv.r.At(ctx, versions.ReservedKey(module, series))
// dropped is builder_reserved_drop (design 47 H2 H-A-592): it names its version, and the reservation of the series is deleted whole
// only when it stands at that version and its fingerprint is not building; the publish item and the version-unreleased go with it,
// the bound ends, and the answer names what was forgotten.
func (rv *reservations) dropped(ctx context.Context, module, series, version, by, why string, at time.Time) (string, error) {
cur, held, err := rv.r.At(ctx, versions.ReservedKey(module, series))
if err != nil {
return "", err
}
if !held {
return "", fmt.Errorf("%s holds no reservation of %s", module, series)
}
if cur.Version != version {
return "", fmt.Errorf("%s's reservation of %s stands at %s, not %s: a reservation a newer build took is never dropped", module, series, cur.Version, version)
}
if rv.looking != nil && rv.looking(module, cur.Fingerprint) {
return "", fmt.Errorf("the build of %s at %s, which holds %s, is building: drop it when that build ends or its ask is dropped (builder_stuck reads it)", module, cur.Fingerprint, version)
}
atRegistries := "the registries' record was not read"
if rv.judge != nil {
if j, jerr := rv.judge(ctx, cur); jerr == nil {
var names []string
for _, h := range append(append([]versions.HeldArtifact{}, j.Held...), j.Elsewhere...) {
names = append(names, h.Seat+" "+h.Name)
}
atRegistries = "the registries keep " + strings.Join(names, ", ") + " at it, a gap the next reserve skips"
if len(names) == 0 {
atRegistries = "no registry holds an artifact at it"
}
}
}
ok, err := rv.r.Drop(ctx, module, series)
if err != nil {
return "", err
}
if ok && held && rv.itemEnded != nil {
rv.itemEnded(ctx, module, cur.Version) // its publish item goes with its reservation (A-456b), its items terminated (§793)
}
if !ok {
return "", fmt.Errorf("%s holds no reservation of %s", module, series)
}
if rv.itemEnded != nil {
rv.itemEnded(ctx, module, cur.Version) // its publish item goes with its reservation (A-456b), its items terminated (§793)
}
rv.dropBound(ctx, versions.ReservedKey(module, series))
rv.found.clear(ctx, versions.VersionUnreleased, meshconditionsclient.ScopeModule, module)
return fmt.Sprintf("the reservation of %s %s is dropped (%s, %s)", module, series, by, why), nil
withdrawn := make([]string, 0, len(cur.Withdrawn))
for v := range cur.Withdrawn {
withdrawn = append(withdrawn, v)
}
sort.Strings(withdrawn)
return fmt.Sprintf("the reservation of %s %s is dropped (%s, %s): forgot version %s of fingerprint %s, %d recorded digests, withdrawn numbers %v and its publish item and version-unreleased; %s",
module, series, by, why, cur.Version, cur.Fingerprint, len(cur.Artifacts), withdrawn, atRegistries), nil
}
// noMark says why a published marked nothing, from the reservations the published read (design 47 H H-A-280: no second read):
@@ -143,13 +143,14 @@ func TestTheCatalogsWordsMoveTheReservations(t *testing.T) {
if all, _ := rv.r.All(ctx); len(all) != 0 || bounds.keys[boundKey] || len(st.vals) != 0 {
t.Errorf("after version-released: reservations %v, bounds %v, findings %v; want none", all, bounds.keys, st.vals)
}
if _, err := rv.Reserve(ctx, "m", "1.4", []string{"m:a"}, versions.Source{}); err != nil {
again, err := rv.Reserve(ctx, "m", "1.4", []string{"m:a"}, versions.Source{})
if err != nil {
t.Fatal(err)
}
if answer, err := rv.dropped(ctx, "m", "1.4", "op", "never released", time.Unix(0, 0)); err != nil || !strings.Contains(answer, "dropped") {
if answer, err := rv.dropped(ctx, "m", "1.4", again.Version, "op", "never released", time.Unix(0, 0)); err != nil || !strings.Contains(answer, "dropped") {
t.Errorf("builder_reserved_drop: %q (%v)", answer, err)
}
if _, err := rv.dropped(ctx, "m", "1.4", "op", "again", time.Unix(0, 0)); err == nil {
if _, err := rv.dropped(ctx, "m", "1.4", again.Version, "op", "again", time.Unix(0, 0)); err == nil {
t.Error("a reservation that is gone was dropped again")
}
}