E4b: keep the run a module was applied from in its have
The engine kept the applied run in its memory only, so a restarted engine applied an older run's want again. The have, the record of what the engine applied, carries the run (the node-engine seat's form 2): the engine reads it from the have before it applies a want that carries one, a write that names none keeps the last have's, and every have is written at the seat's form. Builds: design 47 H2 §813 (1); H-A-355, H-A-384 (2), H-A-388 (1)
This commit is contained in:
+34
-14
@@ -78,6 +78,10 @@ type Have struct {
|
||||
PullWait *nodeengine.PullWait
|
||||
// Wait is the hold or wait the have says, in the recovery wait with its ask-at and act (design 47 G §560).
|
||||
Wait *nodeengine.Wait
|
||||
// Run is the composition run the module was applied from, its pipeline sequence in decimal (design 47 H2 §813 (1),
|
||||
// H-A-384 (2), H-A-388; nodeengine.HaveByNodeModuleValue.Run): kept in the have, so a restarted engine applies no
|
||||
// older run again. A write that names none keeps the one the module's last have said (writeHave).
|
||||
Run string
|
||||
}
|
||||
|
||||
// Haves is the node's have bucket as the agent uses it.
|
||||
@@ -250,9 +254,6 @@ type Agent struct {
|
||||
// applied is the composition each module was last applied from: a revision a want named from the key's history is
|
||||
// not the key's latest value, and what it holds is still held out of the others' applies.
|
||||
applied map[string]compNow
|
||||
// appliedRun is, of each module applied from a want that carried run, that run: the composition run's pipeline sequence
|
||||
// in decimal (design 47 H2 §813 (1), H-A-355). A want whose run is not newer is not applied again.
|
||||
appliedRun map[string]string
|
||||
// had is, for each module whose have names a composition the bucket keeps (its latest value or a revision), that
|
||||
// composition, read once at the start (loadHad): what runs of a module the agent has not taken yet, ahead of the kept
|
||||
// declaration (issue 924).
|
||||
@@ -345,7 +346,7 @@ func New(env Env) *Agent {
|
||||
if env.Say == nil {
|
||||
env.Say = func(string) {}
|
||||
}
|
||||
return &Agent{env: env, wants: map[string]wantNow{}, comps: map[string]compNow{}, running: map[string]nodeengine.HaveByNodeModuleValue{}, applied: map[string]compNow{}, appliedRun: map[string]string{}, had: map[string]compNow{}, keptData: map[string]bool{},
|
||||
return &Agent{env: env, wants: map[string]wantNow{}, comps: map[string]compNow{}, running: map[string]nodeengine.HaveByNodeModuleValue{}, applied: map[string]compNow{}, had: map[string]compNow{}, keptData: map[string]bool{},
|
||||
attempt: map[string]attempt{}, checked: map[string]bool{}, prior: map[string]bool{}, said: map[string]string{}, waited: map[string]string{}, notComposed: map[string]notComposedMark{},
|
||||
pulls: map[string]*pullWait{}, settledAt: map[string]time.Time{}, settledSeq: map[string]int{},
|
||||
retry: make(chan []string, 8), reconcile: make(chan []string, 64), failedAgain: make(chan string, 8), tries: map[string]int{}, again: make(chan againAsk, 64),
|
||||
@@ -737,11 +738,17 @@ func (a *Agent) writeHave(ctx context.Context, h Have) {
|
||||
h.Kept = a.kept[h.Module]
|
||||
a.mu.Unlock()
|
||||
}
|
||||
if h.Composed == "" && h.Module != NodeModule {
|
||||
if last, ok := a.env.Haves.Read(ctx, h.Module); ok && last.Composed != "" {
|
||||
h.FP, h.Composed = last.FP, last.Composed
|
||||
if h.Sealed == nil {
|
||||
h.Sealed = last.Sealed
|
||||
if (h.Composed == "" || h.Run == "") && h.Module != NodeModule {
|
||||
if last, ok := a.env.Haves.Read(ctx, h.Module); ok {
|
||||
if h.Composed == "" && last.Composed != "" {
|
||||
h.FP, h.Composed = last.FP, last.Composed
|
||||
if h.Sealed == nil {
|
||||
h.Sealed = last.Sealed
|
||||
}
|
||||
}
|
||||
// The run the module was applied from stays in its have until an apply from another run (H-A-384 (2)).
|
||||
if h.Run == "" {
|
||||
h.Run = last.Run
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1515,6 +1522,22 @@ func (a *Agent) settleOne(ctx context.Context, module string) {
|
||||
} else {
|
||||
a.mu.Unlock()
|
||||
}
|
||||
// Design 47 H2 §813 (1), H-A-384 (2): the run the module was applied from is its have's, never this engine's memory, so
|
||||
// a restarted engine applies no older run again. Read only for a want that carries one.
|
||||
appliedRun := ""
|
||||
if w.Want.Run != "" {
|
||||
h, found, unread := a.readHave(ctx, module)
|
||||
if unread {
|
||||
a.mu.Lock()
|
||||
a.sayOnce("run-unread:"+module+":"+w.Want.Run, fmt.Sprintf("the want of %s carries run %s, and its have, which says "+
|
||||
"the run it was applied from, cannot be read: nothing is applied until it reads", module, w.Want.Run))
|
||||
a.mu.Unlock()
|
||||
return
|
||||
}
|
||||
if found {
|
||||
appliedRun = h.Run
|
||||
}
|
||||
}
|
||||
a.mu.Lock()
|
||||
r, runs := a.running[module]
|
||||
// A module whose last apply failed runs no composition whole, whatever it ran before (ranFailed).
|
||||
@@ -1548,7 +1571,7 @@ func (a *Agent) settleOne(ctx context.Context, module string) {
|
||||
a.mu.Unlock()
|
||||
return // failed already for exactly these keys: retried by the next change of either
|
||||
}
|
||||
if was := a.appliedRun[module]; !runIsNewer(w.Want.Run, was) {
|
||||
if was := appliedRun; !runIsNewer(w.Want.Run, was) {
|
||||
// Design 47 H2 §813 (1), H-A-355: one writer per composition key, and the engine applies again only a newer write.
|
||||
a.sayOnce("run:"+module+":"+w.Want.Run, fmt.Sprintf("the want of %s carries run %s, and the engine applied it from run %s, "+
|
||||
"which is not older: nothing is applied", module, w.Want.Run, was))
|
||||
@@ -1841,9 +1864,6 @@ func (a *Agent) apply(ctx context.Context, module string, w wantNow, comp compNo
|
||||
a.running[module] = nodeengine.HaveByNodeModuleValue{Fp: fp, Composed: dig, Phase: nodeengineclient.PhaseRunning}
|
||||
a.applied[module] = comp
|
||||
run := w.Want.Run
|
||||
if run != "" {
|
||||
a.appliedRun[module] = run
|
||||
}
|
||||
a.mu.Unlock()
|
||||
if run != "" {
|
||||
a.env.Say(fmt.Sprintf("applied %s from run %s", what, run))
|
||||
@@ -1852,7 +1872,7 @@ func (a *Agent) apply(ctx context.Context, module string, w wantNow, comp compNo
|
||||
if a.env.Settled != nil {
|
||||
a.env.Settled(module)
|
||||
}
|
||||
a.writeHave(ctx, Have{Module: module, FP: fp, Composed: dig, Phase: string(nodeengineclient.PhaseRunning), Detail: res.Detail})
|
||||
a.writeHave(ctx, Have{Module: module, FP: fp, Composed: dig, Phase: string(nodeengineclient.PhaseRunning), Detail: res.Detail, Run: run})
|
||||
a.catchUp(ctx, module, catchUps)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user