VW5: the view takes each watched branch's source from the gate's verb source, per branch
The view read the gate's state source and its history, fixed to the branch main. Each watched branch's source is now the seat mesh-delivery's verb source given that branch, asked again on its source-moved; the source row and the event delivered are per branch, a repository's reach is from the source of its modules' registration's first branch, laid over the reach the view's own state kept at its start, and view_tiers given no revision answers per branch. The manifest drops its read of mesh-delivery-gate.source and names the source answer's fields it relies on. Builds: design 47 G §507, §512, §532, §558, A-173, A-225 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
@@ -17,8 +17,8 @@ import (
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshwatchdogsclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-indexer/takein"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-view/viewstate"
|
||||
@@ -437,7 +437,7 @@ func main() {
|
||||
r.SignersState = read(stdio.State("mesh-vault.signers"))
|
||||
r.ConditionsState, r.AttemptsState = read(stdio.State(view.StatusConditionsState)), read(stdio.State(view.StatusAttemptsState))
|
||||
r.PresenceState, r.StuckState = read(stdio.State(view.StatusPresenceState)), read(stdio.State(view.StatusStuckState))
|
||||
r.SourceState = read(stdio.State(view.GateModule + ".source"))
|
||||
r.Sources = view.SourcesOf(stdio.Ask, branches.Followed)
|
||||
r.ProvisionsState = read(stdio.State(view.ProvisionsRead))
|
||||
r.BuildLog = stdio.Log(builds.BuildLogRead).Since
|
||||
r.Pending = pendingOf
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
|
||||
"mesh-delivery-view/internal/view"
|
||||
"reflect"
|
||||
"strings"
|
||||
@@ -137,10 +138,22 @@ func tiersToolSaysEachModulesWait(t *testing.T) {
|
||||
t.Errorf("view_tiers with no answer of indexer_pending = %+v, %v", out, err)
|
||||
}
|
||||
r.Pending = nil
|
||||
// No revision named: the gate's newest, its source key's revision.
|
||||
r.SourceState = view.StateRead{GetEntry: func(string) (json.RawMessage, uint64, error) { return json.RawMessage(`{}`), 9, nil }}
|
||||
if out, err := run(t, r, view.TiersTool, map[string]any{}); err != nil || out.(view.Tiers).Revision != 9 || out.(view.Tiers).Modules != 3 {
|
||||
t.Errorf("view_tiers of the gate's newest = %+v, %v", out, err)
|
||||
// No revision named: per watched branch, the newest source revision the gate's verb source answers for it (design 47 G
|
||||
// A-173); a branch with no source revision yet is left out.
|
||||
asked := map[string]bool{}
|
||||
call := func(key string, body any) (json.RawMessage, error) {
|
||||
in, _ := body.(meshdelivery.SourceInput)
|
||||
asked[key+" "+in.Branch] = true
|
||||
rev := map[string]int64{"release": 9}[in.Branch]
|
||||
return json.Marshal(meshdelivery.SourceAnswer{Branch: in.Branch, Revision: rev})
|
||||
}
|
||||
r.Sources = view.SourcesOf(call, func() []string { return []string{"release", "beta"} })
|
||||
if out, err := run(t, r, view.TiersTool, map[string]any{}); err != nil || len(out.(view.BranchTiers).Branches) != 1 ||
|
||||
out.(view.BranchTiers).Branches[0].Branch != "release" || out.(view.BranchTiers).Branches[0].Revision != 9 || out.(view.BranchTiers).Branches[0].Modules != 3 {
|
||||
t.Errorf("view_tiers of each branch's newest = %+v, %v", out, err)
|
||||
}
|
||||
if !asked["seat:mesh-delivery.source release"] || !asked["seat:mesh-delivery.source beta"] {
|
||||
t.Errorf("the gate's verb source was asked %v, want once per watched branch", asked)
|
||||
}
|
||||
// ADR 0614 §2-§5: a want held on a verb, a reader capability or bus state is named by its edge; bus state is no
|
||||
// provisioner key (none is ever made for it), so a module asking it shows no provision wait of it; and each verb edge
|
||||
|
||||
@@ -59,7 +59,9 @@ type catalogHolder struct {
|
||||
// rev is the revision's number; entries are its entries by module.
|
||||
rev int64
|
||||
entries map[string]meshcatalog.CatalogEntry
|
||||
ctx context.Context
|
||||
// src is the gate's source revision of catalogBranch, as its verb source answers it.
|
||||
src meshdelivery.SourceAnswer
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
func serveCatalog(t testing.TB, ctx context.Context, js jetstream.JetStream, nc *nats.Conn) *catalogHolder {
|
||||
@@ -98,8 +100,17 @@ func serveCatalog(t testing.TB, ctx context.Context, js jetstream.JetStream, nc
|
||||
raw, _ := json.Marshal(map[string]any{"result": a, "node": "n0"})
|
||||
_ = m.Respond(raw)
|
||||
}
|
||||
// The gate's verb source: given no branch the branches it keeps, given catalogBranch its source revision (A-173).
|
||||
source := func(m *nats.Msg) {
|
||||
raw, _ := json.Marshal(map[string]any{"result": map[string]any{"branches": []string{catalogBranch}}, "node": "n0"})
|
||||
var in meshdelivery.SourceInput
|
||||
_ = json.Unmarshal(m.Data, &in)
|
||||
var a any = map[string]any{"branches": []string{catalogBranch}}
|
||||
if in.Branch != "" {
|
||||
h.mu.Lock()
|
||||
a = meshdelivery.SourceAnswer{Branch: in.Branch, Revision: h.src.Revision, Group: h.src.Group, Repositories: h.src.Repositories}
|
||||
h.mu.Unlock()
|
||||
}
|
||||
raw, _ := json.Marshal(map[string]any{"result": a, "node": "n0"})
|
||||
_ = m.Respond(raw)
|
||||
}
|
||||
for subject, handle := range map[string]nats.MsgHandler{"mesh.seat.mesh-catalog.call.revision": answer,
|
||||
@@ -118,6 +129,21 @@ func serveCatalog(t testing.TB, ctx context.Context, js jetstream.JetStream, nc
|
||||
// catalogBranch is the one watched branch of these tests: no branch is named in the view's code (design 47 G §532).
|
||||
const catalogBranch = "release"
|
||||
|
||||
// moveSource is the gate's next source revision of catalogBranch, said as source-moved (design 47 G §507, A-173).
|
||||
func (h *catalogHolder) moveSource(rev int64, group string, heads map[string]string) {
|
||||
h.t.Helper()
|
||||
h.mu.Lock()
|
||||
h.src = meshdelivery.SourceAnswer{Revision: rev, Group: group}
|
||||
for repository, head := range heads {
|
||||
h.src.Repositories = append(h.src.Repositories, meshdelivery.SourceHead{Repository: repository, Head: head, Trunk: catalogBranch})
|
||||
}
|
||||
h.mu.Unlock()
|
||||
body, _ := json.Marshal(meshdelivery.SourceMovedEvent{Branch: catalogBranch, Revision: rev, Group: group})
|
||||
if _, err := h.js.Publish(h.ctx, meshdelivery.SubjectSourceMoved(catalogBranch), body); err != nil {
|
||||
h.t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// put is the holder's next trunk revision with the entry of one module changed, said as catalog-revision.
|
||||
func (h *catalogHolder) put(e meshcatalog.CatalogEntry) {
|
||||
h.t.Helper()
|
||||
@@ -762,7 +788,7 @@ func TestProcessWholeSaysTheSourceRevisionIsDelivered(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
kvs := map[string]jetstream.KeyValue{}
|
||||
for _, name := range []string{view.SourceBucket, view.AssignerWantsBucket, view.HaveBucket, viewstate.ReachBucket} {
|
||||
for _, name := range []string{view.AssignerWantsBucket, view.HaveBucket, viewstate.ReachBucket} {
|
||||
kv, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: name, History: 5})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -791,7 +817,6 @@ func TestProcessWholeSaysTheSourceRevisionIsDelivered(t *testing.T) {
|
||||
want, _ := meshwantsclient.EncodeWant(meshwantsclient.Want{Fp: fp, Composed: "sha256:" + strings.Repeat("c", 64)})
|
||||
failed, _ := nodeengineclient.EncodeHave(nodeengine.HaveByNodeModuleValue{Fp: fp, Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthFailed})
|
||||
good, _ := nodeengineclient.EncodeHave(nodeengine.HaveByNodeModuleValue{Fp: fp, Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK})
|
||||
src, _ := meshdeliveryclient.EncodeSource(meshdelivery.SourceByBranchValue{Group: "feat/x", Heads: map[string]string{"novox/web": strings.Repeat("1", 40)}})
|
||||
catalog.put(meshcatalog.CatalogEntry{Module: "web", Fp: fp, Manifest: map[string]any{"module": "a"}, Repository: "novox/web", Commit: strings.Repeat("1", 40), Path: meshcatalogclient.RootPath})
|
||||
if _, err := kvs[view.AssignerWantsBucket].Put(ctx, "want.ace.web", want); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -799,10 +824,9 @@ func TestProcessWholeSaysTheSourceRevisionIsDelivered(t *testing.T) {
|
||||
if _, err := kvs[view.HaveBucket].Put(ctx, "ace.web", failed); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rev, err := kvs[view.SourceBucket].Put(ctx, meshdeliveryclient.SourceKey("main"), src)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// The gate's source of the watched branch moves: the view asks the verb source for it and reads no gate state (A-173).
|
||||
const rev = 41
|
||||
catalog.moveSource(rev, "feat/x", map[string]string{"novox/web": strings.Repeat("1", 40)})
|
||||
time.Sleep(time.Second)
|
||||
if info, err := events.Info(ctx, jetstream.WithSubjectFilter("mesh.mod.mesh-delivery-view.event."+DeliveredEventType)); err != nil || len(info.State.Subjects) != 0 {
|
||||
t.Fatalf("an event was said before the revision was delivered: %v %+v", err, info.State)
|
||||
@@ -818,8 +842,8 @@ func TestProcessWholeSaysTheSourceRevisionIsDelivered(t *testing.T) {
|
||||
t.Fatal("the delivery of the source revision was never said")
|
||||
}
|
||||
var e view.DeliveredEvent
|
||||
if err := json.Unmarshal(msg.Data, &e); err != nil || e.Revision != rev || e.Group != "feat/x" || e.Heads["novox/web"] != strings.Repeat("1", 40) {
|
||||
t.Errorf("the event = %+v, %v; want revision %d, group feat/x and the heads", e, err, rev)
|
||||
if err := json.Unmarshal(msg.Data, &e); err != nil || e.Branch != catalogBranch || e.Revision != rev || e.Group != "feat/x" || e.Heads["novox/web"] != strings.Repeat("1", 40) {
|
||||
t.Errorf("the event = %+v, %v; want the branch %s, revision %d, group feat/x and the heads", e, err, catalogBranch, rev)
|
||||
}
|
||||
if msg.Header.Get("x-source") != "mesh-delivery-view" || msg.Header.Get("x-event-id") == "" {
|
||||
t.Errorf("the headers = %v", msg.Header)
|
||||
|
||||
@@ -142,12 +142,12 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
}
|
||||
}
|
||||
open := buckets{js: js, reader: reader}
|
||||
for _, bucket := range []string{view.HaveBucket, view.AssignmentsBucket, view.PresenceBucket, view.StuckBucket, view.CandidatesBucket, view.AnswersBucket, builds.BuilderBuildsBucket, view.AssignerWantsBucket, view.SourceBucket, view.AssignerAsksBucket, viewstate.ViewAnswersBucket, view.TakenBucket} {
|
||||
for _, bucket := range []string{view.HaveBucket, view.AssignmentsBucket, view.PresenceBucket, view.StuckBucket, view.CandidatesBucket, view.AnswersBucket, builds.BuilderBuildsBucket, view.AssignerWantsBucket, view.AssignerAsksBucket, viewstate.ViewAnswersBucket, view.TakenBucket, viewstate.ReachBucket} {
|
||||
go follow(ctx, open, bucket, false, model, logger)
|
||||
}
|
||||
// The source's history gives each head's source revision (ADR 0556); the modules' history is each revision of the
|
||||
// catalog half the view takes, in its order (below).
|
||||
go follow(ctx, open, view.SourceBucket, true, model, logger)
|
||||
// The view's own state reach, as it stood at the start, is what the derivation lays its history over (design 47 G A-225);
|
||||
// the modules' history is each revision of the catalog half the view takes, in its order (below), and each watched
|
||||
// branch's source is the seat mesh-delivery's verb source per branch, followed by its source-moved (A-173).
|
||||
statusBucket := process.AwaitBucket(ctx, js, conn, firstViewsBucket, "view_first_views reads nothing and view_first_view_again is not heard", logger.Printf)
|
||||
// The modules are the catalog half's, per watched branch, through meshcatalogclient's branch follower adopted on the
|
||||
// reader (design 47 G §532, §614): the registrations' branches, before the first registrations the gate's source's;
|
||||
@@ -158,7 +158,8 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
return err
|
||||
}
|
||||
branches.Logf = logger.Printf
|
||||
modules := &catalogModules{ctx: ctx, branches: branches, model: model, logger: logger, applied: map[string]bool{}}
|
||||
sources := &branchSources{ctx: ctx, reader: reader, call: calls.Call, model: model, logger: logger}
|
||||
modules := &catalogModules{ctx: ctx, branches: branches, sources: sources, model: model, logger: logger, applied: map[string]bool{}}
|
||||
branches.Changed = modules.changed
|
||||
reader.Start(ctx, js, cred, statusBucket)
|
||||
go func() {
|
||||
@@ -341,6 +342,7 @@ func emitEvent(ctx context.Context, js jetstream.JetStream, cred process.Account
|
||||
type catalogModules struct {
|
||||
ctx context.Context
|
||||
branches *meshcatalogclient.Branches
|
||||
sources *branchSources // the source of each branch followed (A-173)
|
||||
model *view.Model
|
||||
logger *log.Logger
|
||||
|
||||
@@ -352,6 +354,7 @@ type catalogModules struct {
|
||||
|
||||
// changed is the branch follower's Changed: a module of one branch changed.
|
||||
func (c *catalogModules) changed(_, module string, _ json.RawMessage, _ bool, at time.Time) {
|
||||
c.follow()
|
||||
c.mu.Lock()
|
||||
held := c.held
|
||||
c.mu.Unlock()
|
||||
@@ -411,6 +414,7 @@ func (c *catalogModules) settle() {
|
||||
// whole hands every module the followed branches list, removes from the model each it holds that none lists any more,
|
||||
// and tells the model the modules are read.
|
||||
func (c *catalogModules) whole() {
|
||||
c.follow()
|
||||
at := time.Now()
|
||||
listed := map[string]bool{}
|
||||
for _, branch := range c.branches.Followed() {
|
||||
@@ -443,9 +447,35 @@ func (c *catalogModules) whole() {
|
||||
c.model.Initial(view.ReachHistory(view.ModulesBucket))
|
||||
}
|
||||
|
||||
// follow has the source of every followed branch followed, and no other (A-173).
|
||||
func (c *catalogModules) follow() {
|
||||
if c.sources != nil {
|
||||
c.sources.ensure(c.branches.Followed())
|
||||
}
|
||||
}
|
||||
|
||||
// branchOf is the watched branch a module's entry is read from: the first branch of its registration, before the first
|
||||
// registrations the first followed branch that lists it (design 47 G A-103, A-173); "" when none.
|
||||
func (c *catalogModules) branchOf(module string) string {
|
||||
if reg, ok := c.branches.Registrations.Registration(module); ok && len(reg.Branches) > 0 {
|
||||
return reg.Branches[0]
|
||||
}
|
||||
for _, branch := range c.branches.Followed() {
|
||||
if cat, ok := c.branches.Catalog(branch); ok {
|
||||
if _, ok := cat.Entry(module); ok {
|
||||
return branch
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// apply hands the model one module's entry, or its removal when no branch lists it.
|
||||
func (c *catalogModules) apply(module string, entry meshcatalog.CatalogEntry, listed bool, at time.Time) {
|
||||
e := view.Entry{Bucket: view.ModulesBucket, Key: module, At: at, Deleted: !listed}
|
||||
if listed {
|
||||
e.Branch = c.branchOf(module)
|
||||
}
|
||||
if listed {
|
||||
raw, _ := json.Marshal(entry)
|
||||
v, err := view.ModuleValue(raw)
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"mesh-delivery-view/internal/view"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/sourcebranches"
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
"git.novox.be/novox/mesh-sdk/go/views"
|
||||
)
|
||||
|
||||
// sourceState is the state of the view of one watched branch's source in the view's reader: `mesh-delivery.source.<branch>`.
|
||||
const sourceState = "source"
|
||||
|
||||
// adopter is how branchSources puts a branch's view on the view's one reader and takes it off (views.ProcessReader).
|
||||
type adopter interface {
|
||||
Adopt(f *views.Follower, seat, event string, hear func(context.Context, []byte) error) (*views.Picture, error)
|
||||
Drop(owner, state string) error
|
||||
}
|
||||
|
||||
// branchSources follows the source of each watched branch on its own (design 47 G §507, §512, A-173): per branch the
|
||||
// first view of the seat mesh-delivery's verb source given that branch, then each source-moved of that branch, asked
|
||||
// again until the revision heard is held; each answer goes to the model as the branch's SourceBucket entry. The branches
|
||||
// are the ones the branch follower follows (ensure); none is named here.
|
||||
type branchSources struct {
|
||||
ctx context.Context
|
||||
reader adopter
|
||||
call func(key string, body any) (json.RawMessage, error)
|
||||
model *view.Model
|
||||
logger *log.Logger
|
||||
|
||||
mu sync.Mutex
|
||||
branches map[string]*views.Follower // by escaped branch
|
||||
}
|
||||
|
||||
// ensure follows the source of every branch named and drops the view of each followed branch no longer named.
|
||||
func (s *branchSources) ensure(followed []string) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if s.branches == nil {
|
||||
s.branches = map[string]*views.Follower{}
|
||||
}
|
||||
named := map[string]bool{}
|
||||
for _, branch := range followed {
|
||||
esc := keys.EscapeName(branch)
|
||||
named[esc] = true
|
||||
if s.branches[esc] != nil {
|
||||
continue
|
||||
}
|
||||
f := s.follower(branch)
|
||||
if _, err := s.reader.Adopt(f, meshdelivery.Seat, meshdelivery.EventSourceMoved, s.hear(branch, f)); err != nil {
|
||||
s.logger.Printf("the source of %s is not followed, and is adopted again at the next change of the catalog half: %v", branch, err)
|
||||
continue
|
||||
}
|
||||
s.branches[esc] = f
|
||||
}
|
||||
for esc := range s.branches {
|
||||
if named[esc] {
|
||||
continue
|
||||
}
|
||||
if err := s.reader.Drop(meshdelivery.Seat, views.BranchState(sourceState, mustUnescape(esc))); err != nil {
|
||||
s.logger.Printf("the source of %s is not dropped: %v", esc, err)
|
||||
continue
|
||||
}
|
||||
delete(s.branches, esc)
|
||||
s.model.Apply(view.Entry{Bucket: view.SourceBucket, Key: esc, Deleted: true, At: time.Now()})
|
||||
}
|
||||
}
|
||||
|
||||
func mustUnescape(esc string) string {
|
||||
name, err := keys.UnescapeName(esc)
|
||||
if err != nil {
|
||||
return esc
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
// follower is the view of one branch's source: its one value, keyed by the escaped branch, the verb's answer.
|
||||
func (s *branchSources) follower(branch string) *views.Follower {
|
||||
esc := keys.EscapeName(branch)
|
||||
f := &views.Follower{Owner: meshdelivery.Seat, Tool: view.SourceVerb, State: views.BranchState(sourceState, branch)}
|
||||
f.Ask = func(context.Context, string) (views.Answer, error) {
|
||||
a, err := view.SourceOf(s.call, branch)
|
||||
if err != nil {
|
||||
return views.Answer{}, err
|
||||
}
|
||||
raw, err := json.Marshal(a)
|
||||
if err != nil {
|
||||
return views.Answer{}, err
|
||||
}
|
||||
return views.Answer{V: 1, Owner: meshdelivery.Seat, State: f.State, Revision: uint64(a.Revision), Created: sourcebranches.Created,
|
||||
Values: map[string]json.RawMessage{esc: raw}, At: time.Now()}, nil
|
||||
}
|
||||
f.Changed = func(_ string, value json.RawMessage, deleted bool, at time.Time) {
|
||||
e := view.Entry{Bucket: view.SourceBucket, Key: esc, Deleted: deleted, At: at}
|
||||
if !deleted {
|
||||
var a meshdelivery.SourceAnswer
|
||||
if err := json.Unmarshal(value, &a); err != nil {
|
||||
s.logger.Printf("the source of %s is not taken: %v", branch, err)
|
||||
return
|
||||
}
|
||||
se, err := view.SourceEntry(branch, a)
|
||||
if err != nil {
|
||||
s.logger.Printf("the source of %s is not taken: %v", branch, err)
|
||||
return
|
||||
}
|
||||
se.At = at
|
||||
e = se
|
||||
}
|
||||
s.model.Apply(e)
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
// revisionOf is the source revision f holds of the branch, 0 when none.
|
||||
func revisionOf(f *views.Follower, esc string) int64 {
|
||||
raw, ok := f.Get(esc)
|
||||
if !ok {
|
||||
return 0
|
||||
}
|
||||
var a meshdelivery.SourceAnswer
|
||||
if json.Unmarshal(raw, &a) != nil {
|
||||
return 0
|
||||
}
|
||||
return a.Revision
|
||||
}
|
||||
|
||||
// hear is the handler of source-moved for one branch's view: another branch's event is not its own; a revision it does not
|
||||
// hold yet asks the first view again until it does, on its own goroutine, so the consumer is never held.
|
||||
func (s *branchSources) hear(branch string, f *views.Follower) func(context.Context, []byte) error {
|
||||
esc := keys.EscapeName(branch)
|
||||
return func(ctx context.Context, data []byte) error {
|
||||
var ev meshdelivery.SourceMovedEvent
|
||||
if err := json.Unmarshal(data, &ev); err != nil || ev.Branch == "" {
|
||||
return fmt.Errorf("not a %s event: %s", meshdelivery.EventSourceMoved, sourcebranches.ClipBytes(data))
|
||||
}
|
||||
if ev.Branch != branch && ev.Branch != esc {
|
||||
return nil
|
||||
}
|
||||
held := func() bool { return revisionOf(f, esc) >= ev.Revision }
|
||||
if held() {
|
||||
return nil
|
||||
}
|
||||
go sourcebranches.CatchUp(s.ctx, f, held, fmt.Sprintf("source of %s moved to %d", branch, ev.Revision))
|
||||
return nil
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user