From 306534fdf04eca1e1eebfd62a52e7b29bc6a2a48 Mon Sep 17 00:00:00 2001 From: jochen Date: Sat, 14 Nov 2026 17:01:52 +0100 Subject: [PATCH] Indexer: a registration's write logs each step with its time; a first registration prunes nothing; a seed stopped part way writes what it has not --- .../internal/index/registrations.go | 12 +++++++++++- .../internal/index/seed.go | 18 ++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/modules/mesh-delivery-indexer/internal/index/registrations.go b/modules/mesh-delivery-indexer/internal/index/registrations.go index 293002e5..3b72ef20 100644 --- a/modules/mesh-delivery-indexer/internal/index/registrations.go +++ b/modules/mesh-delivery-indexer/internal/index/registrations.go @@ -799,10 +799,16 @@ func (r *Registry) apply(ctx context.Context, key string, p Proposal, w oc.Warra func (r *Registry) write(ctx context.Context, key string, p Proposal, next meshcatalog.Registration, w oc.Warrant) error { at := r.now() next.V, next.Version, next.Warrant, next.By, next.At = 1, p.Was+1, w.Ask, p.Caller, &at + began := time.Now() + step := func(what string) { + r.logf("registration %s version %d: %s (%s since its start)", next.Module, next.Version, what, time.Since(began).Round(time.Millisecond)) + } + step("writing") if r.History != nil { if err := r.History(ctx, next); err != nil { return fmt.Errorf("the version %d of %s is not kept on %s, so it is not written: %w", next.Version, next.Module, RegistrationHistoryStream, err) } + step("kept on " + RegistrationHistoryStream) } data, err := json.Marshal(next) if err != nil { @@ -818,12 +824,16 @@ func (r *Registry) write(ctx context.Context, key string, p Proposal, next meshc if err != nil { return err } + step("written") if r.Say != nil { + defer step("registration-changed said") if err := r.Say(ctx, meshcatalog.RegistrationChangedEvent{V: 1, Module: next.Module, Version: next.Version, Moved: p.Lines, By: p.Caller, Warrant: w.Ask, At: &at}); err != nil { r.logf("registration-changed of %s %d is not said: %v", next.Module, next.Version, err) } } - if r.Pruned != nil { + // A first registration watched no branch before, so no branch's builds are to be pruned. + if r.Pruned != nil && p.Was > 0 { + defer step("builds of unwatched branches pruned") if err := r.Pruned(ctx, next.Module, next.Branches); err != nil { r.logf("the builds of %s on the branches it no longer watches are not pruned: %v", next.Module, err) } diff --git a/modules/mesh-delivery-indexer/internal/index/seed.go b/modules/mesh-delivery-indexer/internal/index/seed.go index cc9ba883..0ea0bcba 100644 --- a/modules/mesh-delivery-indexer/internal/index/seed.go +++ b/modules/mesh-delivery-indexer/internal/index/seed.go @@ -116,9 +116,6 @@ func (r *Registry) ProposeSeed(ctx context.Context, modules []SeedModule, again if err != nil { return "", err } - if len(held) > 0 { - return "", errors.New("the indexer holds registrations already: the seed is for the first start only") - } old, _, found, err := r.load(ctx, SeedKey) if err != nil { return "", err @@ -138,15 +135,28 @@ func (r *Registry) ProposeSeed(ctx context.Context, modules []SeedModule, again if len(regs) == 0 { return "", errors.New("no module of the trunk revision can be registered: " + strings.Join(left, "; ")) } + if len(held) > 0 && (!found || old.State != ProposalOpen) { + return "", errors.New("the indexer holds registrations already: the seed is for the first start only") + } + // A seed that stopped part way (its key still open) writes the modules it has not written yet. + have := map[string]bool{} + for _, k := range held { + have[k] = true + } w := oc.Warrant{Ask: "module-graph"} + written := 0 for _, reg := range regs { + if have[RegistrationKey(reg.Module)] { + continue + } p := Proposal{V: 1, Verb: verbRegister, Module: reg.Module, Caller: by, At: r.now(), State: ProposalOpen, Lines: []string{fmt.Sprintf("%s: registered from the module graph (%s)", reg.Module, reg.Origin)}} if err := r.write(ctx, "", p, reg, w); err != nil { return "", err } + written++ } - said := fmt.Sprintf("%d registrations written from the module graph", len(regs)) + said := fmt.Sprintf("%d registrations written from the module graph (%d held before)", written, len(held)) if found && old.State == ProposalOpen { if err := r.end(ctx, SeedKey, old.Ask, ProposalApplied, said); err != nil { r.logf("the seed key is not ended: %v", err)