I8: the take-in fed by the forge bridge's messages goes with B1's forgemsg: the FORGE consumer and its handlers, the group end, the pending state with its keys, claims, dry take-in and hand tools (indexer_pending, indexer_take_in_pending, indexer_drop_pending, indexer_take_in_merge, kept again for the held take-in in I5), the catch-up by comparison (kickBehind, TakeInBehind, sayUntaken, takeInHeads, kickCatchUp, CatchUp, merge-untaken), the source numbering in memory (nextSource), the source verb's follow and Src stamping on a source answer, the bridge's merged message call, the pull request candidates written from pull and open messages, the checker's previews and verdict hearing. A repository's trees at a commit are the internal whole (wholeAt), which ApplyMessage takes in; the dry indexer stays for a run on request's candidate. The manifest drops the consumes of forge.**, the checker's verdict and version-delivered, the reads of the checker's previews and the invokes of open-pulls, bridge_merged_message and mesh-delivery.source. RoomAgain says room when a take-in is held on a full store (heldFull, I5 holds it). H-A-82: the fill of delivered versions into the edges goes: HearVersionDelivered, the delivered.<module> key, the first fill's kinds 2, 4 and 6 from the placement and the stream running, and outdated's kinds 2, 4 and 6; their entries read not yet delivered. The tests of the removed paths go (index_test's candidate groups, source_test, branch_take_in_test, previews_test, candidate_manifests_test, the FORGE handle tests); the versions tests now hold kinds 2, 4 and 6 as declarations. The integration tests still drive FORGE and are rewritten in I10. Builds: design 47 H §743, §744, §764 (the indexer); H-A-48, H-A-82 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
133 lines
5.7 KiB
Go
133 lines
5.7 KiB
Go
package index
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"slices"
|
|
"strings"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-indexer/takein"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/trunk"
|
|
"git.novox.be/novox/mesh-sdk/go/process"
|
|
)
|
|
|
|
// A merge never moves a module backwards (issue 1126, note 76). The indexer wrote mesh-catalog's merge 9cdac09a back over
|
|
// the later 69056948 for kernel and mesh-build-image: applyManifests and writeOverlay wrote whatever commit a merged
|
|
// message carried, so a late or repeated message rolled the modules, and the nodes that want them, back.
|
|
//
|
|
// The question is whether the incoming commit is OLDER: the forge says the incoming commit is in the later one and the
|
|
// two differ (Contains(incoming, in: later)). Only then is it kept back. A diverged or rewritten history answers no, and
|
|
// is written forward; a commit the forge no longer has (a 404) is not known to be older, is written, and said. A forge
|
|
// that cannot say for another reason (a timeout) writes nothing and is an error: the server delivers the message again.
|
|
//
|
|
// - A merged message asks once, before it writes anything: is its merge older than the repository's taken merge (the
|
|
// last merge applied whole, taken.go)? Then the whole message is late: no module is written or deleted, the taken key
|
|
// stays, and the log says so.
|
|
// - A take-in of a held module asks once for that module: is the source's head older than the module's record
|
|
// (takeInHeld)?
|
|
|
|
// mergeWrite is one merge's write of the modules: its repository and commit, whether it is late (older than the taken
|
|
// merge), the taken merge it was compared with and the answer, and the module keys written, for the line the indexer says
|
|
// per applied merged message.
|
|
type mergeWrite struct {
|
|
repository, merge string
|
|
late string // the taken merge this one is older than, or ""
|
|
asked string // the taken merge the order was asked against, or "" when none was asked
|
|
written []string
|
|
// fresh are the manifest digests this take-in newly wrote: a new module's, or a changed one's (ADR 0579 §1).
|
|
fresh map[string]bool
|
|
}
|
|
|
|
// taken marks a digest this take-in newly wrote.
|
|
func (w *mergeWrite) taken(digest string) {
|
|
if w.fresh == nil {
|
|
w.fresh = map[string]bool{}
|
|
}
|
|
w.fresh[digest] = true
|
|
}
|
|
|
|
func newMergeWrite(f whole) *mergeWrite {
|
|
return &mergeWrite{repository: f.Repository, merge: f.Merge}
|
|
}
|
|
|
|
// ErrNotFound is the forge saying that what it was asked about (here a commit) does not exist: the seat git's error kind
|
|
// not-found, which the indexer's call of the seat wraps (cmd/mesh-delivery-indexer named.go). Only the kind says it,
|
|
// never the error's words: a 502 whose words carry "404" inside a sha is a failure.
|
|
var ErrNotFound = errors.New("the forge does not have it")
|
|
|
|
// notFound says the forge answered that a commit it was asked about does not exist.
|
|
func notFound(err error) bool { return errors.Is(err, ErrNotFound) }
|
|
|
|
// older says commit is older than later: the forge says commit is in later and the two differ. A commit the forge does not
|
|
// have is not known to be older (false, said); a forge that cannot say otherwise is an error. Without a forge to ask
|
|
// (Contains nil) nothing is older.
|
|
func (ix *Indexer) older(ctx context.Context, repository, commit, later string) (bool, error) {
|
|
if ix.Contains == nil || commit == "" || later == "" || commit == later {
|
|
return false, nil
|
|
}
|
|
in, err := ix.Contains(ctx, repository, commit, later)
|
|
if notFound(err) {
|
|
ix.logf("%s: the forge does not have %.12s or %.12s (a rewritten history?), so %.12s is not known to be older and is written: %v", repository, commit, later, commit, err)
|
|
return false, nil
|
|
}
|
|
if err != nil {
|
|
return false, fmt.Errorf("%s: whether %.12s is older than %.12s cannot be read, so nothing of it is written (a merge never moves a module backwards, issue 1126): %w", repository, commit, later, err)
|
|
}
|
|
return in, nil
|
|
}
|
|
|
|
// lateMerge asks, before a merged message writes anything, whether its merge is older than the repository's taken merge
|
|
// (one forge call). A taken state not on the bus yet, or no taken key, asks nothing.
|
|
func (ix *Indexer) lateMerge(ctx context.Context, w *mergeWrite) error {
|
|
if ix.Taken == nil || w.merge == "" {
|
|
return nil
|
|
}
|
|
key, err := trunk.RepositoryKey(w.repository)
|
|
if err != nil {
|
|
return nil // writeTaken says it
|
|
}
|
|
value, _, found, err := ix.Taken.Get(ctx, key)
|
|
if errors.Is(err, process.ErrNotYet) || !found {
|
|
return nil
|
|
}
|
|
if err != nil {
|
|
return fmt.Errorf("taken.%s: %w", key, err)
|
|
}
|
|
cur, err := takein.DecodeTaken(value)
|
|
if err != nil || cur.Merge == "" || cur.Merge == w.merge {
|
|
return nil
|
|
}
|
|
old, err := ix.older(ctx, w.repository, w.merge, cur.Merge)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
w.asked = cur.Merge
|
|
if old {
|
|
w.late = cur.Merge
|
|
ix.logf("%s at %.12s: the merged message is older than taken.%s at %.12s, so no module is written or deleted (a late or repeated message; a merge never moves a module backwards, issue 1126)",
|
|
w.repository, w.merge, key, cur.Merge)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// wrote records a module key the merge wrote.
|
|
func (w *mergeWrite) wrote(key string) {
|
|
if w != nil && !slices.Contains(w.written, key) {
|
|
w.written = append(w.written, key)
|
|
}
|
|
}
|
|
|
|
// said is the line of an applied merged message: its repository, commit and pull request, and the modules written.
|
|
func (w *mergeWrite) said() string {
|
|
if w.late != "" {
|
|
return fmt.Sprintf("%s at %.12s: taken in as late: older than the taken %.12s, nothing written", w.repository, w.merge, w.late)
|
|
}
|
|
written := "none"
|
|
if len(w.written) > 0 {
|
|
written = strings.Join(slices.Sorted(slices.Values(w.written)), ", ")
|
|
}
|
|
return fmt.Sprintf("%s at %.12s: taken in; modules written: %s", w.repository, w.merge, written)
|
|
}
|