Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6f8ba0bf69 | ||
|
|
5bca54bb59 |
@@ -93,6 +93,11 @@ type seatTools struct {
|
|||||||
// seats is the seat list the bundle reads (seatlist.go): until it is read, propose judges no mesh seat the bootstrapped
|
// seats is the seat list the bundle reads (seatlist.go): until it is read, propose judges no mesh seat the bootstrapped
|
||||||
// definitions do not name as held once (ADR 0636 §1). Nil reads nothing.
|
// definitions do not name as held once (ADR 0636 §1). Nil reads nothing.
|
||||||
seatList *seatlist.Part
|
seatList *seatlist.Part
|
||||||
|
// watched is the tools process's watched copy of the state seat-holders (tools.go wants.watched, which gate.Holders
|
||||||
|
// also reads: A-298), read by the verb assignments with seats instead of a bus get per key (issue 1982: under load
|
||||||
|
// that took about 14 s, where the watched copy answers at once). Nil, or a call it cannot answer, falls back to a
|
||||||
|
// direct listing.
|
||||||
|
watched *stdio.WatchedStates
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSeatTools(st seatStore, ask func(string, any) (json.RawMessage, error)) *seatTools {
|
func newSeatTools(st seatStore, ask func(string, any) (json.RawMessage, error)) *seatTools {
|
||||||
@@ -554,25 +559,43 @@ func (s *seatTools) tools() []stdio.Tool {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
// seats is the verb assignments with seats (ADR 0571 §4): who holds each seat and on which node, as the state seat-holders
|
// seatHolders is every key of the state seat-holders and its raw value: from the watched copy (s.watched) when
|
||||||
// holds it; with node, the keys of seats held on that node.
|
// there is one and it answers, else a direct listing, key by key, as the verb answered before (issue 1982).
|
||||||
func (s *seatTools) seats(node string) (any, error) {
|
func (s *seatTools) seatHolders() (map[string][]byte, error) {
|
||||||
|
if s.watched != nil {
|
||||||
|
if vals, err := s.watched.Values(mma.StateSeatHolders); err == nil {
|
||||||
|
return vals, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
keys, err := s.st.keys(mma.StateSeatHolders)
|
keys, err := s.st.keys(mma.StateSeatHolders)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("seat-holders cannot be listed: %w", err)
|
return nil, fmt.Errorf("seat-holders cannot be listed: %w", err)
|
||||||
}
|
}
|
||||||
sort.Strings(keys)
|
out := make(map[string][]byte, len(keys))
|
||||||
out := []mma.SeatHolders{}
|
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
raw, _, found, err := s.st.get(mma.StateSeatHolders, key)
|
raw, _, found, err := s.st.get(mma.StateSeatHolders, key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("seat-holders %s cannot be read: %w", key, err)
|
return nil, fmt.Errorf("seat-holders %s cannot be read: %w", key, err)
|
||||||
}
|
}
|
||||||
if !found {
|
if found {
|
||||||
continue
|
out[key] = raw
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// seats is the verb assignments with seats (ADR 0571 §4): who holds each seat and on which node, as the state seat-holders
|
||||||
|
// holds it; with node, the keys of seats held on that node.
|
||||||
|
func (s *seatTools) seats(node string) (any, error) {
|
||||||
|
raws, err := s.seatHolders()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
keys := slices.Sorted(maps.Keys(raws))
|
||||||
|
out := []mma.SeatHolders{}
|
||||||
|
for _, key := range keys {
|
||||||
var sh mma.SeatHolders
|
var sh mma.SeatHolders
|
||||||
if json.Unmarshal(raw, &sh) != nil {
|
if json.Unmarshal(raws[key], &sh) != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if node != "" && sh.Node != node && !slices.ContainsFunc(sh.Holders, func(h mma.SeatHoldersHoldersItem) bool { return h.Node == node }) {
|
if node != "" && sh.Node != node && !slices.ContainsFunc(sh.Holders, func(h mma.SeatHoldersHoldersItem) bool { return h.Node == node }) {
|
||||||
|
|||||||
@@ -352,6 +352,53 @@ func TestTheSeatsVerbs(t *testing.T) {
|
|||||||
t.Errorf("seats on ace = %+v, %v", out, err)
|
t.Errorf("seats on ace = %+v, %v", out, err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
t.Run("issue 1982: assignments with seats reads the tools process's watched copy of seat-holders, the store only while it cannot", func(t *testing.T) {
|
||||||
|
seeded := map[string][]byte{}
|
||||||
|
put := func(seat, node string, holders ...mma.SeatHoldersHoldersItem) {
|
||||||
|
raw, err := json.Marshal(mma.SeatHolders{Seat: seat, Node: node, Holders: holders})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
seeded[seat] = raw
|
||||||
|
}
|
||||||
|
put("mesh-broker", "", mma.SeatHoldersHoldersItem{Module: "nats", Node: "ace"})
|
||||||
|
put("node-shell.g14", "g14")
|
||||||
|
st := &countingSeatStore{memStore: memStore{mma.StateSeatHolders: &memKV{values: seeded}}}
|
||||||
|
sv := newSeatTools(st, nil)
|
||||||
|
watches := 0
|
||||||
|
sv.watched = stdio.WatchedStatesOver(func(state string, handle func(stdio.StateChange) error) error {
|
||||||
|
watches++
|
||||||
|
for k, v := range seeded {
|
||||||
|
if err := handle(stdio.StateChange{Key: k, Op: stdio.OpPut, Value: v, Current: true}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}, func(state, key string) ([]byte, bool, error) {
|
||||||
|
v, ok := seeded[key]
|
||||||
|
return v, ok, nil
|
||||||
|
})
|
||||||
|
out, err := sv.seats("")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got := out.(map[string]any)["seats"].([]mma.SeatHolders); len(got) != 2 || watches != 1 || st.keysCalls != 0 || st.getCalls != 0 {
|
||||||
|
t.Errorf("seats from the watched copy = %+v, watched %d time(s), the store's own keys %d get %d (want none)",
|
||||||
|
got, watches, st.keysCalls, st.getCalls)
|
||||||
|
}
|
||||||
|
// The lead's answer on issue 1982: the verb falls back to the store's own listing only while the watched copy
|
||||||
|
// cannot be read (here, its watch refused); the answer's form does not change.
|
||||||
|
sv.watched = stdio.WatchedStatesOver(func(string, func(stdio.StateChange) error) error {
|
||||||
|
return errors.New("refused")
|
||||||
|
}, func(state, key string) ([]byte, bool, error) { return nil, false, nil })
|
||||||
|
out, err = sv.seats("")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got := out.(map[string]any)["seats"].([]mma.SeatHolders); len(got) != 2 || st.keysCalls != 1 || st.getCalls != 2 {
|
||||||
|
t.Errorf("seats falling back to the store = %+v, the store's own keys %d get %d (want 1, 2)", got, st.keysCalls, st.getCalls)
|
||||||
|
}
|
||||||
|
})
|
||||||
t.Run("research 072 row 37: a node is written as its keys, and history reads the node key", func(t *testing.T) {
|
t.Run("research 072 row 37: a node is written as its keys, and history reads the node key", func(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
kv := &revKV{values: map[string][]byte{}, revs: map[string]uint64{}}
|
kv := &revKV{values: map[string][]byte{}, revs: map[string]uint64{}}
|
||||||
@@ -750,6 +797,23 @@ func readManifest() (catalogue.Manifest, error) {
|
|||||||
return catalogue.Decode(raw)
|
return catalogue.Decode(raw)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// countingSeatStore is a memStore that counts its calls to keys and get, to prove a reader takes the state from the
|
||||||
|
// watched copy and the store only while that copy cannot be read (issue 1982).
|
||||||
|
type countingSeatStore struct {
|
||||||
|
memStore
|
||||||
|
keysCalls, getCalls int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *countingSeatStore) keys(state string) ([]string, error) {
|
||||||
|
c.keysCalls++
|
||||||
|
return c.memStore.keys(state)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *countingSeatStore) get(state, key string) ([]byte, uint64, bool, error) {
|
||||||
|
c.getCalls++
|
||||||
|
return c.memStore.get(state, key)
|
||||||
|
}
|
||||||
|
|
||||||
// countingKV is a memKV that counts its puts.
|
// countingKV is a memKV that counts its puts.
|
||||||
type countingKV struct {
|
type countingKV struct {
|
||||||
memKV
|
memKV
|
||||||
|
|||||||
@@ -419,6 +419,8 @@ func serveTools() error {
|
|||||||
wants.watched = stdio.NewWatchedStates() // the large states read whole from one watched copy (ADR 0580 clause 3)
|
wants.watched = stdio.NewWatchedStates() // the large states read whole from one watched copy (ADR 0580 clause 3)
|
||||||
// The callers' seat entries are resolved from the assigner's own seat-holders, its watched copy (A-298).
|
// The callers' seat entries are resolved from the assigner's own seat-holders, its watched copy (A-298).
|
||||||
gate.Holders(seatlist.HoldersIn(func() (map[string][]byte, error) { return wants.watched.Values(mma.StateSeatHolders) }))
|
gate.Holders(seatlist.HoldersIn(func() (map[string][]byte, error) { return wants.watched.Values(mma.StateSeatHolders) }))
|
||||||
|
// The verb assignments with seats answers from the same watched copy, so every caller of it is fast too (issue 1982).
|
||||||
|
seatVerbs.watched = wants.watched
|
||||||
wants.revisions = runtimeObjects{busstate.ObjectsOf(assigngraph.RevisionsObjects)}
|
wants.revisions = runtimeObjects{busstate.ObjectsOf(assigngraph.RevisionsObjects)}
|
||||||
tools = append(tools, wants.tools()...)
|
tools = append(tools, wants.tools()...)
|
||||||
keeper := &inputKeeper{vals: stateobjects.ForState(buckets.InputsState), now: time.Now, logf: func(string, ...any) {}}
|
keeper := &inputKeeper{vals: stateobjects.ForState(buckets.InputsState), now: time.Now, logf: func(string, ...any) {}}
|
||||||
|
|||||||
Reference in New Issue
Block a user