H-A-290: the builder's publish queue sends live publishes first, in passes, never a withdrawn build
The tool runner's release waited forty minutes behind old versions: every start asked a publish again for every done build, and each send relisted and reread the whole queue. A publish whose build ended in this run now goes before any asked again at a start (the class kept on the key's value, a live key of a build before the start made a start key at the start); a pass lists a holder's keys once and sends them four at a time; a withdrawn or taken-over build is dropped with its publish item ended at enqueue, at the pass and at the start; a send that returns unsent says why, and every call it makes honours its one bound; builder_publish_queue reads its states in pages and answers counts per holder and class, the oldest and newest queue time, a list capped at fifty and one module's items with their class. Builds: design 47 H H-A-290 (1)-(5), H-A-269, H-A-271, H-A-275
This commit is contained in:
@@ -14,7 +14,8 @@ import (
|
||||
"mesh-delivery-builder/internal/versions"
|
||||
)
|
||||
|
||||
// readerOf is a kept state as the versions package's reader.
|
||||
// readerOf is a kept state as the versions package's reader: every value read in its pages, one request for many (design 47 H
|
||||
// H-A-290 (5)), where a key-by-key read of a queue of two thousand keys outlasts the tool's call.
|
||||
func readerOf(s stdio.KeptState) versions.Reader {
|
||||
return versions.Reader{Keys: s.Keys, Get: func(key string) (json.RawMessage, bool, error) {
|
||||
e, err := s.Get(key)
|
||||
@@ -22,7 +23,31 @@ func readerOf(s stdio.KeptState) versions.Reader {
|
||||
return nil, false, err
|
||||
}
|
||||
return e.Value, true, nil
|
||||
}}
|
||||
}, All: func() (map[string]json.RawMessage, error) { return allPages(s.Page) }}
|
||||
}
|
||||
|
||||
// statePageBytes and statePageBudget bound one page of a whole state read, so its answer fits one bus message and its time.
|
||||
const (
|
||||
statePageBytes = 768 * 1024
|
||||
statePageBudget = 10 * time.Second
|
||||
)
|
||||
|
||||
// allPages is every key's value of a state, page after page; a runtime that answers no page says errors.ErrUnsupported.
|
||||
func allPages(page func(after string, maxBytes int, budget time.Duration) (stdio.StatePage, error)) (map[string]json.RawMessage, error) {
|
||||
out := map[string]json.RawMessage{}
|
||||
for after := ""; ; {
|
||||
pg, err := page(after, statePageBytes, statePageBudget)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, e := range pg.Entries {
|
||||
out[e.Key] = e.Value
|
||||
}
|
||||
if pg.Next == "" || pg.Next == after {
|
||||
return out, nil
|
||||
}
|
||||
after = pg.Next
|
||||
}
|
||||
}
|
||||
|
||||
// republishTools are builder_publish_again and builder_publish_queue (design 47 G §588). The publish again is a hand act:
|
||||
@@ -59,7 +84,11 @@ func republishTools(queue, acted, reasks versions.Reader, ask queueAsker, now fu
|
||||
return map[string]any{"key": key, "queued": a.Queued, "answer": a.Answer}, nil
|
||||
}},
|
||||
{Name: versions.PublishQueueTool, Description: versions.PublishQueueDescription,
|
||||
Input: map[string]any{"type": "object", "properties": map[string]any{}},
|
||||
Run: func(map[string]any) (any, error) { return versions.AnswerQueue(queue, acted, reasks) }},
|
||||
Input: map[string]any{"type": "object", "properties": map[string]any{
|
||||
"module": map[string]any{"type": "string", "description": "list only this module's queued versions, each with its class"},
|
||||
"version": map[string]any{"type": "string", "description": "with module: only this version, MAJOR.MINOR.PATCH"}}},
|
||||
Run: func(args map[string]any) (any, error) {
|
||||
return versions.AnswerQueue(queue, acted, reasks, str(args, "module"), str(args, "version"))
|
||||
}},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,7 +261,8 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
republish := &versions.Republisher{Reserved: reserved.r, Queue: awaitedQueue{awaitedReserved{awaitedVersions{b: queueKV, bucket: own.queue}}},
|
||||
Entry: entryVia(calls.Call), Send: sendVia(calls.Call),
|
||||
Unreleased: reserved.unreleasedWords, Logf: logger.Printf,
|
||||
Holders: holders} // a registry seat's holder from the seat-holders view, from the start (design 47 G A-416, A-416a)
|
||||
Holders: holders, // a registry seat's holder from the seat-holders view, from the start (design 47 G A-416, A-416a)
|
||||
Started: time.Now()} // a build ended from now on is of the live class, sent first (H-A-290 (1))
|
||||
// A number a registry seat already holds is never reserved (H-A-275): read before reserving, through the seats' verb versions.
|
||||
reserved.r.HeldNumbers = func(ctx context.Context, module, fp string, refs []string) ([]string, error) {
|
||||
return republish.HeldNumbers(ctx, module, fp, refs, registryVersionsVia(calls.Call))
|
||||
@@ -307,6 +308,8 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
all, err := reserved.r.All(ctx)
|
||||
return builtOf(all), err
|
||||
}}
|
||||
// A version that never publishes (withdrawn or taken over) has its publish item ended by the queue too (H-A-290 (2)).
|
||||
republish.Ended = items.Done
|
||||
reasksKV.Ready(func(jetstream.KeyValue) { items.AskAllDone(ctx) })
|
||||
wirePublishItems(reserved, items, awaitedReserved{awaitedVersions{b: actedKV, bucket: own.acted}}, releasedKept)
|
||||
acts.Republish = republish.Republish
|
||||
|
||||
@@ -104,6 +104,11 @@ func (p *publishItems) AskAllDone(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
for _, v := range vs {
|
||||
if why := versions.NotStanding(v, true); why != "" { // withdrawn: it never publishes (H-A-290 (2))
|
||||
p.logf("%s %s is not asked to publish at the start: %s; its publish item is ended", v.Module, v.Version, why)
|
||||
p.Done(ctx, v.Module, v.Version)
|
||||
continue
|
||||
}
|
||||
if err := p.Ask(ctx, v.Module, v.Version); err != nil {
|
||||
p.logf("%v", err)
|
||||
}
|
||||
@@ -137,7 +142,8 @@ func (p *publishItems) Try(ctx context.Context, kv jetstream.KeyValue, e jetstre
|
||||
p.logf("%s %s: its reservation cannot be read, the publish item waits: %v", r.Module, r.Version, err)
|
||||
return
|
||||
}
|
||||
if !held { // dropped, taken over or released: never because its artifacts are published (A-456b)
|
||||
if why := versions.NotStanding(v, held); why != "" { // dropped, taken over, released or withdrawn: never because its artifacts are published (A-456b, H-A-290 (2))
|
||||
p.logf("%s %s: the publish item is ended: %s", r.Module, r.Version, why)
|
||||
_ = kv.Delete(ctx, e.Key())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -140,11 +140,13 @@ func TestAPublishItemIsTriedWithAGrowingPauseAndEndsLoudly(t *testing.T) {
|
||||
kv.vals, kv.revs = map[string][]byte{}, map[string]uint64{}
|
||||
p.allDone = func(context.Context) ([]versions.ReservedVersion, error) {
|
||||
published := versions.ReservedVersion{Module: "n", Version: "0.2.0", Artifacts: map[string]string{"n:a": "sha256:a"}, Published: map[string]bool{"n:a": true}, BuiltAt: now}
|
||||
return builtOf([]versions.ReservedVersion{v, published, {Module: "o", Version: "0.1.0"}}), nil // the last build has not ended
|
||||
withdrawn := versions.ReservedVersion{Module: "w", Version: "0.4.0", BuiltAt: now, Withdrawn: map[string]string{"0.4.0": "fp"}}
|
||||
return builtOf([]versions.ReservedVersion{v, published, withdrawn, {Module: "o", Version: "0.1.0"}}), nil // the last build has not ended
|
||||
}
|
||||
_ = p.Ask(ctx, "w", "0.4.0") // asked before its reservation was withdrawn
|
||||
p.AskAllDone(ctx)
|
||||
if len(kv.vals) != 2 {
|
||||
t.Errorf("the start asked %d items, want one per done unreleased reservation", len(kv.vals))
|
||||
if _, ok := kv.vals[versions.PublishItemKey("w", "0.4.0")]; len(kv.vals) != 2 || ok {
|
||||
t.Errorf("the start left %d items (withdrawn's kept: %v), want one per done unreleased reservation and none for a withdrawn one (H-A-290 (2))", len(kv.vals), ok)
|
||||
}
|
||||
// A released version's item is deleted; a version no longer reserved has it deleted at its next try.
|
||||
p.Done(ctx, "m", "0.1.2")
|
||||
@@ -152,9 +154,19 @@ func TestAPublishItemIsTriedWithAGrowingPauseAndEndsLoudly(t *testing.T) {
|
||||
if len(kv.vals) != 0 {
|
||||
t.Errorf("the release left %v", kv.vals)
|
||||
}
|
||||
// A withdrawn reservation has its item ended at its try, nothing queued (H-A-290 (2)).
|
||||
queued = nil
|
||||
_ = p.Ask(ctx, "m", "0.1.2")
|
||||
v.Withdrawn = map[string]string{"0.1.2": "fp"}
|
||||
e, _ := kv.Get(ctx, key)
|
||||
p.Try(ctx, kv, e, decodeItem(t, e.Value()))
|
||||
if len(kv.vals) != 0 || len(queued) != 0 {
|
||||
t.Errorf("a withdrawn reservation left its item %v, queued %v", kv.vals, queued)
|
||||
}
|
||||
v.Withdrawn = nil
|
||||
_ = p.Ask(ctx, "m", "0.1.2")
|
||||
reserved = false
|
||||
e, _ := kv.Get(ctx, key)
|
||||
e, _ = kv.Get(ctx, key)
|
||||
p.Try(ctx, kv, e, decodeItem(t, e.Value()))
|
||||
if len(kv.vals) != 0 {
|
||||
t.Errorf("a dropped reservation left its item %v", kv.vals)
|
||||
|
||||
@@ -33,8 +33,8 @@ func (s awaitedQueue) Bytes(ctx context.Context) (uint64, error) {
|
||||
|
||||
// entryVia reads a catalog graph entry by its fingerprint through the seat mesh-catalog's verb entry.
|
||||
func entryVia(call toolCaller) func(ctx context.Context, fingerprint string) (meshcatalog.CatalogEntry, error) {
|
||||
return func(_ context.Context, fingerprint string) (meshcatalog.CatalogEntry, error) {
|
||||
raw, err := call("seat:"+meshcatalog.Seat+"."+meshcatalog.VerbEntry, meshcatalog.EntryInput{Fingerprint: fingerprint})
|
||||
return func(ctx context.Context, fingerprint string) (meshcatalog.CatalogEntry, error) {
|
||||
raw, err := callWithin(ctx, call, "seat:"+meshcatalog.Seat+"."+meshcatalog.VerbEntry, meshcatalog.EntryInput{Fingerprint: fingerprint})
|
||||
if err != nil {
|
||||
return meshcatalog.CatalogEntry{}, err
|
||||
}
|
||||
@@ -50,8 +50,8 @@ func entryVia(call toolCaller) func(ctx context.Context, fingerprint string) (me
|
||||
// artifact store, addressed by digest. The four seats' publish take one wire form; an answer that lacks parts, or a fault of
|
||||
// the call, is the holder's refusal, said in its words (not stored when the holder lacks the bytes).
|
||||
func sendVia(call toolCaller) func(ctx context.Context, p versions.Publish) error {
|
||||
return func(_ context.Context, p versions.Publish) error {
|
||||
raw, err := call("seat:"+p.Seat+"."+versions.VerbPublish, publishBody(p))
|
||||
return func(ctx context.Context, p versions.Publish) error {
|
||||
raw, err := callWithin(ctx, call, "seat:"+p.Seat+"."+versions.VerbPublish, publishBody(p))
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s's publish of %s %s: %w", p.Seat, p.Name, p.Version, err)
|
||||
}
|
||||
@@ -66,6 +66,29 @@ func sendVia(call toolCaller) func(ctx context.Context, p versions.Publish) erro
|
||||
}
|
||||
}
|
||||
|
||||
// callWithin is call within ctx's bound (design 47 H H-A-290 (4)): its answer, or, once the bound ends first, that it was not
|
||||
// answered within it. The call itself ends by its own bound (the SDK's call timeout), its answer then dropped.
|
||||
func callWithin(ctx context.Context, call toolCaller, key string, body any) (json.RawMessage, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, fmt.Errorf("%s is not called: %w", key, context.Cause(ctx))
|
||||
}
|
||||
type answer struct {
|
||||
raw json.RawMessage
|
||||
err error
|
||||
}
|
||||
done := make(chan answer, 1)
|
||||
go func() {
|
||||
raw, err := call(key, body)
|
||||
done <- answer{raw, err}
|
||||
}()
|
||||
select {
|
||||
case a := <-done:
|
||||
return a.raw, a.err
|
||||
case <-ctx.Done():
|
||||
return nil, fmt.Errorf("%s is not answered within its bound: %w", key, context.Cause(ctx))
|
||||
}
|
||||
}
|
||||
|
||||
// publishBody is the seat's publish input for p: the digest, its kind and name and version, no parts.
|
||||
func publishBody(p versions.Publish) gopackageregistry.PublishInput {
|
||||
return gopackageregistry.PublishInput{Commit: p.Commit, Digest: p.Digest, Fingerprint: p.Fingerprint, Kind: p.Kind, Name: p.Name, Transfer: p.Transfer, Version: p.Version}
|
||||
|
||||
@@ -57,6 +57,26 @@ func TestRepublishSend(t *testing.T) {
|
||||
t.Errorf("%s: asked %q, error %v, want %q", name, asked, err, c.want)
|
||||
}
|
||||
}
|
||||
// A send and its entry read honour the bound they are given (design 47 H H-A-290 (4)): a call still unanswered when it ends
|
||||
// is said as not answered within it, and the send goes on.
|
||||
release := make(chan struct{})
|
||||
defer close(release)
|
||||
called := make(chan struct{}, 2)
|
||||
slow := func(string, any) (json.RawMessage, error) {
|
||||
called <- struct{}{}
|
||||
<-release
|
||||
return json.RawMessage(`{}`), nil
|
||||
}
|
||||
for name, call := range map[string]func(context.Context) error{
|
||||
"the publish": func(ctx context.Context) error { return sendVia(slow)(ctx, p) },
|
||||
"the entry": func(ctx context.Context) error { _, err := entryVia(slow)(ctx, "fp"); return err },
|
||||
} {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
go func() { <-called; cancel() }()
|
||||
if err := call(ctx); err == nil || !strings.Contains(err.Error(), "within its bound") {
|
||||
t.Errorf("%s past its bound answered %v, want it not answered within its bound", name, err)
|
||||
}
|
||||
}
|
||||
if _, _, err := build.NewRepublish("", "0.1.3", "why", "me", versionsNow()); err == nil {
|
||||
t.Error("a version with no module is accepted")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user