B7 seat-holder-nodes: meshcatalogclient.Branches gains SeatHolderNodes, each holder of a seat with its module and its node
It reads the same followed seat-holders view as SeatHolders, through mesh-sdk's seatlist.HolderNodesIn, so the builder matches a returned event's node without reading the view's keys; the follow is made once for either. Builds: design 47 H2 H-A-742 (H-A-606)
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/sourcebranches"
|
||||
"git.novox.be/novox/mesh-sdk/go/busretry"
|
||||
"git.novox.be/novox/mesh-sdk/go/seatlist"
|
||||
"git.novox.be/novox/mesh-sdk/go/views"
|
||||
)
|
||||
|
||||
@@ -403,6 +404,7 @@ func TestSeatHoldersFollowsTheClaimantOfTheAssignerSeat(t *testing.T) {
|
||||
t.Fatalf("holders = %v, want %s", got, want)
|
||||
}
|
||||
}
|
||||
nodes := b.SeatHolderNodes(ctx) // the same followed view, each holder with its node (design 47 H2 H-A-742)
|
||||
main, _ := w.get("mesh-catalog.catalog-revisions.main")
|
||||
seats.mu.Lock()
|
||||
seats.trunk = claims(1, "asg-a")
|
||||
@@ -411,6 +413,9 @@ func TestSeatHoldersFollowsTheClaimantOfTheAssignerSeat(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
answered("asg-a", "node-tools")
|
||||
if got := nodes("node-tool-runner"); !slices.Equal(got, []seatlist.HolderNode{{Module: "node-tools", Node: "anchor"}}) {
|
||||
t.Fatalf("holder nodes = %v, want node-tools on anchor", got)
|
||||
}
|
||||
seats.mu.Lock()
|
||||
seats.trunk = claims(2, "asg-b")
|
||||
seats.mu.Unlock()
|
||||
|
||||
@@ -99,25 +99,43 @@ type seatHolders struct {
|
||||
// follows the new one's (§532); with no claimant it keeps what it has. Nothing is asked on a timer. The part's manifest consumes
|
||||
// `seat:mesh-module-assigner.views.seat-holders`. A Wiring that follows no plain view answers no holders, said in the log.
|
||||
func (b *Branches) SeatHolders(ctx context.Context) func(seat string) []string {
|
||||
sh := &seatHolders{kick: make(chan struct{}, 1)}
|
||||
b.holders.Store(sh)
|
||||
fw, ok := b.w.(viewFollowing)
|
||||
if !ok {
|
||||
b.logf("meshcatalogclient: this part's reader follows no plain view, so no seat's holders are known")
|
||||
} else {
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-sh.kick:
|
||||
}
|
||||
b.refollow(sh, fw)
|
||||
return seatlist.HoldersIn(b.followHolders(ctx))
|
||||
}
|
||||
|
||||
// SeatHolderNodes is SeatHolders answering each holder of a seat with its module and its node, over the same followed view's values
|
||||
// through seatlist.HolderNodesIn, so no module reads the view's keys itself (design 47 H2 H-A-742). It follows the view as
|
||||
// SeatHolders does: a part calls one of them, or both, and the view is followed once.
|
||||
func (b *Branches) SeatHolderNodes(ctx context.Context) func(seat string) []seatlist.HolderNode {
|
||||
return seatlist.HolderNodesIn(b.followHolders(ctx))
|
||||
}
|
||||
|
||||
// followHolders starts the follow of the claimant's seat-holders view, once, and is the view's values as it holds them now.
|
||||
func (b *Branches) followHolders(ctx context.Context) func() (map[string]json.RawMessage, error) {
|
||||
sh := b.holders.Load()
|
||||
if sh == nil {
|
||||
sh = &seatHolders{kick: make(chan struct{}, 1)}
|
||||
if !b.holders.CompareAndSwap(nil, sh) {
|
||||
sh = b.holders.Load()
|
||||
} else {
|
||||
fw, ok := b.w.(viewFollowing)
|
||||
if !ok {
|
||||
b.logf("meshcatalogclient: this part's reader follows no plain view, so no seat's holders are known")
|
||||
} else {
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-sh.kick:
|
||||
}
|
||||
b.refollow(sh, fw)
|
||||
}
|
||||
}()
|
||||
sh.changed()
|
||||
}
|
||||
}()
|
||||
sh.changed()
|
||||
}
|
||||
}
|
||||
return seatlist.HoldersIn(func() (map[string]json.RawMessage, error) {
|
||||
return func() (map[string]json.RawMessage, error) {
|
||||
sh.mu.Lock()
|
||||
values := sh.values
|
||||
sh.mu.Unlock()
|
||||
@@ -125,7 +143,7 @@ func (b *Branches) SeatHolders(ctx context.Context) func(seat string) []string {
|
||||
return nil, nil
|
||||
}
|
||||
return values(), nil
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// changed asks the follow to read the claimant again, without blocking the caller (a view's change is told under its lock).
|
||||
|
||||
Reference in New Issue
Block a user