provision: hostname history store, data-kind predicate, kind immutability
Nearest-region never-reuse plan, Task 2 (spec 2026-10-26 rev 5, #404).
control/hosts-used/<host>.json marks are create-only (MarkHostUsed);
@mode (absent = incomplete) and @floor live beside them. Record.DataKind
exempts static and service. WriteRecord refuses an in-place kind change,
except a create from {} or a tombstone (TombstoneBody keeps no kind).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8 files changed,
+513
−3
docs/superpowers/notes/census-proposal-nearest-region-a.md+11 −0internal/provision/hostsused.go+235 −0internal/provision/hostsused_test.go+218 −0internal/provision/nearest_region_a_census_test.go+35 −0internal/provision/plan9_b8_census_test.go+1 −1internal/provision/record_sequence.go+9 −2internal/provision/testdata/plan14-root-reads-chain.tsv+1 −0internal/provision/testdata/plan14-root-reads-nearest-region-a.tsv+3 −0
CI cancelled — superseded by a newer push — run details
diff --git a/docs/superpowers/notes/census-proposal-nearest-region-a.md b/docs/superpowers/notes/census-proposal-nearest-region-a.md| new file mode 100644 |
| index 000000000..746b430b2 |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-nearest-region-a.md |
| @@ -0,0 +1,11 @@ |
| +# Census approval: nearest-region-a |
| + |
| +Ruling `census-ruling-nearest-region-a`. Every change below keeps the disposition it already has, so it needs an approval, not a decision. |
| + |
| +Envelopes re-pinned: `internal/provision`. |
| + |
| +Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Escalate if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. An escalation goes to the census owner as a decision. |
| + |
| +Seal: `d1e00cfb29d88b7a8e4998b641164e539067a6e1e9e4f52524255343c0c5f9f7` → `d1e00cfb29d88b7a8e4998b641164e539067a6e1e9e4f52524255343c0c5f9f7`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-nearest-region-a.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/internal/provision/hostsused.go b/internal/provision/hostsused.go| new file mode 100644 |
| index 000000000..43d8cd01d |
| --- /dev/null |
| +++ b/internal/provision/hostsused.go |
| @@ -0,0 +1,235 @@ |
| +package provision |
| + |
| +import ( |
| + "context" |
| + "encoding/json" |
| + "errors" |
| + "fmt" |
| + "os" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// The hostname history (nearest-region never-reuse; spec |
| +// docs/superpowers/specs/2026-10-26-nearest-region-without-claims-design.md |
| +// §1, §4). A mark at control/hosts-used/<host>.json means "this hostname may |
| +// hold data". Every data-kind create writer puts one, create-only, before it |
| +// persists anything; no code path ever deletes one. Beside the marks live two |
| +// objects whose names cannot be hostnames: @mode (the console's history |
| +// mode) and @floor (the oldest record-writing build allowed once active). |
| + |
| +// HostsUsedPrefix is where the marks, the mode and the floor live, in the |
| +// console's control store. |
| +const HostsUsedPrefix = "control/hosts-used/" |
| + |
| +// HostsModeKey and HostsFloorKey start with "@", which no valid hostname |
| +// does, so a listing of HostsUsedPrefix tells them from marks. |
| +const ( |
| + HostsModeKey = HostsUsedPrefix + "@mode" |
| + HostsFloorKey = HostsUsedPrefix + "@floor" |
| +) |
| + |
| +// The history modes (spec §4). Absent in the store means incomplete. |
| +const ( |
| + HostsModeIncomplete = "incomplete" |
| + HostsModeActivating = "activating" |
| + HostsModeActive = "active" |
| + HostsModeInvalidated = "invalidated" |
| +) |
| + |
| +// ErrKindChange refuses an in-place write that changes a record's kind: an |
| +// exempt record (static, service) must never become a data kind without the |
| +// mark its create would have written. |
| +var ErrKindChange = errors.New("provision: a record's kind cannot change") |
| + |
| +// HostUse is a mark's body. It records who first marked the hostname and |
| +// why; nothing reads it back as authority, since the mark's presence alone |
| +// is the fact. |
| +type HostUse struct { |
| + Host string `json:"host"` |
| + Account string `json:"account"` |
| + App string `json:"app"` |
| + Kind string `json:"kind"` |
| + Source string `json:"source"` |
| + At time.Time `json:"at"` |
| +} |
| + |
| +// HostsUsedKey is host's mark key, or "" for a host that fails |
| +// ValidHostShape (uppercase, a trailing dot, a slash, "@mode"). |
| +func HostsUsedKey(host string) string { |
| + if !ValidHostShape(host) { |
| + return "" |
| + } |
| + return HostsUsedPrefix + host + ".json" |
| +} |
| + |
| +// MarkHostUsed writes u's mark create-only. fresh reports that this call |
| +// wrote it; a mark already present is (false, nil) and its body is left as |
| +// it was. Any other store error passes through: the caller does not know |
| +// whether the hostname is marked. |
| +func MarkHostUsed(ctx context.Context, s release.Store, u HostUse) (fresh bool, err error) { |
| + key := HostsUsedKey(u.Host) |
| + if key == "" { |
| + return false, fmt.Errorf("provision: hosts used: %q is not a hostname", u.Host) |
| + } |
| + body, err := json.Marshal(u) |
| + if err != nil { |
| + return false, err |
| + } |
| + if _, err := s.Put(ctx, key, body, ""); err != nil { |
| + if errors.Is(err, release.ErrCASConflict) { |
| + return false, nil |
| + } |
| + return false, err |
| + } |
| + return true, nil |
| +} |
| + |
| +// HostIsUsed reports whether host's mark exists. An unreadable store is an |
| +// error, never "unused". |
| +func HostIsUsed(ctx context.Context, s release.Store, host string) (bool, error) { |
| + key := HostsUsedKey(host) |
| + if key == "" { |
| + return false, fmt.Errorf("provision: hosts used: %q is not a hostname", host) |
| + } |
| + _, _, err := s.Get(ctx, key) |
| + switch { |
| + case err == nil: |
| + return true, nil |
| + case errors.Is(err, os.ErrNotExist): |
| + return false, nil |
| + } |
| + return false, err |
| +} |
| + |
| +// DataKind reports whether a record of r's kind can hold data: every kind |
| +// but static and service (spec §1). An addr-backed instance is a data kind, |
| +// because its Addrs can change. Sidecars are always data kinds and are |
| +// marked by their own writer. |
| +func (r Record) DataKind() bool { |
| + switch r.KindOrDefault() { |
| + case "static", "service": |
| + return false |
| + } |
| + return true |
| +} |
| + |
| +func validHostsMode(m string) bool { |
| + switch m { |
| + case HostsModeIncomplete, HostsModeActivating, HostsModeActive, HostsModeInvalidated: |
| + return true |
| + } |
| + return false |
| +} |
| + |
| +type hostsModeBody struct { |
| + Mode string `json:"mode"` |
| +} |
| + |
| +// ReadHostsMode reads @mode. Absent is (incomplete, "", nil). A body that |
| +// does not name a known mode is an error, never a default. |
| +func ReadHostsMode(ctx context.Context, s release.Store) (mode, etag string, err error) { |
| + raw, etag, err := s.Get(ctx, HostsModeKey) |
| + if errors.Is(err, os.ErrNotExist) { |
| + return HostsModeIncomplete, "", nil |
| + } |
| + if err != nil { |
| + return "", "", err |
| + } |
| + var b hostsModeBody |
| + if err := json.Unmarshal(raw, &b); err != nil { |
| + return "", "", fmt.Errorf("provision: hosts used: %s: %w", HostsModeKey, err) |
| + } |
| + if !validHostsMode(b.Mode) { |
| + return "", "", fmt.Errorf("provision: hosts used: %s names no known mode (%q)", HostsModeKey, b.Mode) |
| + } |
| + return b.Mode, etag, nil |
| +} |
| + |
| +// WriteHostsMode writes @mode on ifMatch ("" is create-only, as Store.Put) |
| +// and returns the new ETag. A lost race is release.ErrCASConflict. |
| +func WriteHostsMode(ctx context.Context, s release.Store, mode, ifMatch string) (string, error) { |
| + if !validHostsMode(mode) { |
| + return "", fmt.Errorf("provision: hosts used: unknown mode %q", mode) |
| + } |
| + body, err := json.Marshal(hostsModeBody{Mode: mode}) |
| + if err != nil { |
| + return "", err |
| + } |
| + return s.Put(ctx, HostsModeKey, body, ifMatch) |
| +} |
| + |
| +// HostsFloor is the oldest console and CLI build allowed to write records |
| +// once the history is active (spec §4). |
| +type HostsFloor struct { |
| + Version string `json:"version"` |
| + Commit string `json:"commit"` |
| +} |
| + |
| +// ReadHostsFloor reads @floor; absent is (nil, "", nil). |
| +func ReadHostsFloor(ctx context.Context, s release.Store) (*HostsFloor, string, error) { |
| + raw, etag, err := s.Get(ctx, HostsFloorKey) |
| + if errors.Is(err, os.ErrNotExist) { |
| + return nil, "", nil |
| + } |
| + if err != nil { |
| + return nil, "", err |
| + } |
| + var f HostsFloor |
| + if err := json.Unmarshal(raw, &f); err != nil { |
| + return nil, "", fmt.Errorf("provision: hosts used: %s: %w", HostsFloorKey, err) |
| + } |
| + return &f, etag, nil |
| +} |
| + |
| +// WriteHostsFloor writes @floor on ifMatch, as WriteHostsMode. |
| +func WriteHostsFloor(ctx context.Context, s release.Store, f HostsFloor, ifMatch string) (string, error) { |
| + body, err := json.Marshal(f) |
| + if err != nil { |
| + return "", err |
| + } |
| + return s.Put(ctx, HostsFloorKey, body, ifMatch) |
| +} |
| + |
| +// checkKindUnchanged is WriteRecord's kind immutability. before and body are |
| +// the fields RecordSequence parsed. A create ({} before) may be any kind. A |
| +// tombstone body keeps no kind (TombstoneBody) and is no live record, so |
| +// retiring a record of any kind still lands. Absent and "" read as instance. |
| +func checkKindUnchanged(before, body map[string]json.RawMessage) error { |
| + if len(before) == 0 || isTombstoneFields(body) { |
| + return nil |
| + } |
| + b, okB := kindOfFields(before) |
| + a, okA := kindOfFields(body) |
| + if !okB || !okA || a != b { |
| + return ErrKindChange |
| + } |
| + return nil |
| +} |
| + |
| +// kindOfFields is the kind a record body's fields name; false when the |
| +// field is present and not a string. |
| +func kindOfFields(f map[string]json.RawMessage) (string, bool) { |
| + raw, ok := f["kind"] |
| + if !ok { |
| + return "instance", true |
| + } |
| + var k string |
| + if err := json.Unmarshal(raw, &k); err != nil { |
| + return "", false |
| + } |
| + if k == "" { |
| + return "instance", true |
| + } |
| + return k, true |
| +} |
| + |
| +func isTombstoneFields(f map[string]json.RawMessage) bool { |
| + raw, ok := f["retired"] |
| + if !ok { |
| + return false |
| + } |
| + var retired bool |
| + return json.Unmarshal(raw, &retired) == nil && retired |
| +} |
diff --git a/internal/provision/hostsused_test.go b/internal/provision/hostsused_test.go| new file mode 100644 |
| index 000000000..9140f7737 |
| --- /dev/null |
| +++ b/internal/provision/hostsused_test.go |
| @@ -0,0 +1,218 @@ |
| +package provision |
| + |
| +import ( |
| + "bytes" |
| + "context" |
| + "errors" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// The hostname history (nearest-region never-reuse plan, Task 2; spec |
| +// 2026-10-26-nearest-region-without-claims-design.md §1): a create-only mark |
| +// per hostname that may hold data, the data-kind predicate that decides who |
| +// marks, and the mode and floor objects beside the marks. |
| + |
| +func TestMarkHostUsedCreateOnly(t *testing.T) { |
| + s := release.NewDirStore(t.TempDir()) |
| + ctx := context.Background() |
| + at := time.Date(2026, 10, 26, 9, 0, 0, 0, time.UTC) |
| + first := HostUse{Host: "shop.example.com", Account: "bab", App: "shop", Kind: "instance", Source: "create", At: at} |
| + fresh, err := MarkHostUsed(ctx, s, first) |
| + if err != nil || !fresh { |
| + t.Fatalf("first mark = (%v, %v), want (true, nil)", fresh, err) |
| + } |
| + key := HostsUsedKey("shop.example.com") |
| + if key != "control/hosts-used/shop.example.com.json" { |
| + t.Fatalf("HostsUsedKey = %q", key) |
| + } |
| + before, _, err := s.Get(ctx, key) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + second := first |
| + second.Account, second.App, second.At = "other", "other", at.Add(time.Hour) |
| + fresh, err = MarkHostUsed(ctx, s, second) |
| + if err != nil || fresh { |
| + t.Fatalf("second mark = (%v, %v), want (false, nil)", fresh, err) |
| + } |
| + after, _, err := s.Get(ctx, key) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if !bytes.Equal(before, after) { |
| + t.Fatalf("the second mark changed the body:\n%s\n%s", before, after) |
| + } |
| + used, err := HostIsUsed(ctx, s, "shop.example.com") |
| + if err != nil || !used { |
| + t.Fatalf("HostIsUsed = (%v, %v), want (true, nil)", used, err) |
| + } |
| + used, err = HostIsUsed(ctx, s, "other.example.com") |
| + if err != nil || used { |
| + t.Fatalf("HostIsUsed of an unmarked host = (%v, %v), want (false, nil)", used, err) |
| + } |
| +} |
| + |
| +func TestMarkHostUsedRefusesABadHost(t *testing.T) { |
| + s := release.NewDirStore(t.TempDir()) |
| + for _, host := range []string{"", "Shop.example.com", "shop.example.com.", "../x", "a/b"} { |
| + if HostsUsedKey(host) != "" { |
| + t.Errorf("HostsUsedKey(%q) = %q, want empty", host, HostsUsedKey(host)) |
| + } |
| + if fresh, err := MarkHostUsed(context.Background(), s, HostUse{Host: host}); err == nil || fresh { |
| + t.Errorf("MarkHostUsed(%q) = (%v, %v), want an error", host, fresh, err) |
| + } |
| + } |
| +} |
| + |
| +// failingStore fails every call with err. |
| +type failingStore struct { |
| + release.Store |
| + err error |
| +} |
| + |
| +func (f failingStore) Get(context.Context, string) ([]byte, string, error) { return nil, "", f.err } |
| +func (f failingStore) Put(context.Context, string, []byte, string) (string, error) { |
| + return "", f.err |
| +} |
| + |
| +func TestMarkHostUsedStoreError(t *testing.T) { |
| + down := errors.New("the bucket did not answer") |
| + s := failingStore{Store: release.NewDirStore(t.TempDir()), err: down} |
| + fresh, err := MarkHostUsed(context.Background(), s, HostUse{Host: "shop.example.com"}) |
| + if !errors.Is(err, down) || fresh { |
| + t.Fatalf("MarkHostUsed = (%v, %v), want the store's error", fresh, err) |
| + } |
| + if used, err := HostIsUsed(context.Background(), s, "shop.example.com"); !errors.Is(err, down) || used { |
| + t.Fatalf("HostIsUsed = (%v, %v), want the store's error", used, err) |
| + } |
| +} |
| + |
| +func TestDataKindExemptsStaticAndService(t *testing.T) { |
| + for _, c := range []struct { |
| + rec Record |
| + want bool |
| + }{ |
| + {Record{}, true}, |
| + {Record{Kind: "instance"}, true}, |
| + {Record{Kind: "instance", Addrs: []string{"10.0.0.1:8080"}}, true}, |
| + {Record{Kind: "instance", Addr: "10.0.0.1:8080"}, true}, |
| + {Record{Kind: "static"}, false}, |
| + {Record{Kind: "service", Addrs: []string{"10.0.0.1:8080"}}, false}, |
| + } { |
| + if got := c.rec.DataKind(); got != c.want { |
| + t.Errorf("Record{Kind: %q, Addrs: %v, Addr: %q}.DataKind() = %v, want %v", c.rec.Kind, c.rec.Addrs, c.rec.Addr, got, c.want) |
| + } |
| + } |
| +} |
| + |
| +func TestHostsModeDefaultsIncomplete(t *testing.T) { |
| + s := release.NewDirStore(t.TempDir()) |
| + ctx := context.Background() |
| + mode, etag, err := ReadHostsMode(ctx, s) |
| + if err != nil || mode != HostsModeIncomplete || etag != "" { |
| + t.Fatalf("ReadHostsMode of an empty store = (%q, %q, %v), want (incomplete, \"\", nil)", mode, etag, err) |
| + } |
| + tag, err := WriteHostsMode(ctx, s, HostsModeActivating, "") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := WriteHostsMode(ctx, s, HostsModeActive, ""); !errors.Is(err, release.ErrCASConflict) { |
| + t.Fatalf("a create-only mode write over a present one = %v, want a conflict", err) |
| + } |
| + if _, err := WriteHostsMode(ctx, s, HostsModeActive, tag); err != nil { |
| + t.Fatal(err) |
| + } |
| + mode, _, err = ReadHostsMode(ctx, s) |
| + if err != nil || mode != HostsModeActive { |
| + t.Fatalf("ReadHostsMode = (%q, %v), want active", mode, err) |
| + } |
| + if _, err := WriteHostsMode(ctx, s, "sideways", ""); err == nil { |
| + t.Fatal("WriteHostsMode accepted an unknown mode") |
| + } |
| + // An unknown mode in the store is an error, never a default. |
| + if _, err := s.Put(ctx, HostsModeKey, []byte(`{"mode":"sideways"}`), ""); err == nil { |
| + t.Fatal("the mode key was writable create-only while present") |
| + } |
| + _, etag, _ = ReadHostsMode(ctx, s) |
| + if _, err := s.Put(ctx, HostsModeKey, []byte(`{"mode":"sideways"}`), etag); err != nil { |
| + t.Fatal(err) |
| + } |
| + if mode, _, err := ReadHostsMode(ctx, s); err == nil { |
| + t.Fatalf("ReadHostsMode of an unknown mode = %q, want an error", mode) |
| + } |
| + // The mode and floor keys never parse as marks. |
| + if HostsUsedKey("@mode") != "" || HostsUsedKey("@floor") != "" { |
| + t.Fatal("a mode or floor name passes as a host") |
| + } |
| +} |
| + |
| +func TestHostsFloorRoundTrips(t *testing.T) { |
| + s := release.NewDirStore(t.TempDir()) |
| + ctx := context.Background() |
| + f, etag, err := ReadHostsFloor(ctx, s) |
| + if err != nil || f != nil || etag != "" { |
| + t.Fatalf("ReadHostsFloor of an empty store = (%v, %q, %v), want nothing", f, etag, err) |
| + } |
| + if _, err := WriteHostsFloor(ctx, s, HostsFloor{Version: "v0.29.0", Commit: "0123456789abcdef0123456789abcdef01234567"}, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + f, _, err = ReadHostsFloor(ctx, s) |
| + if err != nil || f == nil || f.Version != "v0.29.0" || f.Commit != "0123456789abcdef0123456789abcdef01234567" { |
| + t.Fatalf("ReadHostsFloor = (%+v, %v)", f, err) |
| + } |
| +} |
| + |
| +// TestWriteRecordRefusesKindChange: a record's kind is fixed at create, so |
| +// an exempt record (static, service) can never become a data kind in place |
| +// and skip the mark its create would have written. |
| +func TestWriteRecordRefusesKindChange(t *testing.T) { |
| + s := release.NewDirStore(t.TempDir()) |
| + ctx := context.Background() |
| + key := RecordKey("bab", "shop", "shop.example.com") |
| + body := func(kind string) []byte { |
| + if kind == "-" { |
| + return []byte(`{"schema":1,"host":"shop.example.com","slug":"shop","app":"shop","account":"bab","channel":"stable","created_at":"2026-10-26T09:00:00Z"}`) |
| + } |
| + return []byte(`{"schema":1,"host":"shop.example.com","slug":"shop","app":"shop","account":"bab","channel":"stable","created_at":"2026-10-26T09:00:00Z","kind":"` + kind + `"}`) |
| + } |
| + tag, _, err := WriteRecord(ctx, s, key, []byte(`{}`), body("static"), "") |
| + if err != nil { |
| + t.Fatalf("a create from {} of any kind: %v", err) |
| + } |
| + if _, _, err := WriteRecord(ctx, s, key, body("static"), body("instance"), tag); !errors.Is(err, ErrKindChange) { |
| + t.Fatalf("static to instance = %v, want ErrKindChange", err) |
| + } |
| + if _, _, err := WriteRecord(ctx, s, key, body("static"), body("-"), tag); !errors.Is(err, ErrKindChange) { |
| + t.Fatalf("static to an absent kind = %v, want ErrKindChange", err) |
| + } |
| + if _, _, err := WriteRecord(ctx, s, key, body("static"), body("service"), tag); !errors.Is(err, ErrKindChange) { |
| + t.Fatalf("static to service = %v, want ErrKindChange", err) |
| + } |
| + if raw, _, _ := s.Get(ctx, key); !bytes.Equal(raw, body("static")) { |
| + t.Fatalf("a refused kind change wrote %s", raw) |
| + } |
| + if tag, _, err = WriteRecord(ctx, s, key, body("static"), body("static"), tag); err != nil { |
| + t.Fatalf("same kind: %v", err) |
| + } |
| + // "" and "instance" are one kind. |
| + key2 := RecordKey("bab", "shop", "two.example.com") |
| + tag2, _, err := WriteRecord(ctx, s, key2, []byte(`{}`), body("-"), "") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, _, err := WriteRecord(ctx, s, key2, body("-"), body("instance"), tag2); err != nil { |
| + t.Fatalf("absent kind to instance: %v", err) |
| + } |
| + // A tombstone keeps no kind (TombstoneBody), and retiring a static |
| + // record must still land. |
| + tomb, err := TombstoneBody(body("static")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, _, err := WriteRecord(ctx, s, key, body("static"), tomb, tag); err != nil { |
| + t.Fatalf("tombstoning a static record: %v", err) |
| + } |
| +} |
diff --git a/internal/provision/nearest_region_a_census_test.go b/internal/provision/nearest_region_a_census_test.go| new file mode 100644 |
| index 000000000..458490cf9 |
| --- /dev/null |
| +++ b/internal/provision/nearest_region_a_census_test.go |
| @@ -0,0 +1,35 @@ |
| +package provision |
| + |
| +// Record-write census entries for nearest-region never-reuse merge A (branch |
| +// nearest-region-a, plan docs/superpowers/plans/2026-10-26-nearest-region-never-reuse.md |
| +// Tasks 2-4), layered on regionLabelsWriteCensusInventory (main's newest at |
| +// b1d00ca7). Reviewed by the branch author; the census approval is recorded |
| +// on #280 with the root-read card |
| +// (docs/superpowers/notes/census-proposal-nearest-region-a.md). |
| +// - WriteRecord, re-pinned: it now refuses an in-place write that changes |
| +// the record's kind (checkKindUnchanged), except a create from {} or a |
| +// tombstone. Its one Put is unchanged: still the record-primitive. |
| +// - MarkHostUsed, WriteHostsMode, WriteHostsFloor, new: each Puts one |
| +// object under control/hosts-used/ (a hostname's mark, @mode, @floor). |
| +// No record key, no record body: nonrecord. |
| +func nearestRegionAWriteCensusInventory() []censusEntry { |
| + entries := append([]censusEntry(nil), regionLabelsWriteCensusInventory()...) |
| + replacements := []censusEntry{ |
| + {"internal/provision/hostsused.go", "MarkHostUsed", "nonrecord", "sel:Put", "439f9ca1443f2c815f2ddb18b4732285d236d745fb660de66dc3a175b4532fd3"}, |
| + {"internal/provision/hostsused.go", "WriteHostsFloor", "nonrecord", "sel:Put", "c10e2e2fd57470c81785df3dddd9bb33013b416ce5381e74a9657811ec6b5c79"}, |
| + {"internal/provision/hostsused.go", "WriteHostsMode", "nonrecord", "sel:Put", "21147fa65d21d7a074589ca4ea6cf2ec9852a7ab42ca3acaac429562d8f22146"}, |
| + {"internal/provision/record_sequence.go", "WriteRecord", "record-primitive", "key:IsRecordKey,key:WriteRecord,key:preparedRecordKey,sel:Put", "15806daf27c0266a673aa8c291052b5bc094a8d747ea21254a69e66bd3de585b"}, |
| + } |
| + for _, r := range replacements { |
| + found := false |
| + for i, e := range entries { |
| + if e.File == r.File && e.Unit == r.Unit { |
| + entries[i], found = r, true |
| + } |
| + } |
| + if !found { |
| + entries = append(entries, r) |
| + } |
| + } |
| + return entries |
| +} |
diff --git a/internal/provision/plan9_b8_census_test.go b/internal/provision/plan9_b8_census_test.go| index 9ba7acb51..e3496027a 100644 |
| --- a/internal/provision/plan9_b8_census_test.go |
| +++ b/internal/provision/plan9_b8_census_test.go |
| @@ -366,7 +366,7 @@ func TestPlan9B8RecordWriteCensus(t *testing.T) { |
| if len(got) < 100 { |
| t.Fatalf("census found only %d units under %s; the walk is broken", len(got), root) |
| } |
| - inventory := regionLabelsWriteCensusInventory() |
| + inventory := nearestRegionAWriteCensusInventory() |
| problems := append(censusDiff(inventory, got), censusPolicy(inventory)...) |
| if len(problems) > 0 { |
| t.Fatalf("record-write census rejected %d site(s); update the explicit inventory only after reviewing the source:\n %s", len(problems), strings.Join(problems, "\n ")) |
diff --git a/internal/provision/record_sequence.go b/internal/provision/record_sequence.go| index f8c307f18..d417c0077 100644 |
| --- a/internal/provision/record_sequence.go |
| +++ b/internal/provision/record_sequence.go |
| @@ -116,7 +116,9 @@ type preparedRecord struct { |
| // Legacy absent counters and no claim context retain the exact body bytes. |
| // A before marked by a migration (incarnation_migrating) is refused with |
| // ErrRecordMigrating unless ctx carries WithMigration of that marker; a |
| -// create-only write reads no before and is unaffected. |
| +// create-only write reads no before and is unaffected. A body whose kind |
| +// differs from before's is refused with ErrKindChange, except a create or a |
| +// tombstone (checkKindUnchanged). |
| func WriteRecord(ctx context.Context, s release.Store, key string, before, body []byte, etag string) (string, uint64, error) { |
| if !IsRecordKey(key) { |
| return "", 0, ErrRecordSequence |
| @@ -128,10 +130,15 @@ func WriteRecord(ctx context.Context, s release.Store, key string, before, body |
| if err := checkRecordMarker(ctx, before); err != nil { |
| return "", 0, err |
| } |
| - _, candidate, err := RecordSequence(body) |
| + bodyFields, candidate, err := RecordSequence(body) |
| if err != nil { |
| return "", 0, err |
| } |
| + // A record's kind is fixed at create (nearest-region never-reuse, |
| + // hostsused.go): only a create ({} before) or a tombstone may differ. |
| + if err := checkKindUnchanged(fields, bodyFields); err != nil { |
| + return "", 0, err |
| + } |
| enabled, _ := ctx.Value(recordSequenceKey{}).(bool) |
| _, present := fields["record_seq"] |
| p, nested := ctx.Value(preparedRecordKey{}).(*preparedRecord) |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index f814feea2..d0ba2c42c 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -57,3 +57,4 @@ plan14-root-reads-instance-egress-sizes-328-329-new.tsv aa6c6832fe50f05ab771ebe2 |
| plan14-root-reads-instance-egress-sizes-328-329.tsv c1ab16d1d7eaccb3928a4fd5f74f8fc931221cbd67d5d751a63354984c7b249f |
| plan14-root-reads-region-labels-decisions.tsv b265c2ae74edbaca766d33e085d31a8e7c6f86883d12d0ed4472bd99a7c3278d |
| plan14-root-reads-region-labels.tsv d1e00cfb29d88b7a8e4998b641164e539067a6e1e9e4f52524255343c0c5f9f7 |
| +plan14-root-reads-nearest-region-a.tsv d1e00cfb29d88b7a8e4998b641164e539067a6e1e9e4f52524255343c0c5f9f7 |
diff --git a/internal/provision/testdata/plan14-root-reads-nearest-region-a.tsv b/internal/provision/testdata/plan14-root-reads-nearest-region-a.tsv| new file mode 100644 |
| index 000000000..3dca0d3ec |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-nearest-region-a.tsv |
| @@ -0,0 +1,3 @@ |
| +# Census overlay nearest-region-a, written by census-propose (#369). census-ruling-nearest-region-a, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-nearest-region-a.md. |
| +# 0 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +@coverage internal/provision 5ac7b4911e200ff8cac14e080c294da1c29b2652a19df66a86e71a174408cb66 |