diff --git a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/main.go b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/main.go index 51e04cb50..e48e3cbc6 100644 --- a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/main.go +++ b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/main.go @@ -362,8 +362,11 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro Packages: awaitedStore{b: packages, js: js, name: index.Bucket(cred.Module, index.PackagesState)}, Files: filesVia(calls.Call), GoSum: goSumVia(calls.Call), GoMod: goModVia(calls.Call), Heard: heardStore, Runs: awaitedStore{b: runs}, Graph: graph, // How long a reservation is kept and how long its gathering waits at most (design 47 H2 §805, H-A-424). - ReservedKeep: reservedSetting("reserved-keep", index.DefaultReservedKeep, logger.Printf), - ReservedSettle: reservedSetting("reserved-settle", index.DefaultReservedSettle, logger.Printf), + ReservedKeep: durationSetting("reserved-keep", index.DefaultReservedKeep, logger.Printf), + ReservedSettle: durationSetting("reserved-settle", index.DefaultReservedSettle, logger.Printf), + // How long a take-in waits on another part before it says so, and before it raises take-in-waiting (H2 §803, H-A-461 (2)). + WaitingLine: durationSetting(index.WaitingLineSetting, index.DefaultWaitingLine, logger.Printf), + WaitingBound: durationSetting(index.WaitingBoundSetting, index.DefaultWaitingBound, logger.Printf), SeatDefinitions: awaitedStore{b: seatDefs}, ReadFile: readFileVia(calls.Call), SaySeatDefinition: saySeats, Revisions: revisions, EntryIndex: awaitedStore{b: process.AwaitBucket(ctx, js, conn, index.Bucket(cred.Module, index.EntryIndexState), "no entry is found by its fingerprint", logger.Printf)}, // Message a kept call: a read, called again through a transport fault (ADR 0668 §1) // Each catalog revision may bring another holder of a build seat: the build modules are found again (buildmodules.go). @@ -690,8 +693,8 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro } } -// reservedSetting is the setting key read as a duration (stdio.SettingDuration); one that does not read is said and takes def. -func reservedSetting(key string, def time.Duration, logf func(string, ...any)) time.Duration { +// durationSetting is the setting key read as a duration (stdio.SettingDuration); one that does not read is said and takes def. +func durationSetting(key string, def time.Duration, logf func(string, ...any)) time.Duration { d, err := stdio.SettingDuration(key, def) if err != nil { logf("%v: %s is taken", err, def) diff --git a/modules/mesh-delivery-indexer/internal/index/candidates.go b/modules/mesh-delivery-indexer/internal/index/candidates.go index bb94bccbe..42e39d950 100644 --- a/modules/mesh-delivery-indexer/internal/index/candidates.go +++ b/modules/mesh-delivery-indexer/internal/index/candidates.go @@ -196,6 +196,10 @@ type Indexer struct { // first reservation its gathering settles at the latest: the settings reserved-keep and reserved-settle (design 47 H2 // §805, H-A-424); zero takes the default. ReservedKeep, ReservedSettle time.Duration + // WaitingLine is how long a take-in waits on another part before it says so and keeps its waiting-on, and WaitingBound + // how long before it raises take-in-waiting: the settings take-in-waiting-line and take-in-waiting-bound (design 47 H2 + // §803, H-A-461 (2)); zero takes the default. + WaitingLine, WaitingBound time.Duration } func (ix *Indexer) logf(format string, args ...any) { diff --git a/modules/mesh-delivery-indexer/internal/index/takein_source_test.go b/modules/mesh-delivery-indexer/internal/index/takein_source_test.go index 3386f2592..5765977ef 100644 --- a/modules/mesh-delivery-indexer/internal/index/takein_source_test.go +++ b/modules/mesh-delivery-indexer/internal/index/takein_source_test.go @@ -1,6 +1,7 @@ package index import ( + "cmp" "context" "encoding/json" "errors" @@ -141,11 +142,15 @@ func TestASourceRevisionIsTakenInAsOneRevision(t *testing.T) { now := start timers := make(chan context.CancelFunc) var mu sync.Mutex + var asked []time.Duration // the bounds the wait asked, in order var lines []string wrote := make(chan struct{}, 1) findings := newFindings() w := &Indexer{Module: testSelf, TakeIns: running, Findings: findings, Now: func() time.Time { mu.Lock(); defer mu.Unlock(); return now }, - Bound: func(parent context.Context, _ time.Duration) (context.Context, context.CancelFunc) { + Bound: func(parent context.Context, d time.Duration) (context.Context, context.CancelFunc) { + mu.Lock() + asked = append(asked, d) + mu.Unlock() b, cancel := context.WithCancel(parent) timers <- cancel return b, cancel @@ -156,10 +161,10 @@ func TestASourceRevisionIsTakenInAsOneRevision(t *testing.T) { lines = append(lines, fmt.Sprintf(format, args...)) }} w.Findings = findingsSignal{findings, wrote} - listing := func(answerAfter time.Duration) { + listing := func(answerAfter, line, bound time.Duration) { t.Helper() mu.Lock() - now, lines = start, nil + now, lines, asked = start, nil, nil mu.Unlock() release, res := make(chan struct{}), make(chan error) go func() { @@ -167,7 +172,7 @@ func TestASourceRevisionIsTakenInAsOneRevision(t *testing.T) { res <- err }() first := <-timers - if answerAfter < WaitingLineAfter { + if answerAfter < line { close(release) <-res return @@ -177,7 +182,7 @@ func TestASourceRevisionIsTakenInAsOneRevision(t *testing.T) { mu.Unlock() first() second := <-timers // asked once the line is said and the waiting-on written - if answerAfter >= WaitingFindingAfter { + if answerAfter >= bound { second() <-wrote if h := findings.Held(); len(h) != 1 || h[0].Kind != TakeInWaitingKind || h[0].Scope != mcc.ScopeMerge || h[0].ID != "9" { @@ -189,15 +194,27 @@ func TestASourceRevisionIsTakenInAsOneRevision(t *testing.T) { t.Fatal(err) } } + // The bounds are the settings take-in-waiting-line and take-in-waiting-bound, 1m and 5m when unset (H-A-461 (2)): the + // wait asks the line, then the rest to the bound. for _, c := range []struct { - after time.Duration - lines int - finding bool - }{{30 * time.Second, 0, false}, {70 * time.Second, 1, false}, {6 * time.Minute, 1, false}} { - listing(c.after) + after, line, bound time.Duration // line and bound zero: the settings unset + lines int + finding bool + }{{30 * time.Second, 0, 0, 0, false}, {70 * time.Second, 0, 0, 1, false}, {6 * time.Minute, 0, 0, 1, false}, + {6 * time.Minute, 2 * time.Minute, 10 * time.Minute, 1, false}} { + w.WaitingLine, w.WaitingBound = c.line, c.bound + line, bound := cmp.Or(c.line, time.Minute), cmp.Or(c.bound, 5*time.Minute) + listing(c.after, line, bound) mu.Lock() - got := slices.Clone(lines) + got, gotAsked := slices.Clone(lines), slices.Clone(asked) mu.Unlock() + wantAsked := []time.Duration{line} + if c.after >= line { + wantAsked = append(wantAsked, bound-line) + } + if !slices.Equal(gotAsked, wantAsked) { + t.Errorf("answered after %s (line %s, bound %s): bounds asked %v, want %v", c.after, c.line, c.bound, gotAsked, wantAsked) + } if len(got) != c.lines || (c.lines == 1 && !strings.Contains(got[0], "waits on git trees since 2026-11-22T01:00:00Z")) { t.Errorf("answered after %s: lines %q, want %d naming git trees and since when", c.after, got, c.lines) } diff --git a/modules/mesh-delivery-indexer/internal/index/takein_waiting.go b/modules/mesh-delivery-indexer/internal/index/takein_waiting.go index e732b658f..b29d0f9d2 100644 --- a/modules/mesh-delivery-indexer/internal/index/takein_waiting.go +++ b/modules/mesh-delivery-indexer/internal/index/takein_waiting.go @@ -11,17 +11,19 @@ import ( mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient" ) -// A take-in says what it waits on (design 47 H2 §803, H-A-409): a source-moved take-in that waits longer than -// WaitingLineAfter on another part (the seat git's listing or a file, a package's versions, a registry) writes one journal +// A take-in says what it waits on (design 47 H2 §803, H-A-409): a source-moved take-in that waits longer than the +// setting take-in-waiting-line on another part (the seat git's listing or a file, a package's versions, a registry) writes one journal // line naming the part, the verb and since when, and keeps its waiting-on in the state takeins under the key -// RunningPrefix and the source revision, rewritten at each new wait and removed at the take-in's end; past -// WaitingFindingAfter it raises the finding take-in-waiting (scope merge, id the source revision), cleared when the wait -// ends. indexer_pending answers it beside the held take-ins. +// RunningPrefix and the source revision, rewritten at each new wait and removed at the take-in's end; past the setting +// take-in-waiting-bound it raises the finding take-in-waiting (scope merge, id the source revision), cleared when the wait +// ends. indexer_pending answers it beside the held take-ins. The two bounds are settings with these defaults (H-A-461 (2)). const ( TakeInWaitingKind = "take-in-waiting" RunningPrefix = "running." - WaitingLineAfter = time.Minute - WaitingFindingAfter = 5 * time.Minute + WaitingLineSetting = "take-in-waiting-line" + WaitingBoundSetting = "take-in-waiting-bound" + DefaultWaitingLine = time.Minute + DefaultWaitingBound = 5 * time.Minute ) // WaitingOn is what a running take-in waits on: the part, its verb and since when. @@ -95,8 +97,8 @@ func passed(ctx, b context.Context, done <-chan struct{}) bool { return ctx.Err() == nil } -// waited is f, a call on part's verb: within a running take-in (ctx), a wait past WaitingLineAfter is said and kept, one -// past WaitingFindingAfter raises take-in-waiting until it ends. Outside a take-in it is f alone. +// waited is f, a call on part's verb: within a running take-in (ctx), a wait past take-in-waiting-line is said and kept, one +// past take-in-waiting-bound raises take-in-waiting until it ends. Outside a take-in it is f alone. func waited[T any](ctx context.Context, part, verb string, f func() (T, error)) (T, error) { run, ok := ctx.Value(takeInRunKey{}).(*takeInRun) if !ok { @@ -115,7 +117,14 @@ func waited[T any](ctx context.Context, part, verb string, f func() (T, error)) func (ix *Indexer) watchWait(ctx context.Context, run *takeInRun, part, verb string, done <-chan struct{}) { since := ix.now().UTC() - line, cancel := ix.bound(ctx, WaitingLineAfter) + after, bound := ix.WaitingLine, ix.WaitingBound + if after <= 0 { + after = DefaultWaitingLine + } + if bound <= 0 { + bound = DefaultWaitingBound + } + line, cancel := ix.bound(ctx, after) defer cancel() if !passed(ctx, line, done) { return @@ -123,7 +132,7 @@ func (ix *Indexer) watchWait(ctx context.Context, run *takeInRun, part, verb str ix.logf("take-in: source revision %d of %s waits on %s %s since %s", run.source, run.branch, part, verb, since.Format(time.RFC3339)) ix.writeWaiting(ctx, RunningTakeIn{Branch: run.branch, Source: run.source, WaitingOn: WaitingOn{Part: part, Verb: verb, Since: since}}) id := strconv.FormatInt(run.source, 10) - finding, cancelFinding := ix.bound(ctx, WaitingFindingAfter-WaitingLineAfter) + finding, cancelFinding := ix.bound(ctx, max(bound-after, 0)) defer cancelFinding() if !passed(ctx, finding, done) { return diff --git a/modules/mesh-delivery-indexer/manifest_test.go b/modules/mesh-delivery-indexer/manifest_test.go index 8eb5d50ec..af28dc77e 100644 --- a/modules/mesh-delivery-indexer/manifest_test.go +++ b/modules/mesh-delivery-indexer/manifest_test.go @@ -229,11 +229,11 @@ func TestManifestDeclarations(t *testing.T) { // 1238/AC1, 1444 (reads the build t.Errorf("streams = %+v, want registration-history keeping its history, 64 MiB, and the findings stream at 8 MiB (§387, H2 §783)", m.Streams) } // Design 47 H2 §810, §814 (H-A-394 (1)): it claims a seat, so its class is core. §775: it makes kept calls, so it declares - // the kept-call pace, 1 s to 30 s, read while it runs. + // the kept-call pace, 1 s to 30 s, read while it runs. §803 (H-A-461 (2)): a take-in's waiting line and bound, 1m and 5m. if m.Class != "core" { t.Errorf("class = %q, want core", m.Class) } - for key, def := range map[string]string{busretry.PaceFirstSetting: "1s", busretry.PaceMaxSetting: "30s"} { + for key, def := range map[string]string{busretry.PaceFirstSetting: "1s", busretry.PaceMaxSetting: "30s", index.WaitingLineSetting: "1m", index.WaitingBoundSetting: "5m"} { if c, _ := m.Config[key].(map[string]any); c["default"] != def || c["runtime"] != true || c["type"] != "string" { t.Errorf("config %s = %v, want a runtime string setting defaulting to %s", key, m.Config[key], def) } diff --git a/modules/mesh-delivery-indexer/module.json b/modules/mesh-delivery-indexer/module.json index 5a9a0307b..e48cd603e 100644 --- a/modules/mesh-delivery-indexer/module.json +++ b/modules/mesh-delivery-indexer/module.json @@ -130,6 +130,20 @@ "trusted": false, "default": "30s", "runtime": true + }, + "take-in-waiting-line": { + "type": "string", + "description": "how long a take-in waits on another part (the seat git, a package's versions, a registry) before it writes one journal line and its waiting-on in takeins, a Go duration (design 47 H2 §803, H-A-461 (2)).", + "trusted": false, + "default": "1m", + "runtime": true + }, + "take-in-waiting-bound": { + "type": "string", + "description": "how long a take-in waits on another part before it raises the finding take-in-waiting, cleared when the wait ends, a Go duration (design 47 H2 §803, H-A-461 (2)).", + "trusted": false, + "default": "5m", + "runtime": true } }, "state": [