B8: the builder's record of a build carries its end and outcome

The artifact store's sweep read each done key's history to learn when its build ended.
A done or failed key now carries ended and outcome, written with its end (kept as it was
when the same end is written again), so a reader of the builds reads no key history.

Builds: design 47 H2 §797
This commit is contained in:
2026-11-22 01:57:04 +01:00
parent c8cc249a90
commit b45f12f70f
4 changed files with 39 additions and 2 deletions
@@ -10,6 +10,7 @@ import (
"reflect"
"slices"
"strings"
"time"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds/forms"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/containerimageregistryclient/reference"
@@ -260,6 +261,11 @@ type BuilderBuild struct {
// time at most, then asks the operator. A person's build (builder_build_again, the operator's answer) starts the count
// again. A reader that does not know the field reads none.
EventBuilds int `json:"event-builds,omitempty"`
// Ended and Outcome are, on a done or failed key, when the build ended and how (done or failed), written with its end, so a
// reader of the builds (the artifact store's sweep) reads no key history (design 47 H2 §797). A reader that does not know the
// fields reads the key as before; a key written before them names neither.
Ended time.Time `json:"ended,omitzero"`
Outcome string `json:"outcome,omitempty"`
}
func (b BuilderBuild) check() error {
@@ -7,6 +7,7 @@ import (
"slices"
"sort"
"strings"
"time"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
@@ -252,6 +253,23 @@ func (c Claimer) Claim(ctx context.Context, module, fingerprint, manifest string
return nil, nil
}
// endOf gives a done or failed build its end and outcome (design 47 H2 §797): the end the key holds already for that outcome, else
// now. A build that has not ended names neither.
func endOf(was, b builds.BuilderBuild, now func() time.Time) builds.BuilderBuild {
if b.State != builds.BuildDone && b.State != builds.BuildFailed {
b.Ended, b.Outcome = time.Time{}, ""
return b
}
b.Outcome = b.State
if b.Ended.IsZero() {
b.Ended = now().UTC()
if was.Outcome == b.State && !was.Ended.IsZero() {
b.Ended = was.Ended
}
}
return b
}
func (c Claimer) write(_ context.Context, key string, b builds.BuilderBuild, put func([]byte) (uint64, error)) (*Claim, error) {
data, err := builds.EncodeBuilderBuild(b)
if err != nil {
@@ -272,6 +290,7 @@ func (c Claimer) write(_ context.Context, key string, b builds.BuilderBuild, put
// the key holds. A key that changed meanwhile is ErrConflict: the claim is no longer this builder's.
func (c Claimer) Finish(ctx context.Context, cl *Claim, b builds.BuilderBuild) error {
b.V = keys.Version
b = endOf(cl.Build, b, time.Now)
if builds.SameBuilderBuild(cl.Build, b) {
return nil
}
@@ -6,6 +6,7 @@ import (
"slices"
"sync"
"testing"
"time"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
)
@@ -209,9 +210,14 @@ func TestFinishMovesTheKeyByCompareAndSetAndWritesOnlyADifferentValue(t *testing
if err := c.Finish(context.Background(), got, done); err != nil {
t.Fatal(err)
}
if v := valueOf(t, st, got.Key); v.State != builds.BuildDone || v.Artifacts[0].Digest != digest {
v := valueOf(t, st, got.Key)
if v.State != builds.BuildDone || v.Artifacts[0].Digest != digest {
t.Errorf("the key holds %+v", v)
}
// Design 47 H2 §797: the done key carries its end and outcome, so a reader of the builds reads no key history.
if v.Outcome != builds.BuildDone || v.Ended.IsZero() || time.Since(v.Ended) > time.Minute {
t.Errorf("the done key ended %v with outcome %q, want now and done", v.Ended, v.Outcome)
}
writes := st.writes
if err := c.Finish(context.Background(), got, done); err != nil && !errors.Is(err, ErrConflict) {
t.Fatal(err)
@@ -219,6 +225,12 @@ func TestFinishMovesTheKeyByCompareAndSetAndWritesOnlyADifferentValue(t *testing
if st.writes != writes {
t.Errorf("the same value was written again (%d writes, was %d)", st.writes, writes)
}
if again := endOf(v, done, time.Now); again.Ended != v.Ended || again.Outcome != builds.BuildDone {
t.Errorf("the same end given again ended %v, want the end the key holds, %v", again.Ended, v.Ended)
}
if building := endOf(v, builds.BuilderBuild{State: builds.BuildBuilding}, time.Now); !building.Ended.IsZero() || building.Outcome != "" {
t.Errorf("a building key carries an end: %+v", building)
}
// Finish after the key changed is a conflict, not an overwrite (merged into this test for the test budget).
st = newMem()
@@ -420,7 +420,7 @@ func (b *Builder) Sweep(ctx context.Context, pictured ...string) error {
}
closed := builds.BuilderBuild{State: builds.BuildFailed, By: b.Claimer.By, Manifest: cur.Manifest, Step: cur.Step,
Error: fmt.Sprintf("closed at start: left building by %s, and the module no longer has this fingerprint, so nothing will build it", cur.By)}
data, err := builds.EncodeBuilderBuild(closed)
data, err := builds.EncodeBuilderBuild(endOf(cur, closed, time.Now))
if err != nil {
return err
}