I6 (2b): the indexer keeps the seat list as one object and hands it by seat-list
At each trunk seat-definition move (said or not) the indexer writes the trunk's definitions, resolved, as one JSON array sorted by seat into its objects seat-lists under its sha256, when not held, and deletes every object but the newest two, never the one just kept; one journal line per write and delete. Its process serves the chunked verb seat-list: digest, size and chunks, then the object's bytes; a list not kept yet is refused naming it. The manifest serves seat-list and declares seat-lists in its old objects section at 64 MiB. composer.Request gains seat-list, the digest of the bytes Seats were filled from; the judge reads Seats alone. Builds: design 47 H2 §814, §820; H-A-441, H-A-443 (1)
This commit is contained in:
@@ -318,13 +318,16 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
seatDefs := process.AwaitBucket(ctx, js, conn, index.Bucket(cred.Module, index.SeatDefinitionsState), "no seat definition is kept", logger.Printf)
|
||||
marks := process.AwaitBucket(ctx, js, conn, index.Bucket(cred.Module, views.MarksState), "no change is said on the views family, so every reader waits on its first view", logger.Printf)
|
||||
seatBus := &seatBus{defs: awaitedSource{ctx, seatDefs}, marks: awaitedSource{ctx, marks}}
|
||||
// The seat lists, one object per digest (design 47 H2 §814, §820; H-A-441, H-A-443), kept at each trunk definition's move
|
||||
// and handed by the verb seat-list.
|
||||
seatLists := newBusObjects(js, cred, index.SeatListsObjects)
|
||||
// The build modules are found again at every change of the seat list (buildmodules.go), once the indexer is made.
|
||||
var buildFollow atomic.Pointer[buildModulesFollow]
|
||||
seatReader, saySeats := followSeatList(seatBus, saySeatDefinition(js, cred), logger.Printf, func() {
|
||||
if b := buildFollow.Load(); b != nil {
|
||||
go b.refresh() // never inside the reader's change: the refresh reads the reader's definitions
|
||||
}
|
||||
})
|
||||
}, seatLists)
|
||||
readWhenBound(seatReader, seatDefs, marks)
|
||||
var fillFollow atomic.Pointer[versionsFill]
|
||||
// Kept while named (design 47 G §675): the want and the running build that name a fingerprint, heard below.
|
||||
@@ -336,9 +339,10 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
inputsStore := awaitedStore{b: process.AwaitBucket(ctx, js, conn, index.Bucket(cred.Module, index.InputsState), "no input of a run ask is kept, so the verb input answers none", logger.Printf)}
|
||||
inObjects := &inputObjects{js: js, module: cred.Module}
|
||||
stopInput, err := calls.AnswerSeat(meshcatalog.Seat, seatlist.Definition(seatReader.Reader, meshcatalog.Seat), map[string]process.SeatHandler{
|
||||
meshcatalog.VerbInput: index.InputVerb(inputsStore, inObjects, conn, buscalls.SeatAckWithin, logger.Printf)})
|
||||
meshcatalog.VerbInput: index.InputVerb(inputsStore, inObjects, conn, buscalls.SeatAckWithin, logger.Printf),
|
||||
meshcatalog.VerbSeatList: index.SeatListVerb(seatBus.defs, seatLists, conn, buscalls.SeatAckWithin, logger.Printf)})
|
||||
if err != nil {
|
||||
return fmt.Errorf("answering the verb input: %w", err)
|
||||
return fmt.Errorf("answering the verbs input and seat-list: %w", err)
|
||||
}
|
||||
defer stopInput()
|
||||
// The state takeins: hand acts ask there (watched below), and a running take-in keeps what it waits on (H2 §803, H-A-409).
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
"git.novox.be/novox/mesh-sdk/go/views"
|
||||
@@ -109,6 +110,28 @@ func (b *busObjects) Names(ctx context.Context) ([]string, error) {
|
||||
return names, nil
|
||||
}
|
||||
|
||||
// List is every object the store holds, a deleted one left out (index.SeatLists).
|
||||
func (b *busObjects) List(ctx context.Context) ([]buscalls.ObjectInfo, error) {
|
||||
o, err := b.open(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
infos, err := o.List(ctx)
|
||||
if errors.Is(err, jetstream.ErrNoObjectsFound) {
|
||||
return []buscalls.ObjectInfo{}, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make([]buscalls.ObjectInfo, 0, len(infos))
|
||||
for _, i := range infos {
|
||||
if !i.Deleted {
|
||||
out = append(out, buscalls.ObjectInfo{Name: i.Name, Size: i.Size, Chunks: i.Chunks, Digest: i.Digest, Modified: i.ModTime})
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (b *busObjects) Fill(ctx context.Context) (int64, int64, error) {
|
||||
o, err := b.open(ctx)
|
||||
if err != nil {
|
||||
|
||||
@@ -110,18 +110,26 @@ func (b *seatBus) said(c index.SeatDefinitionChanged) {
|
||||
// seatlist.Part, novox/hq ADR 0636 §7), which gives catalogue what it holds at every change, and wraps say so that each move
|
||||
// the indexer says is also heard by the reader. Its two tools are not served: the indexer's process serves no request
|
||||
// subject (ADR 0437 §4), and its list is its own state seat-definitions, which indexer_seat_definition and the seat's verb
|
||||
// seat-definitions read. It returns the part, whose status the indexer's health can show.
|
||||
func followSeatList(bus *seatBus, say func(context.Context, index.SeatDefinitionChanged) error, logf func(string, ...any), changed func()) (*seatlist.Part, func(context.Context, index.SeatDefinitionChanged) error) {
|
||||
// seat-definitions read. It returns the part, whose status the indexer's health can show. At each trunk definition's move,
|
||||
// said or not, the seat list is kept as one object in lists, the objects seat-lists (design 47 H2 §814, §820, H-A-441), a
|
||||
// failure said in logf.
|
||||
func followSeatList(bus *seatBus, say func(context.Context, index.SeatDefinitionChanged) error, logf func(string, ...any), changed func(), lists index.SeatLists) (*seatlist.Part, func(context.Context, index.SeatDefinitionChanged) error) {
|
||||
part := seatlist.NewPart(toolPrefix)
|
||||
part.Follow(bus, changed, logf)
|
||||
return part, func(ctx context.Context, c index.SeatDefinitionChanged) error {
|
||||
if err := say(ctx, c); err != nil {
|
||||
return err
|
||||
if c.Source != index.SourceTrunk { // only a trunk's definition is the seat list's
|
||||
return say(ctx, c)
|
||||
}
|
||||
if c.Source == index.SourceTrunk { // only a trunk's definition is the seat list's
|
||||
err := say(ctx, c)
|
||||
if err == nil {
|
||||
bus.said(c)
|
||||
}
|
||||
return nil
|
||||
if lists != nil {
|
||||
if _, kerr := index.KeepSeatList(ctx, bus.defs, lists, logf); kerr != nil {
|
||||
logf("the seat list is not kept in %s after %s moved: %v", index.SeatListsObjects, c.Seat, kerr)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -10,6 +13,8 @@ import (
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/seatlist"
|
||||
"git.novox.be/novox/mesh-sdk/go/views"
|
||||
|
||||
"mesh-delivery-indexer/internal/index"
|
||||
)
|
||||
|
||||
type unboundSource struct {
|
||||
@@ -44,7 +49,17 @@ func (b *awaitedFake) Ready(f func(jetstream.KeyValue)) { b.ready = append(b.rea
|
||||
func TestTheSeatListIsReadAgainWhenItsStatesAreBound(t *testing.T) {
|
||||
src := &unboundSource{}
|
||||
bus := &seatBus{defs: src, marks: src}
|
||||
part, _ := followSeatList(bus, nil, t.Logf, nil)
|
||||
var mu sync.Mutex
|
||||
var unkept []string
|
||||
logf := func(f string, a ...any) {
|
||||
t.Logf(f, a...)
|
||||
if strings.HasPrefix(f, "the seat list is not kept") {
|
||||
mu.Lock()
|
||||
unkept = append(unkept, fmt.Sprintf(f, a...))
|
||||
mu.Unlock()
|
||||
}
|
||||
}
|
||||
part, say := followSeatList(bus, func(context.Context, index.SeatDefinitionChanged) error { return nil }, logf, nil, &busObjects{})
|
||||
reader := part.Reader()
|
||||
<-reader.Ready()
|
||||
if reader.Status().Heard {
|
||||
@@ -76,5 +91,14 @@ func TestTheSeatListIsReadAgainWhenItsStatesAreBound(t *testing.T) {
|
||||
if _, ok := seatlist.Definition(part.Reader, "no-such-seat")(); ok {
|
||||
t.Error("a seat the list does not hold is answered a definition")
|
||||
}
|
||||
// Design 47 H2 §814 (H-A-441): a trunk definition's move keeps the seat list in seat-lists, a pull request's does not; here
|
||||
// the list holds no definition, so the keeping is refused and said.
|
||||
_ = say(context.Background(), index.SeatDefinitionChanged{Seat: "a", Source: "pull-7", Digest: "d"})
|
||||
_ = say(context.Background(), index.SeatDefinitionChanged{Seat: "a", Source: index.SourceTrunk, Digest: "d"})
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if len(unkept) != 1 || !strings.Contains(unkept[0], "holds no trunk definition") {
|
||||
t.Errorf("the moves kept the seat list as %q, want one try, for the trunk's", unkept)
|
||||
}
|
||||
var _ seatlist.Bus = bus
|
||||
}
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
package index
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
||||
"git.novox.be/novox/mesh-sdk/go/views"
|
||||
)
|
||||
|
||||
// The seat list as one object (design 47 H2 §814, §820; H-A-441): the trunk's seat definitions, resolved with their
|
||||
// includes, as one JSON array in composer.Request.Seats' form sorted by seat, kept in the indexer's objects seat-lists
|
||||
// under its digest (the sha256 of those bytes), written at each trunk seat-definition-changed or -removed; every object
|
||||
// but the newest two is deleted at each new list. The seat mesh-catalog's verb seat-list hands its digest, size and bytes, and
|
||||
// a validate run's asker fills its request's seats from them, so every run of one seat list judges the same bytes.
|
||||
|
||||
// SeatListsObjects is the indexer's objects store of seat lists, in its old objects section (a foundation part, ADR 0619
|
||||
// §2): 64 MiB, one object per digest.
|
||||
const SeatListsObjects = "seat-lists"
|
||||
|
||||
// seatListsKept is how many seat lists the objects keep: the newest two.
|
||||
const seatListsKept = 2
|
||||
|
||||
// SeatLists is the objects seat-lists as the indexer's process reaches them, to write, prune and hand out.
|
||||
type SeatLists interface {
|
||||
// Put stores data whole under name, replacing one of that name.
|
||||
Put(ctx context.Context, name string, data []byte) error
|
||||
// Get is the object's bytes; ErrNoObject when it holds none of that name.
|
||||
Get(ctx context.Context, name string) ([]byte, error)
|
||||
// Delete removes the object; one it does not hold is no error.
|
||||
Delete(ctx context.Context, name string) error
|
||||
// List is every object the store holds, a deleted one left out.
|
||||
List(ctx context.Context) ([]buscalls.ObjectInfo, error)
|
||||
}
|
||||
|
||||
// SeatListOf is the trunk's seat list as the object holds it, and its digest: each trunk definition resolved, in the
|
||||
// order of its seat's name. A list with no seat is an error: no validator judges by an empty list.
|
||||
func SeatListOf(defs views.Source) ([]byte, string, error) {
|
||||
keys, err := defs.Keys()
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("the %s state cannot be listed: %w", SeatDefinitionsState, err)
|
||||
}
|
||||
type seatDef struct {
|
||||
seat string
|
||||
def json.RawMessage
|
||||
}
|
||||
var seats []seatDef
|
||||
for _, key := range keys {
|
||||
seat, ok := strings.CutSuffix(key, "."+SourceTrunk)
|
||||
if !ok || strings.HasPrefix(key, outOfStepPrefix) {
|
||||
continue
|
||||
}
|
||||
v, ok, err := defs.Get(key)
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("%s.%s cannot be read: %w", SeatDefinitionsState, key, err)
|
||||
}
|
||||
if !ok || v == nil {
|
||||
continue
|
||||
}
|
||||
var e SeatDefinitionEntry
|
||||
if err := json.Unmarshal(v.Value, &e); err != nil || e.Digest == "" || len(e.Definition) == 0 {
|
||||
continue // an entry that holds no definition is no seat of the list
|
||||
}
|
||||
seats = append(seats, seatDef{seat, e.Definition})
|
||||
}
|
||||
slices.SortFunc(seats, func(a, b seatDef) int { return strings.Compare(a.seat, b.seat) })
|
||||
list := make([]json.RawMessage, 0, len(seats))
|
||||
for _, s := range seats {
|
||||
list = append(list, s.def)
|
||||
}
|
||||
if len(list) == 0 {
|
||||
return nil, "", fmt.Errorf("the %s state holds no trunk definition, so there is no seat list", SeatDefinitionsState)
|
||||
}
|
||||
raw, err := json.Marshal(list)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
sum := sha256.Sum256(raw)
|
||||
return raw, hex.EncodeToString(sum[:]), nil
|
||||
}
|
||||
|
||||
// KeepSeatList writes the trunk's seat list into seat-lists under its digest when the objects do not hold it, then deletes
|
||||
// every object but the newest two, never the list just kept. It answers the list's digest; each write and each delete is
|
||||
// one line in logf.
|
||||
func KeepSeatList(ctx context.Context, defs views.Source, o SeatLists, logf func(string, ...any)) (string, error) {
|
||||
raw, digest, err := SeatListOf(defs)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
held, err := o.List(ctx)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("the objects %s cannot be listed: %w", SeatListsObjects, err)
|
||||
}
|
||||
if !slices.ContainsFunc(held, func(i buscalls.ObjectInfo) bool { return i.Name == digest }) {
|
||||
if err := o.Put(ctx, digest, raw); err != nil {
|
||||
return "", fmt.Errorf("the seat list %s cannot be kept in %s: %w", digest, SeatListsObjects, err)
|
||||
}
|
||||
logf("seat list %s kept in %s (%d bytes)", digest, SeatListsObjects, len(raw))
|
||||
if held, err = o.List(ctx); err != nil {
|
||||
return digest, fmt.Errorf("the objects %s cannot be listed: %w", SeatListsObjects, err)
|
||||
}
|
||||
}
|
||||
slices.SortFunc(held, func(a, b buscalls.ObjectInfo) int { return b.Modified.Compare(a.Modified) }) // newest first
|
||||
kept := 0
|
||||
for _, i := range held {
|
||||
if i.Name == digest || kept < seatListsKept {
|
||||
kept++
|
||||
continue
|
||||
}
|
||||
if err := o.Delete(ctx, i.Name); err != nil {
|
||||
return digest, fmt.Errorf("the seat list %s cannot be deleted from %s: %w", i.Name, SeatListsObjects, err)
|
||||
}
|
||||
logf("seat list %s deleted from %s: only the newest %d are kept", i.Name, SeatListsObjects, seatListsKept)
|
||||
}
|
||||
return digest, nil
|
||||
}
|
||||
|
||||
// SeatListVerb is the seat mesh-catalog's verb seat-list, served by the indexer's process (H-A-443: the owner hands its
|
||||
// objects, ADR 0596): the trunk's seat list's digest and size, then the bytes of its object in seat-lists in chunks of at
|
||||
// most buscalls.SeatChunkBytes on the call's chunk subjects, each acknowledged before the next. A list the objects do not
|
||||
// hold yet is refused naming it, never answered with other bytes. A caller that does not acknowledge within within ends
|
||||
// the send, said in logf.
|
||||
func SeatListVerb(defs views.Source, o SeatLists, line buscalls.ChunkLine, within time.Duration, logf func(string, ...any)) func(caller string, body json.RawMessage) (any, error) {
|
||||
return func(_ string, raw json.RawMessage) (any, error) {
|
||||
var in meshcatalog.SeatListInput
|
||||
if err := json.Unmarshal(raw, &in); err != nil {
|
||||
return nil, fmt.Errorf("the arguments are not JSON: %w", err)
|
||||
}
|
||||
if !callToken.MatchString(in.Call) {
|
||||
return nil, errors.New("call is one token of 16 to 64 letters, digits, - or _: 128 random bits the caller chooses")
|
||||
}
|
||||
ctx := context.Background()
|
||||
_, digest, err := SeatListOf(defs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
body, err := o.Get(ctx, digest)
|
||||
if errors.Is(err, ErrNoObject) {
|
||||
return nil, fmt.Errorf("the seat list %s is not kept in %s yet: it is written at the trunk's next seat-definition change", digest, SeatListsObjects)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the seat list %s cannot be read from %s: %w", digest, SeatListsObjects, err)
|
||||
}
|
||||
send := buscalls.SeatChunks{Seat: meshcatalog.Seat, Verb: meshcatalog.VerbSeatList, Call: in.Call}
|
||||
total := int64((len(body) + buscalls.SeatChunkBytes - 1) / buscalls.SeatChunkBytes)
|
||||
go func() { // the send subscribes to the acknowledgements itself and ends when every chunk is sent or one is not acknowledged
|
||||
if err := send.Send(line, body, within, logf); err != nil {
|
||||
logf("the send %s of the seat list %s: %v", in.Call, digest, err)
|
||||
}
|
||||
}()
|
||||
return meshcatalog.SeatListAnswer{Digest: digest, Size: int64(len(body)), Chunks: total}, nil
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package index
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/nats-io/nats.go"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
||||
"git.novox.be/novox/mesh-sdk/go/views"
|
||||
)
|
||||
|
||||
// memSeatLists is seat-lists in memory; each put is a second newer than the last.
|
||||
type memSeatLists struct {
|
||||
objects map[string][]byte
|
||||
at map[string]time.Time
|
||||
clock time.Time
|
||||
}
|
||||
|
||||
func (m *memSeatLists) Put(_ context.Context, name string, data []byte) error {
|
||||
m.clock = m.clock.Add(time.Second)
|
||||
m.objects[name], m.at[name] = data, m.clock
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *memSeatLists) Get(_ context.Context, name string) ([]byte, error) {
|
||||
d, ok := m.objects[name]
|
||||
if !ok {
|
||||
return nil, ErrNoObject
|
||||
}
|
||||
return d, nil
|
||||
}
|
||||
|
||||
func (m *memSeatLists) Delete(_ context.Context, name string) error {
|
||||
delete(m.objects, name)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *memSeatLists) List(context.Context) ([]buscalls.ObjectInfo, error) {
|
||||
out := []buscalls.ObjectInfo{}
|
||||
for n, d := range m.objects {
|
||||
out = append(out, buscalls.ObjectInfo{Name: n, Size: uint64(len(d)), Modified: m.at[n]})
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (m *memSeatLists) names() []string {
|
||||
var out []string
|
||||
for n := range m.objects {
|
||||
out = append(out, n)
|
||||
}
|
||||
slices.Sort(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// noLine is a chunk line that hears nothing, so a send ends at once, said.
|
||||
type noLine struct{}
|
||||
|
||||
func (noLine) Publish(string, []byte) error { return nil }
|
||||
func (noLine) Subscribe(string, nats.MsgHandler) (*nats.Subscription, error) {
|
||||
return nil, errors.New("no bus in this test")
|
||||
}
|
||||
|
||||
// Design 47 H2 §814, §820 (H-A-441, H-A-443): the trunk's seat list is one object of seat-lists named by its sha256, in the
|
||||
// order of its seats, kept at each new list with the newest two, and handed by the verb seat-list.
|
||||
func TestTheSeatListIsOneObjectByItsDigest(t *testing.T) {
|
||||
entry := func(seat, source, def string) *views.Entry {
|
||||
raw, _ := json.Marshal(SeatDefinitionEntry{Seat: seat, Source: source, Digest: "d-" + seat, Definition: json.RawMessage(def)})
|
||||
return &views.Entry{Value: raw}
|
||||
}
|
||||
defs := memSource{
|
||||
SeatDefinitionKey("a-b"): entry("a-b", SourceTrunk, `{"seat":"a-b"}`),
|
||||
SeatDefinitionKey("a"): entry("a", SourceTrunk, `{"seat":"a"}`),
|
||||
"a.pull-7": entry("a", "pull-7", `{"seat":"a","pull":7}`),
|
||||
outOfStepPrefix + "c." + SourceTrunk: entry("c", SourceTrunk, `{"seat":"c"}`),
|
||||
}
|
||||
want := `[{"seat":"a"},{"seat":"a-b"}]` // by seat, not by key: "a-b.trunk" sorts before "a.trunk"
|
||||
sum := sha256.Sum256([]byte(want))
|
||||
digest := hex.EncodeToString(sum[:])
|
||||
raw, got, err := SeatListOf(defs)
|
||||
if err != nil || string(raw) != want || got != digest {
|
||||
t.Fatalf("SeatListOf = %s %s (%v), want %s %s", raw, got, err, want, digest)
|
||||
}
|
||||
if _, _, err := SeatListOf(memSource{}); err == nil {
|
||||
t.Error("an empty seat list was given a digest")
|
||||
}
|
||||
|
||||
lists := &memSeatLists{objects: map[string][]byte{}, at: map[string]time.Time{}}
|
||||
verb := SeatListVerb(defs, lists, noLine{}, time.Second, t.Logf)
|
||||
if _, err := verb("", json.RawMessage(`{"call":"0123456789abcdef0123456789abcdef"}`)); err == nil || !strings.Contains(err.Error(), "not kept in seat-lists yet") {
|
||||
t.Errorf("a list not kept yet was answered: %v", err)
|
||||
}
|
||||
for _, old := range []string{"old-1", "old-2", "old-3"} {
|
||||
_ = lists.Put(context.Background(), old, []byte("[]"))
|
||||
}
|
||||
if d, err := KeepSeatList(context.Background(), defs, lists, t.Logf); err != nil || d != digest {
|
||||
t.Fatalf("KeepSeatList = %s (%v), want %s", d, err, digest)
|
||||
}
|
||||
if names := lists.names(); !slices.Equal(names, []string{digest, "old-3"}) || string(lists.objects[digest]) != want {
|
||||
t.Errorf("seat-lists holds %v, want the list kept and the newest other", names)
|
||||
}
|
||||
before := lists.at[digest]
|
||||
if _, err := KeepSeatList(context.Background(), defs, lists, t.Logf); err != nil || !lists.at[digest].Equal(before) || len(lists.objects) != 2 {
|
||||
t.Errorf("the same list kept again was written again, or another deleted: %v %v", lists.names(), err)
|
||||
}
|
||||
|
||||
if _, err := verb("", json.RawMessage(`{"call":"x"}`)); err == nil || !strings.Contains(err.Error(), "128 random bits") {
|
||||
t.Errorf("a call that is no token was taken: %v", err)
|
||||
}
|
||||
a, err := verb("", json.RawMessage(`{"call":"0123456789abcdef0123456789abcdef"}`))
|
||||
if err != nil || a != (meshcatalog.SeatListAnswer{Digest: digest, Size: int64(len(want)), Chunks: 1}) {
|
||||
t.Errorf("seat-list = %+v (%v), want its digest, size and one chunk", a, err)
|
||||
}
|
||||
}
|
||||
@@ -149,9 +149,11 @@ func TestManifestDeclarations(t *testing.T) { // 1238/AC1, 1444 (reads the build
|
||||
// capped at 512 MiB, under the local name the indexer opens. W4.14 (design 47, Reverted): their form is 1. Design 47 H
|
||||
// §742 (H-A-105): no catch-up tool of the indexer's follows a restore, indexer_take_in having gone with the builder-log
|
||||
// index; the gate's gate_head_take is the one hand take of a head.
|
||||
if len(m.Objects) != 1 || m.Objects[0].Name != index.CatalogRevisionsObjects || m.Objects[0].MaxMiB != 512 ||
|
||||
m.Objects[0].Form != 1 || m.Objects[0].CatchUp != "" {
|
||||
t.Errorf("objects = %+v, want %s capped at 512 MiB, form 1, no catch-up tool", m.Objects, index.CatalogRevisionsObjects)
|
||||
// Design 47 H2 §814, §820 (H-A-441): the seat lists, one object per digest, 64 MiB, in the old section too.
|
||||
if len(m.Objects) != 2 || m.Objects[0].Name != index.CatalogRevisionsObjects || m.Objects[0].MaxMiB != 512 ||
|
||||
m.Objects[0].Form != 1 || m.Objects[0].CatchUp != "" || m.Objects[1].Name != index.SeatListsObjects || m.Objects[1].MaxMiB != 64 {
|
||||
t.Errorf("objects = %+v, want %s capped at 512 MiB, form 1, no catch-up tool, and %s at 64 MiB", m.Objects,
|
||||
index.CatalogRevisionsObjects, index.SeatListsObjects)
|
||||
}
|
||||
// D-11 (ADR 0634 §1): the holders and buckets the indexer names (internal/index/names.go) are its manifest's: its own
|
||||
// name and states with their revisions, and the states it reads, each as `<holder>.<state>`.
|
||||
@@ -306,8 +308,8 @@ func TestManifestDeclarations(t *testing.T) { // 1238/AC1, 1444 (reads the build
|
||||
// ADR 0604 §2, ADR 0636 §4: it holds the seat mesh-catalog, serving its four verbs and seat-definitions from its tools
|
||||
// bundle (which stays without a request subject); ADR 0663 §1: and revision, in the same runtime of its own.
|
||||
if len(m.Claims) != 1 || m.Claims[0].Name != index.CatalogSeat || m.Claims[0].Scope != catalogue.ScopeMesh ||
|
||||
!slices.Equal(m.Claims[0].Serves, []string{"modules", "module", "provides", "dependents", index.SeatDefinitionsVerb, "revision", "entry", "registrations", "register", "policy", "watch", "unwatch", "versions", "outdated", "input"}) {
|
||||
t.Errorf("claims = %+v, want mesh-catalog with its seven verbs (entry: design 47 G §675)", m.Claims)
|
||||
!slices.Equal(m.Claims[0].Serves, []string{"modules", "module", "provides", "dependents", index.SeatDefinitionsVerb, "seat-list", "revision", "entry", "registrations", "register", "policy", "watch", "unwatch", "versions", "outdated", "input"}) {
|
||||
t.Errorf("claims = %+v, want mesh-catalog with its verbs (entry: design 47 G §675; seat-list: H2 §814)", m.Claims)
|
||||
}
|
||||
for _, e := range []string{index.SeatDefinitionChangedEvent, index.SeatDefinitionRemovedEvent} {
|
||||
if slices.Contains(m.Emits, e) {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
"provides",
|
||||
"dependents",
|
||||
"seat-definitions",
|
||||
"seat-list",
|
||||
"revision",
|
||||
"entry",
|
||||
"registrations",
|
||||
@@ -147,7 +148,8 @@
|
||||
{ "name": "mesh-delivery-indexer-findings", "events": ["finding-written.*", "finding-cleared.*", "findings-stated.*"], "max-age-days": 7, "max-mib": 16 }
|
||||
],
|
||||
"objects": [
|
||||
{ "name": "catalog-revisions", "max-mib": 512, "form": 1 }
|
||||
{ "name": "catalog-revisions", "max-mib": 512, "form": 1 },
|
||||
{ "name": "seat-lists", "max-mib": 64 }
|
||||
],
|
||||
"emits": [
|
||||
"take-in.pending",
|
||||
|
||||
@@ -67,6 +67,10 @@ type Request struct {
|
||||
// them (the definitions of the seat mesh-catalog, resolved), raw so that this package names no seat (ADR 0635 §4, ADR 0636
|
||||
// §1). The judge and the composer read them. None is no list at hand: a composer handed none judges no machine (ADR 0636 §1).
|
||||
Seats []json.RawMessage `json:"seats,omitempty"`
|
||||
// SeatList is the sha256 of the bytes Seats were filled from: the object of the seat mesh-catalog's seat-list, or a
|
||||
// revision's own definitions in the same form (design 47 H2 §814; H-A-441, H-A-443), so a verdict says which seat list
|
||||
// judged it. The asker fetches the bytes and fills Seats before the run; the judge reads Seats alone. Empty is none named.
|
||||
SeatList string `json:"seat-list,omitempty"`
|
||||
// BlameTries bounds the composer's search for the modules a machine that does not compose blames: it composes at
|
||||
// most this many times more, the assigner's setting blame-tries, since the composer has no settings of its own
|
||||
// (design 47 G §721, §729; A-469i). None is no search: the composer blames only what its composition holds or
|
||||
|
||||
@@ -63,6 +63,11 @@ func TestAManifestIsItsBytesOrItsDigest(t *testing.T) {
|
||||
if back, derr := Decode(wire); err != nil || derr != nil || back.BlameTries != 20 || !strings.Contains(string(wire), `"blame_tries":20`) {
|
||||
t.Errorf("blame_tries 20 went as %s and read back %d (%v, %v)", wire, back.BlameTries, err, derr)
|
||||
}
|
||||
// Design 47 H2 §814 (H-A-441): the seat list a request's seats were filled from reads back by its digest.
|
||||
wire, err = json.Marshal(Request{V: Version, SeatList: "0123abcd"})
|
||||
if back, derr := Decode(wire); err != nil || derr != nil || back.SeatList != "0123abcd" || !strings.Contains(string(wire), `"seat-list":"0123abcd"`) {
|
||||
t.Errorf("seat-list went as %s and read back %q (%v, %v)", wire, back.SeatList, err, derr)
|
||||
}
|
||||
// H3 (design 47 G A-470j, A-470k): a case's none, each module the revision gives no fingerprint with its none words,
|
||||
// reads back whole; a case naming none leaves the field off the wire.
|
||||
wire, err = json.Marshal(Request{V: Version, Cases: []Case{{Name: "change", Manifests: map[string]Manifest{},
|
||||
|
||||
Reference in New Issue
Block a user