Builder: a released build counts as reserved for the build step (A-456a)
Builds: design 47 G A-456a, A-456
This commit is contained in:
@@ -115,7 +115,10 @@ type Reserver struct {
|
||||
// Took is told when a build took over the series' reservation of an older build never released (design 47 G A-455): the
|
||||
// older reservation, which no want follows any more, is gone from the key, replaced by the newer's. Nil is told none.
|
||||
Took func(ctx context.Context, older, newer ReservedVersion)
|
||||
Now func() time.Time
|
||||
// Releases is the builder's own record of the versions it saw released, by module and fingerprint (design 47 G A-456a): the
|
||||
// reservation is deleted at release, so a rerun of a released build's step reads it here, never from the catalog. Nil keeps none.
|
||||
Releases ReserveStore
|
||||
Now func() time.Time
|
||||
}
|
||||
|
||||
func (r *Reserver) now() time.Time {
|
||||
@@ -248,6 +251,20 @@ func allSet(m map[string]string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// ReleasedKey is the key of the record that the build of fingerprint was released (design 47 G A-456a), in the state acted.
|
||||
func ReleasedKey(module, fingerprint string) string {
|
||||
return "released." + EscapeToken(module) + "." + EscapeToken(fingerprint)
|
||||
}
|
||||
|
||||
// ReleasedFor says whether the builder saw a version released for the build of fingerprint.
|
||||
func (r *Reserver) ReleasedFor(ctx context.Context, module, fingerprint string) (bool, error) {
|
||||
if r.Releases == nil {
|
||||
return false, nil
|
||||
}
|
||||
_, _, found, err := r.Releases.Get(ctx, ReleasedKey(module, fingerprint))
|
||||
return found, err
|
||||
}
|
||||
|
||||
// Released takes the catalog's version-released in: the key of that version is deleted, and every key of module's other
|
||||
// series (the manifest moved on). A key holding a newer reserved version of the same series stays. It answers the keys
|
||||
// deleted.
|
||||
@@ -269,6 +286,11 @@ func (r *Reserver) Released(ctx context.Context, module, version string) ([]stri
|
||||
if !found || (cur.Series == series && cur.Version != version) {
|
||||
continue
|
||||
}
|
||||
if cur.Version == version && cur.Fingerprint != "" && r.Releases != nil {
|
||||
if _, err := r.Releases.Create(ctx, ReleasedKey(module, cur.Fingerprint), []byte(`{"version":"`+version+`"}`)); err != nil && !errors.Is(err, ErrConflict) {
|
||||
return gone, fmt.Errorf("the release of %s %s cannot be recorded: %w", module, version, err)
|
||||
}
|
||||
}
|
||||
if err := r.Store.Delete(ctx, k); err != nil {
|
||||
return gone, fmt.Errorf("%s cannot be deleted: %w", k, err)
|
||||
}
|
||||
|
||||
@@ -173,3 +173,31 @@ func TestReservationIsReadAndMarkedPublished(t *testing.T) {
|
||||
t.Errorf("the bound key does not name the reservation back: %q %v", key, ok)
|
||||
}
|
||||
}
|
||||
|
||||
// TestAReleaseIsRecordedByFingerprintBeforeItsReservationGoes: design 47 G A-456a — the version-released of a version records
|
||||
// that the build of its fingerprint was released, so a rerun of its step finds it after the reservation is deleted.
|
||||
func TestAReleaseIsRecordedByFingerprintBeforeItsReservationGoes(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
rel := &reserveMem{mem: newMem()}
|
||||
r := &Reserver{Store: &reserveMem{mem: newMem()}, Releases: rel, Filled: func() bool { return true },
|
||||
ReleasedOf: func(context.Context, string) ([]string, error) { return nil, nil }}
|
||||
v, err := r.Reserve(ctx, "m", "0.1", []string{"m:a"}, Source{Fingerprint: "src2:aa"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if ok, _ := r.ReleasedFor(ctx, "m", "src2:aa"); ok {
|
||||
t.Fatal("a build not released is said released")
|
||||
}
|
||||
if _, err := r.Released(ctx, "m", v.Version); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if ok, err := r.ReleasedFor(ctx, "m", "src2:aa"); !ok || err != nil {
|
||||
t.Errorf("released for the fingerprint: %v (%v), want true", ok, err)
|
||||
}
|
||||
if ok, _ := r.ReleasedFor(ctx, "m", "src2:bb"); ok {
|
||||
t.Error("another fingerprint is said released")
|
||||
}
|
||||
if all, _ := r.All(ctx); len(all) != 0 {
|
||||
t.Errorf("reservations left: %v", all)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user