Merge pull request 'nats: a ledger's state and index buckets take the ledger's cap (design 47 H2 H-A-636)' (#751) from fix/ledger-state-cap into main

This commit was merged in pull request #751.
This commit is contained in:
2026-11-24 00:59:22 +00:00
2 changed files with 25 additions and 2 deletions
+18 -1
View File
@@ -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}",
+7 -1
View File
@@ -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
}