Add the chain package and its buckets: builds, rollouts and assignments with history 64 (issue 1089)

internal/chain holds typed Build, Rollout and Assignment and a Backend with no delete or purge, in memory and on the bus. The builds and rollouts buckets are asserted with history 64, no age and values up to just under a mebibyte; the assignments bucket gets the same, keeping its marker age because a stream cannot be made to disallow message ages. Migration 0104 makes the one-row chain_moved switch. The controller keeps no consolidated schema, so 0104 is the whole schema change. Nothing reads the buckets yet.
This commit is contained in:
2026-10-18 02:39:11 +02:00
parent 54070f5bc3
commit fc55785956
15 changed files with 1175 additions and 9 deletions
+40
View File
@@ -0,0 +1,40 @@
package inventory
import (
"strings"
"testing"
)
// **The move of the chain has a switch, made by the last migration and written by no migration** (ADR 0408 §8, issue
// 1089): migration 0104 makes the one-row table chain_moved, and does not touch a table of the chain, which a later
// delivery drops once the move is read back.
func TestMigration0104MakesTheSwitchOfTheChainsMoveAndNothingElse(t *testing.T) {
migrations, err := Migrations()
if err != nil {
t.Fatal(err)
}
var found bool
for _, m := range migrations {
if m.Number != 104 {
continue
}
found = true
sql := strings.ToLower(m.SQL)
if !strings.Contains(sql, "create table chain_moved") || !strings.Contains(sql, "check (only_one)") {
t.Errorf("migration 0104 does not make the one-row chain_moved:\n%s", m.SQL)
}
for _, line := range strings.Split(sql, "\n") {
if strings.HasPrefix(strings.TrimSpace(line), "--") {
continue
}
for _, verb := range []string{"drop ", "insert ", "delete ", "update ", "alter "} {
if strings.Contains(line, verb) {
t.Errorf("migration 0104 does more than make the switch: %q", line)
}
}
}
}
if !found {
t.Fatal("no migration 0104")
}
}
@@ -0,0 +1,16 @@
-- Builds, rollouts and assignments move to the bus (novox/hq ADR 0408 §8, design 47 milestone 5, issue 1089).
--
-- This migration makes the switch alone. The rows of build, build_request, release_plan, batched_merge, assignment and
-- pending_assignment are written into the chain's buckets by the serving controller at its start, holding the lease,
-- because a migration runs when the store is opened, before any connection to the bus. This row is the switch: while it
-- is absent nothing reads the buckets; once the move has counted every row against the keys it wrote, it is written, and
-- nothing reads the tables. One row at most; never written by a migration, so a delivery alone changes nothing. The
-- controller keeps no consolidated schema, so this migration is the whole of the change; the tables go by a later one.
create table chain_moved (
only_one boolean primary key default true check (only_one),
moved_at timestamptz not null default now(),
-- The counts the move read from the tables and wrote as keys, per kind, and the largest value it wrote: what a
-- reader of the move reads back.
counts jsonb not null,
largest jsonb not null
);