A catalogue asks for what it was not there to hear
Its event queue is durable, so a running catalogue misses nothing. What it cannot have is what was announced before it first ran — and on a fresh mesh that is never arbitrary: the shared base, the store the catalogue runs on, and the catalogue itself are each necessarily built BEFORE a catalogue exists to hear about them. The graph's foundation is the part it never sees. So it says it is catching up, and the control plane re-announces what it recorded, oldest first, marked as a replay. Oldest first because a graph is built in the order things happened: registering a module that stands on a base before the base would point an edge at a version nothing has seen, and the shape of a fresh mesh guarantees the base is both first and the one that was missed. The replayer hands announcements back rather than publishing them, because the wire belongs to the link package and a replay building its own events could drift from what the builder emits — the one thing it must match exactly, since the catalogue has a single handler for both. Its own queue and its own consumer: two consumers on one queue split its messages, and a catch-up request going to whichever half was not listening is a gap that looks like a working mesh. Toward novox/hq 04-ISSUES/050. Claude-Session: https://claude.ai/code/session_01D6qtiYU3P9jk3pnAXyAFyx
This commit is contained in:
@@ -3,6 +3,7 @@ package inventory
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"sort"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -174,3 +175,63 @@ func manifestOrNil(raw []byte) any {
|
||||
}
|
||||
return raw
|
||||
}
|
||||
|
||||
// Announceable is every build worth telling a catalogue about, oldest first.
|
||||
//
|
||||
// **Oldest first, because a graph is built in the order things happened.** Registering a module
|
||||
// that stands on a base before the base itself would make the edge point at a version the
|
||||
// catalogue has not seen, and the shape of a fresh mesh guarantees that order matters: the base is
|
||||
// always first and always the one that was missed.
|
||||
//
|
||||
// Only builds that succeeded and know what they built. A failure produced no module-version, and
|
||||
// announcing one would put something in the graph that was never made — the same rule the builder
|
||||
// follows when it decides whether to announce at all.
|
||||
//
|
||||
// One row per module and commit: a module built twice at the same commit is one fact, and the
|
||||
// latest row is the one whose artifacts are current.
|
||||
func (i *Inventory) Announceable(ctx context.Context) ([]Build, error) {
|
||||
rows, err := i.store.Pool().Query(ctx,
|
||||
`select distinct on (module, commit_hash)
|
||||
id, repository, ref, module, commit_hash, built_on, failed, made,
|
||||
source_path, manifest, built_against, at
|
||||
from build
|
||||
where failed = '' and module is not null and module <> '' and commit_hash <> ''
|
||||
order by module, commit_hash, at desc`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var out []Build
|
||||
for rows.Next() {
|
||||
var b Build
|
||||
var made []byte
|
||||
var manifest, against []byte
|
||||
if err := rows.Scan(&b.ID, &b.Repository, &b.Ref, &b.Module, &b.Commit,
|
||||
&b.On, &b.Failed, &made, &b.Path, &manifest, &against, &b.At); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := json.Unmarshal(made, &b.Made); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Null rather than empty is a build recorded before the mesh kept these, and saying so is
|
||||
// the point of keeping them nullable: the replay carries nothing rather than an empty
|
||||
// declaration for a module that certainly had one.
|
||||
if len(manifest) > 0 {
|
||||
b.Manifest = manifest
|
||||
}
|
||||
if len(against) > 0 {
|
||||
if err := json.Unmarshal(against, &b.Against); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
out = append(out, b)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Sorted here rather than in the query, because `distinct on` fixes the ordering it needs and
|
||||
// the order that matters to a catalogue is a different one.
|
||||
sort.Slice(out, func(a, b int) bool { return out[a].At.Before(out[b].At) })
|
||||
return out, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user