From 0f648e26dd5243ec8fc754af5773fcc77bff3f4b Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 24 Nov 2026 01:39:00 +0100 Subject: [PATCH] nats: a ledger's state and index buckets take the ledger's own max-mib The keeper planned a ledger's state bucket and each index bucket with no option, so each was the state default of 64 MiB whatever the ledger asked, while its history and snapshot took max-mib. The delivery gate's ledger asks 1024 and its state bucket filled at 64. The state and index buckets now take the ledger's max-mib and no other of its options; a ledger with none keeps the state default. A raised cap reaches a held bucket through the keeper's existing path for larger settings (check at the first view after a start). The keeper's plan test: the existing ledger row now expects its state and index buckets at the ledger's 16 MiB; a row with max-mib 1024 (and a past-values option that must not reach them) expects 1 GiB; a row with none expects 64 MiB. Design 47 H2's corrections, item 12 (lead answer H-A-636). Builds: design 47 H2 H-A-636 (corrections, item 12) --- modules/nats/internal/keeper/keeper_test.go | 19 ++++++++++++++++++- modules/nats/internal/keeper/plan.go | 8 +++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/modules/nats/internal/keeper/keeper_test.go b/modules/nats/internal/keeper/keeper_test.go index 33593fc00..aaa61f679 100644 --- a/modules/nats/internal/keeper/keeper_test.go +++ b/modules/nats/internal/keeper/keeper_test.go @@ -327,6 +327,11 @@ func entry(name, storage, template string, options map[string]string) catalogue. func TestEachTemplateIsPlannedUnderTheModulesNames(t *testing.T) { ledger := entry("records", catalogue.StorageLedger, catalogue.TemplateLedger, map[string]string{"max-mib": "16"}) ledger.Types = []catalogue.LedgerType{{Name: "decision", Indexes: []catalogue.LedgerIndex{{Name: "by-topic", On: []string{"topic"}}}}} + // A ledger's state and index buckets take its max-mib and no other option of it (design 47 H2's corrections, item 12, H-A-636). + bigLedger := entry("records", catalogue.StorageLedger, catalogue.TemplateLedger, map[string]string{"max-mib": "1024", "history": "5"}) + bigLedger.Types = ledger.Types + plainLedger := entry("records", catalogue.StorageLedger, catalogue.TemplateLedger, nil) + plainLedger.Types = ledger.Types bare := entry("raw", catalogue.StorageStream, "", nil) bare.Configuration = map[string]json.RawMessage{"when-full": json.RawMessage(`"drop-oldest"`), "max-mib": json.RawMessage("8"), "max-age-days": json.RawMessage("3")} forGood := entry("reviews", catalogue.StorageStream, "", nil) @@ -368,9 +373,21 @@ func TestEachTemplateIsPlannedUnderTheModulesNames(t *testing.T) { binding: "objects mesh-knowledge_outputs"}, {name: "ledger", entry: ledger, objects: "stream mesh-knowledge_records [mesh.ledger.mesh-knowledge.records.history.>] {16 MiB, age 0, history 0, new, size 262144}; " + + "key-value mesh-knowledge_records_state {16 MiB, age 0, history 1, new, size 262144}; " + + "key-value mesh-knowledge_records_index-by-topic {16 MiB, age 0, history 1, new, size 262144}; " + + "stream mesh-knowledge_records_snapshot [mesh.ledger.mesh-knowledge.records.snapshot.>] {16 MiB, age 0, history 1, old, size 0}", + binding: "history mesh-knowledge_records on mesh.ledger.mesh-knowledge.records.history, state mesh-knowledge_records_state, indexes map[by-topic:mesh-knowledge_records_index-by-topic], snapshot mesh.ledger.mesh-knowledge.records.snapshot"}, + {name: "ledger naming max-mib 1024 and past values: its state and index buckets at 1 GiB, no other option reaching them (H-A-636)", entry: bigLedger, + objects: "stream mesh-knowledge_records [mesh.ledger.mesh-knowledge.records.history.>] {1024 MiB, age 0, history 0, new, size 262144}; " + + "key-value mesh-knowledge_records_state {1024 MiB, age 0, history 1, new, size 262144}; " + + "key-value mesh-knowledge_records_index-by-topic {1024 MiB, age 0, history 1, new, size 262144}; " + + "stream mesh-knowledge_records_snapshot [mesh.ledger.mesh-knowledge.records.snapshot.>] {1024 MiB, age 0, history 1, old, size 0}", + binding: "history mesh-knowledge_records on mesh.ledger.mesh-knowledge.records.history, state mesh-knowledge_records_state, indexes map[by-topic:mesh-knowledge_records_index-by-topic], snapshot mesh.ledger.mesh-knowledge.records.snapshot"}, + {name: "ledger naming no max-mib: its state and index buckets at the state default (H-A-636)", entry: plainLedger, + objects: "stream mesh-knowledge_records [mesh.ledger.mesh-knowledge.records.history.>] {1024 MiB, age 0, history 0, new, size 262144}; " + "key-value mesh-knowledge_records_state {64 MiB, age 0, history 1, new, size 262144}; " + "key-value mesh-knowledge_records_index-by-topic {64 MiB, age 0, history 1, new, size 262144}; " + - "stream mesh-knowledge_records_snapshot [mesh.ledger.mesh-knowledge.records.snapshot.>] {16 MiB, age 0, history 1, old, size 0}", + "stream mesh-knowledge_records_snapshot [mesh.ledger.mesh-knowledge.records.snapshot.>] {1024 MiB, age 0, history 1, old, size 0}", binding: "history mesh-knowledge_records on mesh.ledger.mesh-knowledge.records.history, state mesh-knowledge_records_state, indexes map[by-topic:mesh-knowledge_records_index-by-topic], snapshot mesh.ledger.mesh-knowledge.records.snapshot"}, {name: "bare stream", entry: bare, objects: "stream mesh-knowledge_raw [mesh.bus.mesh-knowledge.raw.>] {8 MiB, age 259200, history 0, old, size 0}", diff --git a/modules/nats/internal/keeper/plan.go b/modules/nats/internal/keeper/plan.go index 43320154a..c9c8fb2f1 100644 --- a/modules/nats/internal/keeper/plan.go +++ b/modules/nats/internal/keeper/plan.go @@ -229,7 +229,13 @@ func PlanOf(module string, e catalogue.BusStateEntry) (Plan, error) { return Plan{}, err } history.MaxAgeSeconds = days(age) - state, err := stateSettings(options{}) + // The state bucket and each index bucket take the ledger's own max-mib, as its history and snapshot do, and no + // other option of it; with none they keep the state default (design 47 H2's corrections, item 12, H-A-636). + stateOpts := options{} + if raw, ok := opts.raw[catalogue.OptionCapMiB]; ok { + stateOpts.raw = map[string]json.RawMessage{catalogue.OptionCapMiB: raw} + } + state, err := stateSettings(stateOpts) if err != nil { return Plan{}, err } -- 2.54.0