H-A-479 (2) runner: a rerun reopening an ended pipeline pins its revision again
The indexer pins a pipeline's revision from pipeline-started to
pipeline-ended, so a rerun of a step in an ended pipeline (main.258's
composition at 14:41, after its end at 14:15) asked a step against a
revision the catalog had already removed. A rerun of an ended delivering
pipeline now reads its revision fresh through the catalog seat's verb
revision first and is refused by name, nothing asked, when it is gone
("its revision <r> is gone; start the mover again at the head"); once
reopened it says its pipeline-started again, so the indexer pins the
revision until its next end.
Builds: design 47 H2 H-A-479, H-A-479 addendum (2)
This commit is contained in:
@@ -96,3 +96,34 @@ func TestARevisionHeardIsHandedToItsStart(t *testing.T) {
|
||||
t.Errorf("a body that is no event = %v, want it ended", err)
|
||||
}
|
||||
}
|
||||
|
||||
// H-A-479 addendum (2): a revision is held when the catalog seat's revision verb answers that revision, read fresh; none-yet,
|
||||
// another revision or a refusal saying "no such object" is gone; another failure is said as it is.
|
||||
func TestRevisionHeldReadsTheCatalogsRevisionFresh(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
answer catalog.RevisionAnswer
|
||||
err error
|
||||
gone bool
|
||||
fails bool
|
||||
}{
|
||||
{name: "held", answer: catalog.RevisionAnswer{Revision: &catalog.CatalogRevision{Revision: 258}}},
|
||||
{name: "another revision", answer: catalog.RevisionAnswer{Revision: &catalog.CatalogRevision{Revision: 259}}, gone: true, fails: true},
|
||||
{name: "none yet", answer: catalog.RevisionAnswer{NoneYet: true}, gone: true, fails: true},
|
||||
{name: "removed", err: errors.New("revision main.258: no such object"), gone: true, fails: true},
|
||||
{name: "unreachable", err: errors.New("no responders"), fails: true},
|
||||
} {
|
||||
var asked catalog.RevisionInput
|
||||
call := func(_ string, body any) (json.RawMessage, error) {
|
||||
asked = body.(catalog.RevisionInput)
|
||||
if c.err != nil {
|
||||
return nil, c.err
|
||||
}
|
||||
return json.Marshal(c.answer)
|
||||
}
|
||||
err := revisionHeld(call)("main", 258)
|
||||
if (err != nil) != c.fails || errors.Is(err, pipeline.ErrRevisionGone) != c.gone || asked.Revision != 258 || asked.Branch != "main" {
|
||||
t.Errorf("%s: %v (asked %+v)", c.name, err, asked)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,14 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
"git.novox.be/novox/mesh-sdk/go/seatlist"
|
||||
|
||||
@@ -65,5 +69,37 @@ func writeVerbs(h *pipeline.Hearer, s *pipeline.Starter, view func(string) (pipe
|
||||
candidate := func(group, branch string, revision int64) (pipeline.Half, error) {
|
||||
return readCandidate(calls.CallKept, catalog.CatalogRevisionEvent{Kind: "candidate", Group: group, Branch: branch, Revision: revision})
|
||||
}
|
||||
return pipeline.Verbs{Hearer: h, Starter: s, View: view, Candidate: candidate, Acts: meshhandactsclient.Recorder{Ask: calls.Call}}
|
||||
return pipeline.Verbs{Hearer: h, Starter: s, View: view, Candidate: candidate, Acts: meshhandactsclient.Recorder{Ask: calls.Call},
|
||||
RevisionHeld: revisionHeld(calls.CallKept)}
|
||||
}
|
||||
|
||||
// revisionHeld reads the first page of a branch's catalog revision through the catalog seat's verb revision, never a kept
|
||||
// copy, so a rerun reopening an ended pipeline knows whether the catalog still keeps its revision (design 47 H2 H-A-479
|
||||
// addendum (2)): an answer of that revision is kept; none-yet, another revision, or a refusal saying the catalog's
|
||||
// "no such object" is gone (pipeline.ErrRevisionGone); any other failure is said as it is.
|
||||
func revisionHeld(call func(key string, body any) (json.RawMessage, error)) func(string, int64) error {
|
||||
return func(branch string, revision int64) error {
|
||||
raw, err := call(meshcatalogclient.RevisionVerb, catalog.RevisionInput{Branch: keys.EscapeName(branch), Revision: revision})
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "no such object") {
|
||||
return fmt.Errorf("%w: %v", pipeline.ErrRevisionGone, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
answer, said, ok := buscalls.Unwrap(raw)
|
||||
if !ok {
|
||||
if strings.Contains(said, "no such object") {
|
||||
return fmt.Errorf("%w: %s", pipeline.ErrRevisionGone, said)
|
||||
}
|
||||
return fmt.Errorf("%s answered: %s", meshcatalogclient.RevisionVerb, said)
|
||||
}
|
||||
var a catalog.RevisionAnswer
|
||||
if err := json.Unmarshal(answer, &a); err != nil {
|
||||
return fmt.Errorf("%s answered no revision: %w", meshcatalogclient.RevisionVerb, err)
|
||||
}
|
||||
if a.NoneYet || a.Revision == nil || a.Revision.Revision != revision {
|
||||
return fmt.Errorf("%w: %s answered no revision %d of %s", pipeline.ErrRevisionGone, meshcatalogclient.RevisionVerb, revision, branch)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +30,15 @@ type Verbs struct {
|
||||
Acts views.HandActs
|
||||
// Runs answers the read verb test-runs, answered by the process that holds test-runs-cap-mib (A-470i).
|
||||
Runs RunsRead
|
||||
// RevisionHeld says whether a branch's catalog revision is still kept, read through the catalog seat's verb revision
|
||||
// at the time of the ask: nil when it is, an error wrapping ErrRevisionGone when it is removed (design 47 H2 H-A-479
|
||||
// addendum (2)).
|
||||
RevisionHeld func(branch string, revision int64) error
|
||||
}
|
||||
|
||||
// ErrRevisionGone is a catalog revision the catalog no longer keeps (H-A-479 addendum (2)).
|
||||
var ErrRevisionGone = errors.New("the catalog revision is gone")
|
||||
|
||||
func (v Verbs) now() time.Time { return v.Hearer.now() }
|
||||
|
||||
func (v Verbs) record(verb, what, why string) error {
|
||||
@@ -276,10 +283,48 @@ func (v Verbs) EndAgain(_ string, in seat.EndAgainInput) (seat.EndAgainAnswer, e
|
||||
// the ask saying it is a rerun and the caller the bus proved; a failed pipeline runs again and ends once more with its end
|
||||
// count one higher (§325), an approval never asked waiting again. A review waits again; an approval is asked again by
|
||||
// `ask-again`.
|
||||
//
|
||||
// A rerun of a step in an ended delivering pipeline reopens it: its revision is read first and the rerun refused by name,
|
||||
// nothing asked, when the catalog removed it; once reopened its pipeline-started is said again, so the indexer pins its
|
||||
// revision again until its next end (design 47 H2 H-A-479 addendum (2)).
|
||||
func (v Verbs) Rerun(caller string, in seat.RerunInput) (seat.RerunAnswer, error) {
|
||||
if in.Step == seat.StepResultStepApproval {
|
||||
return seat.RerunAnswer{}, errors.New("an approval is asked again by ask-again, not rerun")
|
||||
}
|
||||
reopens, err := v.reopening(in.Pipeline)
|
||||
if err != nil {
|
||||
return seat.RerunAnswer{}, err
|
||||
}
|
||||
a, err := v.rerun(caller, in)
|
||||
if err == nil && reopens && v.Starter != nil {
|
||||
if p, _, gerr := v.Hearer.Store.Get(in.Pipeline); gerr == nil && p.Ended == nil {
|
||||
v.Starter.sayStartedPipeline(p, v.now())
|
||||
v.Starter.logf("%s reopened by a rerun: its pipeline-started is said again, so its revision %d is pinned again (H-A-479)", in.Pipeline, p.Revision)
|
||||
}
|
||||
}
|
||||
return a, err
|
||||
}
|
||||
|
||||
// reopening says whether a rerun of pipeline key reopens an ended delivering pipeline, refusing it when its revision is
|
||||
// gone (H-A-479 addendum (2)). A pipeline not read, a run's, or one the rerun refuses anyway is left to the rerun.
|
||||
func (v Verbs) reopening(key string) (bool, error) {
|
||||
p, _, err := v.Hearer.Store.Get(key)
|
||||
if err != nil || p.Ended == nil || p.Run != "" || p.Revision <= 0 ||
|
||||
p.Outcome == seat.PipelineOutcomeCancelled || p.Outcome == seat.PipelineOutcomeSuperseded {
|
||||
return false, nil
|
||||
}
|
||||
if v.RevisionHeld != nil {
|
||||
if err := v.RevisionHeld(p.Branch, p.Revision); errors.Is(err, ErrRevisionGone) {
|
||||
return false, fmt.Errorf("the pipeline %s ended and its revision %d is gone; start the mover again at the head: nothing was asked (%v)", key, p.Revision, err)
|
||||
} else if err != nil {
|
||||
return false, fmt.Errorf("the pipeline %s ended and its revision %d is not read, so it is not reopened: nothing was asked: %w", key, p.Revision, err)
|
||||
}
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// rerun asks one step again (Rerun).
|
||||
func (v Verbs) rerun(caller string, in seat.RerunInput) (seat.RerunAnswer, error) {
|
||||
if p, _, err := v.Hearer.Store.Get(in.Pipeline); err == nil {
|
||||
if i, err := stepOf(p, in.Module, in.Step, in.Artifact); err == nil && v.Hearer.TestRuns != nil && sharedRun(p.Steps[i]) != "" && BoundSeat(p.Steps[i].Seat) {
|
||||
return v.rerunTest(caller, in, p.Steps[i])
|
||||
|
||||
@@ -3,6 +3,7 @@ package pipeline
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -493,3 +494,60 @@ func TestStartWithModulesStartsAFailedMoverAgainAtTheHead(t *testing.T) {
|
||||
t.Error("a mover key of an again pipeline is not read as a mover's steps")
|
||||
}
|
||||
}
|
||||
|
||||
// H-A-479 addendum (2): a rerun of a step in an ended pipeline pins its revision again at the reopening (its pipeline-started
|
||||
// said again), and is refused by name, nothing asked, when the revision is already removed.
|
||||
func TestARerunOfAnEndedPipelinePinsItsRevisionAgainOrIsRefusedWhenItIsGone(t *testing.T) {
|
||||
v, store, _, asks, _, _ := verbsFixture()
|
||||
var started []seat.PipelineStarted
|
||||
v.Starter.Say = func(_ string, body any) error {
|
||||
if ps, ok := body.(seat.PipelineStarted); ok {
|
||||
started = append(started, ps)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
e := store[pkey]
|
||||
at := time.Unix(2, 0)
|
||||
e.p.Revision, e.p.Outcome, e.p.Ended = 5, seat.PipelineOutcomeFailed, &at
|
||||
for i := range e.p.Steps {
|
||||
if e.p.Steps[i].Artifact == "app:program" && e.p.Steps[i].Step == "lint" {
|
||||
e.p.Steps[i].Outcome = seat.StepResultOutcomeFailed
|
||||
}
|
||||
}
|
||||
store[pkey] = e
|
||||
gone := true
|
||||
v.RevisionHeld = func(branch string, revision int64) error {
|
||||
if gone {
|
||||
return fmt.Errorf("revision %s.%d: no such object: %w", branch, revision, ErrRevisionGone)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
in := seat.RerunInput{Pipeline: pkey, Step: "lint", Artifact: "app:program", Why: "retry"}
|
||||
if _, err := v.Rerun("operator", in); err == nil || !strings.Contains(err.Error(), "its revision 5 is gone; start the mover again at the head") {
|
||||
t.Fatalf("a rerun of an ended pipeline whose revision is gone = %v; want refused by name", err)
|
||||
}
|
||||
if len(asks.asks) != 0 || store[pkey].p.Outcome != seat.PipelineOutcomeFailed || len(started) != 0 {
|
||||
t.Fatalf("a refused rerun asked %d, left the pipeline %s, said %d starts", len(asks.asks), store[pkey].p.Outcome, len(started))
|
||||
}
|
||||
gone = false
|
||||
if _, err := v.Rerun("operator", in); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(started) != 1 || started[0].Pipeline != pkey || started[0].Revision != 5 {
|
||||
t.Errorf("pipeline-started at the reopening = %+v, want %s at revision 5 (its revision pinned again)", started, pkey)
|
||||
}
|
||||
// A rerun of a running pipeline reopens nothing and says no start.
|
||||
e = store[pkey]
|
||||
for i := range e.p.Steps {
|
||||
if e.p.Steps[i].Artifact == "app:program" && e.p.Steps[i].Step == "unit" {
|
||||
e.p.Steps[i].Outcome = seat.StepResultOutcomeFailed
|
||||
}
|
||||
}
|
||||
store[pkey] = e
|
||||
if _, err := v.Rerun("operator", seat.RerunInput{Pipeline: pkey, Step: "unit", Artifact: "app:program", Why: "x"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(started) != 1 {
|
||||
t.Errorf("a rerun of a running pipeline said pipeline-started again: %+v", started)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user