B4 held-elsewhere: a build again withdraws a standing number a registry holds for another build and takes the next free one
(2), the publish item's end at a refusal for other bytes, waits on the lead's answer. Builds: design 47 H2 H-A-590 (1) (3), H-A-616, H-A-279
This commit is contained in:
@@ -260,9 +260,10 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
Holders: holders, // a registry seat's holder from the seat-holders view, from the start (design 47 G A-416, A-416a)
|
||||
Started: time.Now()} // a build ended from now on is of the live class (H-A-290 (1))
|
||||
// A number a registry seat already holds is never reserved (H-A-275): read before reserving, through the seats' verb versions.
|
||||
reserved.r.HeldNumbers = func(ctx context.Context, module, fp string, refs []string) ([]string, error) {
|
||||
return republish.HeldNumbers(ctx, module, fp, refs, registryVersionsVia(calls.Call))
|
||||
reserved.r.HeldRecords = func(ctx context.Context, module, fp string, refs []string) ([]versions.HeldArtifact, error) {
|
||||
return republish.HeldRecords(ctx, module, fp, refs, registryVersionsVia(calls.Call))
|
||||
}
|
||||
reserved.r.MovedFrom = reserved.movedFrom
|
||||
// A done build whose number a registry holds elsewhere is built again at the next free number (H-A-279), on the builder's context.
|
||||
reserved.rebuild = func(_ context.Context, module, fp, why string) error {
|
||||
res := b.BuildAgain(ctx, module, fp, why, "the builder", buildAgainBound)
|
||||
|
||||
@@ -608,11 +608,27 @@ func (rv *reservations) movedElsewhere(ctx context.Context, v versions.ReservedV
|
||||
}
|
||||
return err
|
||||
}
|
||||
var at []string
|
||||
for _, h := range j.Elsewhere {
|
||||
at = append(at, fmt.Sprintf("%s holds %s %s at %s, built %s", h.Seat, h.Name, h.Version, h.Digest, v.Artifacts[h.Ref]))
|
||||
}
|
||||
why := fmt.Sprintf("%s is withdrawn and the build of %s is built again at the next free number: %s", v.Version, v.Fingerprint, strings.Join(at, "; "))
|
||||
why := elsewhereWords(v, j.Elsewhere)
|
||||
rv.heldElsewhere(ctx, v.Module, why)
|
||||
return rv.rebuild(ctx, v.Module, v.Fingerprint, why)
|
||||
}
|
||||
|
||||
// elsewhereWords says what withdrew v's number: each artifact a registry holds there for another build, with the seat, both digests and
|
||||
// the fingerprint the registry keeps for it when one is kept (design 47 H2 H-A-590 (1), H-A-279).
|
||||
func elsewhereWords(v versions.ReservedVersion, elsewhere []versions.HeldArtifact) string {
|
||||
var at []string
|
||||
for _, h := range elsewhere {
|
||||
w := fmt.Sprintf("%s holds %s %s at %s, built %s", h.Seat, h.Name, h.Version, h.Digest, v.Artifacts[h.Ref])
|
||||
if h.Fingerprint != "" {
|
||||
w += ", for fingerprint " + h.Fingerprint
|
||||
}
|
||||
at = append(at, w)
|
||||
}
|
||||
return fmt.Sprintf("%s is withdrawn and the build of %s is built again at the next free number: %s", v.Version, v.Fingerprint, strings.Join(at, "; "))
|
||||
}
|
||||
|
||||
// movedFrom is told by the reserver a standing number it withdrew at a build again (design 47 H2 H-A-590 (1)): the finding is raised;
|
||||
// the reserve itself takes the next number no registry holds.
|
||||
func (rv *reservations) movedFrom(ctx context.Context, v versions.ReservedVersion, elsewhere []versions.HeldArtifact) {
|
||||
rv.heldElsewhere(ctx, v.Module, elsewhereWords(v, elsewhere))
|
||||
}
|
||||
|
||||
@@ -742,7 +742,13 @@ func TestARegistrysRecordEndsOrMovesAPublish(t *testing.T) {
|
||||
rv.released = func(_ context.Context, m, v string) { ended = append(ended, m+" "+v) }
|
||||
rv.itemEnded = rv.released // a build withdrawn or superseded ends its publish item too (§793)
|
||||
registry := []string{"0.1.37"}
|
||||
rv.r.HeldNumbers = func(context.Context, string, string, []string) ([]string, error) { return registry, nil }
|
||||
rv.r.HeldRecords = func(context.Context, string, string, []string) ([]versions.HeldArtifact, error) {
|
||||
var out []versions.HeldArtifact
|
||||
for _, v := range registry {
|
||||
out = append(out, versions.HeldArtifact{Version: v})
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
res, err := rv.Reserve(ctx, "node-tools", "0.1", []string{"node-tools:program"}, versions.Source{Fingerprint: "fp1"})
|
||||
if err != nil || res.Version != "0.1.0" {
|
||||
t.Fatalf("reserved %q (%v)", res.Version, err)
|
||||
|
||||
@@ -854,6 +854,8 @@ type HeldVersion struct {
|
||||
// the seat and the name it is published as, the version and the digest the seat holds.
|
||||
type HeldArtifact struct {
|
||||
Ref, Seat, Name, Version, Digest string
|
||||
// Fingerprint is the fingerprint the registry keeps for the version, empty where none is kept (design 47 H2 H-A-589 (3)).
|
||||
Fingerprint string
|
||||
}
|
||||
|
||||
// Judged is what the registries' record says of a reserved version's artifacts (design 47 H H-A-272, H-A-274, H-A-275; H2 H-A-588
|
||||
@@ -934,15 +936,16 @@ func (r *Republisher) Held(ctx context.Context, v ReservedVersion, versionsOf fu
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// HeldNumbers are the versions (MAJOR.MINOR.PATCH) a registry seat's record holds of any of module's artifacts refs, as the catalog
|
||||
// entry of fingerprint names their seats and names (design 47 H H-A-275): a number one holds is never reserved. An artifact the
|
||||
// entry names no registry seat for is read nowhere.
|
||||
func (r *Republisher) HeldNumbers(ctx context.Context, module, fingerprint string, refs []string, versionsOf func(ctx context.Context, seat, name string) ([]HeldVersion, error)) ([]string, error) {
|
||||
// HeldRecords are the versions (MAJOR.MINOR.PATCH) a registry seat's record holds of any of module's artifacts refs, as the catalog
|
||||
// entry of fingerprint names their seats and names (design 47 H H-A-275), one record per artifact and version with the digest and the
|
||||
// fingerprint the registry keeps (H2 H-A-590 (1)): a number one holds is never reserved. An artifact the entry names no registry seat
|
||||
// for is read nowhere.
|
||||
func (r *Republisher) HeldRecords(ctx context.Context, module, fingerprint string, refs []string, versionsOf func(ctx context.Context, seat, name string) ([]HeldVersion, error)) ([]HeldArtifact, error) {
|
||||
e, err := r.Entry(ctx, fingerprint)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the catalog entry %s of %s cannot be read: %w", fingerprint, module, err)
|
||||
}
|
||||
var out []string
|
||||
var out []HeldArtifact
|
||||
for _, ref := range refs {
|
||||
seat, name, _, ok := publishTarget(e, module, ref)
|
||||
if !ok {
|
||||
@@ -953,8 +956,8 @@ func (r *Republisher) HeldNumbers(ctx context.Context, module, fingerprint strin
|
||||
return out, fmt.Errorf("%s's versions of %s cannot be read: %w", seat, name, err)
|
||||
}
|
||||
for _, h := range held {
|
||||
if v := strings.TrimPrefix(h.Version, "v"); v != "" && !slices.Contains(out, v) {
|
||||
out = append(out, v)
|
||||
if v := strings.TrimPrefix(h.Version, "v"); v != "" {
|
||||
out = append(out, HeldArtifact{Ref: ref, Seat: seat, Name: name, Version: v, Digest: h.Digest, Fingerprint: h.Fingerprint})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ func TestTheRegistriesRecordSaysWhetherAVersionIsHeld(t *testing.T) {
|
||||
if c.lacks && !strings.Contains(j.Lacks, "0.1.37") {
|
||||
t.Errorf("what the registry lacks is said as %q", j.Lacks)
|
||||
}
|
||||
nums, err := r.HeldNumbers(ctx, "m", "fp", []string{"m:lib"}, versionsOf)
|
||||
nums, err := r.HeldRecords(ctx, "m", "fp", []string{"m:lib"}, versionsOf)
|
||||
if err != nil || len(nums) != len(c.holds) {
|
||||
t.Errorf("the held numbers are %v (%v), want one per version the seat holds", nums, err)
|
||||
}
|
||||
|
||||
@@ -161,28 +161,46 @@ type Reserver struct {
|
||||
// Logf says an index write that failed (H-A-269 (1)): the reservation stands, and Reindex writes its index at the next
|
||||
// start. Nil says nothing.
|
||||
Logf func(string, ...any)
|
||||
// HeldNumbers are the versions a registry seat's record holds of any of module's artifacts (design 47 H H-A-275), read before a
|
||||
// number is reserved: a number one holds is skipped. Nil reads none; a read that fails is said and the reserve proceeds.
|
||||
HeldNumbers func(ctx context.Context, module, fingerprint string, refs []string) ([]string, error)
|
||||
// HeldRecords are the versions a registry seat's record holds of any of module's artifacts (design 47 H H-A-275), each with the
|
||||
// digest and the fingerprint the registry keeps, read before a number is reserved: a number one holds is skipped, and a
|
||||
// standing reservation whose number one holds for another build is withdrawn (design 47 H2 H-A-590 (1)). Nil reads none; a
|
||||
// read that fails is said and the reserve proceeds.
|
||||
HeldRecords func(ctx context.Context, module, fingerprint string, refs []string) ([]HeldArtifact, error)
|
||||
// HeldElsewhere is told the numbers of module a reserve skipped because a registry holds them (H-A-275); nil is told none.
|
||||
HeldElsewhere func(ctx context.Context, module string, skipped []string)
|
||||
// MovedFrom is told a standing reservation a reserve withdrew because a registry holds an artifact at its number for another
|
||||
// build, with those artifacts (H-A-590 (1), H-A-279); nil is told none.
|
||||
MovedFrom func(ctx context.Context, v ReservedVersion, elsewhere []HeldArtifact)
|
||||
}
|
||||
|
||||
// heldNumbers are the patches of series a registry holds of module's artifacts (H-A-275); a read that fails is said, and none.
|
||||
func (r *Reserver) heldNumbers(ctx context.Context, module, series, fingerprint string, refs []string) map[int]bool {
|
||||
if r.HeldNumbers == nil {
|
||||
return nil
|
||||
// heldNumbers are the patches of series a registry holds of module's artifacts (H-A-275), and the records they come from; a read
|
||||
// that fails is said, and none.
|
||||
func (r *Reserver) heldNumbers(ctx context.Context, module, series, fingerprint string, refs []string) (map[int]bool, []HeldArtifact) {
|
||||
if r.HeldRecords == nil {
|
||||
return nil, nil
|
||||
}
|
||||
vs, err := r.HeldNumbers(ctx, module, fingerprint, refs)
|
||||
recs, err := r.HeldRecords(ctx, module, fingerprint, refs)
|
||||
if err != nil {
|
||||
r.said(fmt.Errorf("%s: the registries' versions are not read before reserving, so a number they hold is not skipped: %w", module, err))
|
||||
}
|
||||
out := map[int]bool{}
|
||||
for _, v := range vs {
|
||||
if s, p, err := SplitVersion(v); err == nil && s == series {
|
||||
for _, h := range recs {
|
||||
if s, p, err := SplitVersion(strings.TrimPrefix(h.Version, "v")); err == nil && s == series {
|
||||
out[p] = true
|
||||
}
|
||||
}
|
||||
return out, recs
|
||||
}
|
||||
|
||||
// heldElsewhereAt are the records of recs at v's number held for another build (design 47 H2 H-A-590 (1), H-A-616): the registry
|
||||
// keeps another fingerprint, or none and the reservation records another digest or none for the artifact.
|
||||
func heldElsewhereAt(v ReservedVersion, recs []HeldArtifact) []HeldArtifact {
|
||||
var out []HeldArtifact
|
||||
for _, h := range recs {
|
||||
if strings.TrimPrefix(h.Version, "v") == v.Version && !heldFor(v, h.Ref, HeldVersion{Version: h.Version, Digest: h.Digest, Fingerprint: h.Fingerprint}) {
|
||||
out = append(out, h)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -243,13 +261,22 @@ func (r *Reserver) Reserve(ctx context.Context, module, series string, artifacts
|
||||
}
|
||||
}
|
||||
key := ReservedKey(module, series)
|
||||
held := r.heldNumbers(ctx, module, series, src.Fingerprint, artifacts)
|
||||
held, records := r.heldNumbers(ctx, module, series, src.Fingerprint, artifacts)
|
||||
for {
|
||||
cur, rev, found, err := r.get(ctx, key)
|
||||
if err != nil {
|
||||
return ReservedVersion{}, err
|
||||
}
|
||||
withdrawn := found && hasKey(cur.Withdrawn, cur.Version) // a number a registry holds elsewhere (H-A-279)
|
||||
// A standing reservation of this fingerprint whose number a registry holds for another build, or for none the reservation
|
||||
// records, is withdrawn now, as the done build's path withdraws it (design 47 H2 H-A-590 (1)); the next number no registry holds
|
||||
// is taken. A read that did not answer left no record: the standing number is kept.
|
||||
var elsewhere []HeldArtifact
|
||||
if found && !withdrawn && cur.Fingerprint == src.Fingerprint && cur.Fingerprint != "" {
|
||||
if elsewhere = heldElsewhereAt(cur, records); len(elsewhere) > 0 {
|
||||
withdrawn = true
|
||||
}
|
||||
}
|
||||
if found && !withdrawn && cur.Fingerprint == src.Fingerprint && cur.Fingerprint != "" && !slices.Contains(released, cur.Version) {
|
||||
if _, p, err := SplitVersion(cur.Version); err == nil && p > high {
|
||||
return cur, nil // kept until released (H-A-225); one at or below the catalog's highest can never be released
|
||||
@@ -270,7 +297,7 @@ func (r *Reserver) Reserve(ctx context.Context, module, series string, artifacts
|
||||
out.Upstream = slices.Clone(src.Upstream)
|
||||
if found {
|
||||
out.Withdrawn = maps.Clone(cur.Withdrawn)
|
||||
if cur.Fingerprint != src.Fingerprint {
|
||||
if cur.Fingerprint != src.Fingerprint || len(elsewhere) > 0 {
|
||||
if out.Withdrawn == nil {
|
||||
out.Withdrawn = map[string]string{}
|
||||
}
|
||||
@@ -301,6 +328,9 @@ func (r *Reserver) Reserve(ctx context.Context, module, series string, artifacts
|
||||
if len(skipped) > 0 && r.HeldElsewhere != nil {
|
||||
r.HeldElsewhere(ctx, module, skipped)
|
||||
}
|
||||
if len(elsewhere) > 0 && r.MovedFrom != nil {
|
||||
r.MovedFrom(ctx, cur, elsewhere)
|
||||
}
|
||||
if found && r.Took != nil {
|
||||
r.Took(ctx, cur, out)
|
||||
}
|
||||
|
||||
@@ -464,11 +464,15 @@ func TestANumberARegistryHoldsIsNeverReserved(t *testing.T) {
|
||||
var readErr error
|
||||
var skipped []string
|
||||
r := &Reserver{Store: store, ReleasedOf: func(context.Context, string) ([]string, error) { return []string{"0.1.36"}, nil },
|
||||
HeldNumbers: func(_ context.Context, module, fp string, refs []string) ([]string, error) {
|
||||
HeldRecords: func(_ context.Context, module, fp string, refs []string) ([]HeldArtifact, error) {
|
||||
if module != "node-tools" || fp != "fp1" || len(refs) != 1 {
|
||||
t.Errorf("the registries are read for %s %s %v", module, fp, refs)
|
||||
}
|
||||
return held, readErr
|
||||
var out []HeldArtifact
|
||||
for _, v := range held {
|
||||
out = append(out, HeldArtifact{Ref: "node-tools:program", Version: v})
|
||||
}
|
||||
return out, readErr
|
||||
},
|
||||
HeldElsewhere: func(_ context.Context, _ string, s []string) { skipped = append(skipped, s...) }}
|
||||
v, err := r.Reserve(ctx, "node-tools", "0.1", []string{"node-tools:program"}, Source{Fingerprint: "fp1", Repository: "o/r", Commit: "c1"})
|
||||
@@ -500,4 +504,35 @@ func TestANumberARegistryHoldsIsNeverReserved(t *testing.T) {
|
||||
if v, err := r.Reserve(ctx, "node-tools", "0.2", []string{"node-tools:program"}, Source{Fingerprint: "fp1"}); err != nil || v.Version != "0.2.1" {
|
||||
t.Errorf("with the registry down reserved %q (%v), want 0.2.1 (what it answered still skipped)", v.Version, err)
|
||||
}
|
||||
// H2 H-A-590 (1), H-A-616: a build again of F keeps F's standing number unless a registry holds an artifact at it for another
|
||||
// build: the registry keeps another fingerprint, or none and another digest; one with the reserved digest, or F's own
|
||||
// fingerprint, keeps it.
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
held HeldArtifact
|
||||
wantMoved bool
|
||||
}{
|
||||
{name: "another fingerprint kept", held: HeldArtifact{Digest: "sha256:mine", Fingerprint: "other"}, wantMoved: true},
|
||||
{name: "no fingerprint, another digest", held: HeldArtifact{Digest: "sha256:theirs"}, wantMoved: true},
|
||||
{name: "no fingerprint, the reserved digest", held: HeldArtifact{Digest: "sha256:mine"}},
|
||||
{name: "F's own fingerprint", held: HeldArtifact{Digest: "sha256:mine", Fingerprint: "fp9"}},
|
||||
} {
|
||||
st := &reserveMem{mem: newMem()}
|
||||
var told []HeldArtifact
|
||||
rr := &Reserver{Store: st, ReleasedOf: func(context.Context, string) ([]string, error) { return nil, nil }}
|
||||
first, err := rr.Reserve(ctx, "m", "0.3", []string{"m:a"}, Source{Fingerprint: "fp9"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, _, err := rr.Built(ctx, "m", first.Version, map[string]string{"m:a": "sha256:mine"}, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
c.held.Ref, c.held.Version, c.held.Seat = "m:a", first.Version, SeatArtifacts
|
||||
rr.HeldRecords = func(context.Context, string, string, []string) ([]HeldArtifact, error) { return []HeldArtifact{c.held}, nil }
|
||||
rr.MovedFrom = func(_ context.Context, _ ReservedVersion, e []HeldArtifact) { told = e }
|
||||
again, err := rr.Reserve(ctx, "m", "0.3", []string{"m:a"}, Source{Fingerprint: "fp9", Rebuild: true})
|
||||
if err != nil || (again.Version != first.Version) != c.wantMoved || (again.Withdrawn[first.Version] == "fp9") != c.wantMoved || (len(told) == 1) != c.wantMoved {
|
||||
t.Errorf("%s: the build again reserved %+v (%v), told %v; want the number %s %s", c.name, again, err, told, first.Version, map[bool]string{true: "withdrawn and the next taken", false: "kept"}[c.wantMoved])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user