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:
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -280,15 +280,16 @@ func (unreadable) Get(context.Context, string) ([]byte, uint64, bool, error) {
|
||||
// reasks, under a key of the reservation (never a build key), refusing a module with no MAJOR.MINOR or no why.
|
||||
func TestADropOfAReservationIsAReasksValueOfItsOwnKey(t *testing.T) {
|
||||
at := time.Unix(0, 0)
|
||||
key, data, err := NewReservedDrop("m", "1.4", "never released", "op@x", at)
|
||||
key, data, err := NewReservedDrop("m", "1.4", "1.4.3", "never released", "op@x", at)
|
||||
if err != nil || key != "reserved."+versions.ReservedKey("m", "1.4") {
|
||||
t.Fatalf("key %q (%v)", key, err)
|
||||
}
|
||||
if r, err := DecodeReAsk(data); err != nil || r.Mode != ModeReservedDrop || r.Name != "m" || r.FP != "1.4" || r.By != "op@x" {
|
||||
if r, err := DecodeReAsk(data); err != nil || r.Mode != ModeReservedDrop || r.Name != "m" || r.FP != "1.4" || r.Version != "1.4.3" || r.By != "op@x" {
|
||||
t.Errorf("value = %+v (%v)", r, err)
|
||||
}
|
||||
for name, args := range map[string][3]string{"no module": {"", "1.4", "why"}, "no series": {"m", "1", "why"}, "three numbers": {"m", "1.4.2", "why"}, "no why": {"m", "1.4", " "}} {
|
||||
if _, _, err := NewReservedDrop(args[0], args[1], args[2], "op", at); err == nil {
|
||||
for name, args := range map[string][4]string{"no module": {"", "1.4", "1.4.3", "why"}, "no series": {"m", "1", "1.4.3", "why"}, "three numbers": {"m", "1.4.2", "1.4.3", "why"}, "no why": {"m", "1.4", "1.4.3", " "},
|
||||
"no version": {"m", "1.4", "", "why"}, "another series": {"m", "1.4", "1.5.3", "why"}} {
|
||||
if _, _, err := NewReservedDrop(args[0], args[1], args[2], args[3], "op", at); err == nil {
|
||||
t.Errorf("%s: a drop was made", name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,9 +129,10 @@ func NewOldFormDrop(node, why, by string, at time.Time) (string, []byte, error)
|
||||
const ModeReservedDrop = "reserved-drop"
|
||||
|
||||
// NewReservedDrop is the value builder_reserved_drop writes: the key `reserved.<module>.<MAJOR.MINOR>` (never a build key)
|
||||
// and the value.
|
||||
func NewReservedDrop(module, series, why, by string, at time.Time) (string, []byte, error) {
|
||||
module, series = strings.TrimSpace(module), strings.TrimSpace(series)
|
||||
// and the value, which names the version to drop (design 47 H2 H-A-592 (1)): a reservation a newer build took after it was read
|
||||
// is never dropped.
|
||||
func NewReservedDrop(module, series, version, why, by string, at time.Time) (string, []byte, error) {
|
||||
module, series, version = strings.TrimSpace(module), strings.TrimSpace(series), strings.TrimSpace(version)
|
||||
if module == "" {
|
||||
return "", nil, errors.New("module is required")
|
||||
}
|
||||
@@ -141,7 +142,10 @@ func NewReservedDrop(module, series, why, by string, at time.Time) (string, []by
|
||||
if strings.TrimSpace(why) == "" {
|
||||
return "", nil, errors.New("say why the reservation is dropped (why)")
|
||||
}
|
||||
data, err := json.Marshal(ReAsk{V: 1, Why: strings.TrimSpace(why), By: by, At: at.UTC(), Mode: ModeReservedDrop, Name: module, FP: series})
|
||||
if s, _, err := versions.SplitVersion(version); err != nil || s != series {
|
||||
return "", nil, fmt.Errorf("version %q is not a MAJOR.MINOR.PATCH of the series %s (version is required)", version, series)
|
||||
}
|
||||
data, err := json.Marshal(ReAsk{V: 1, Why: strings.TrimSpace(why), By: by, At: at.UTC(), Mode: ModeReservedDrop, Name: module, FP: series, Version: version})
|
||||
return "reserved." + versions.ReservedKey(module, series), data, err
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ type Acts struct {
|
||||
// its answer, or why not.
|
||||
ReserveDone func(ctx context.Context, module, fp, by, why string, at time.Time) (string, error)
|
||||
// DropReserved drops a module's reservation of one MAJOR.MINOR by hand (builder_reserved_drop): its answer, or why not.
|
||||
DropReserved func(ctx context.Context, module, series, by, why string, at time.Time) (string, error)
|
||||
DropReserved func(ctx context.Context, module, series, version, by, why string, at time.Time) (string, error)
|
||||
// PublishDrop terminates one publish item (builder_publish_drop, design 47 H2 §793): the answer, or why not.
|
||||
PublishDrop func(ctx context.Context, module, version, by, why string) (string, error)
|
||||
}
|
||||
|
||||
@@ -1217,7 +1217,10 @@ const (
|
||||
"the version its build reserved at its start, each artifact's digest once built, when the build ended and which artifacts a registry " +
|
||||
"seat said published. With module, that module's only. A key goes when the catalog says version-released for it. Read-only."
|
||||
ReservedDropDescription = "Drop a module's reservation of one MAJOR.MINOR by hand (design 47 G section 369), when its version will never be " +
|
||||
"released; the next build takes the next after the highest released. A hand act: it is recorded in the hand-act log."
|
||||
"released; given module, series and the version it stands at (version, as builder_reserved shows it). Refused when the key holds another version " +
|
||||
"(it names the one that stands) and while the reservation's fingerprint is building. It forgets the key whole (the version, its fingerprint, the " +
|
||||
"artifacts' recorded digests, its withdrawn numbers), its publish item and its version-unreleased, and the answer names what it forgot; what the " +
|
||||
"registries hold at the version stays, a gap the next reserve skips. A hand act: it is recorded in the hand-act log."
|
||||
ReserveDoneDescription = "Reserve a version for a done trunk build that reserved none (design 47 G A-455): given module and fp, the next version " +
|
||||
"of the series is reserved for that fingerprint with the digests of the build's artifacts, and its publish is queued as builder_publish_again " +
|
||||
"queues it; builds nothing. For a done key that cannot be built again. Refused when the key is not done, is no first watched branch's, or " +
|
||||
|
||||
Reference in New Issue
Block a user