diff --git a/modules/nats/internal/keeper/keeper_test.go b/modules/nats/internal/keeper/keeper_test.go index 90d499d5a..381b2cbc5 100644 --- a/modules/nats/internal/keeper/keeper_test.go +++ b/modules/nats/internal/keeper/keeper_test.go @@ -341,6 +341,9 @@ func TestEachTemplateIsPlannedUnderTheModulesNames(t *testing.T) { {name: "state", entry: entry("drafts", catalogue.StorageKeyValue, catalogue.TemplateState, map[string]string{"history": "5"}), objects: "key-value mesh-knowledge_drafts {64 MiB, age 0, history 5, new, size 262144}; object-store mesh-knowledge_drafts-objects {16 MiB, age 0, history 0, new, size 0}", binding: "bucket mesh-knowledge_drafts"}, + {name: "state naming max-mib (A-283)", entry: entry("drafts", catalogue.StorageKeyValue, catalogue.TemplateState, map[string]string{"max-mib": "8"}), + objects: "key-value mesh-knowledge_drafts {8 MiB, age 0, history 1, new, size 262144}; object-store mesh-knowledge_drafts-objects {16 MiB, age 0, history 0, new, size 0}", + binding: "bucket mesh-knowledge_drafts"}, {name: "state naming objects-max-mib (ยง591)", entry: entry("drafts", catalogue.StorageKeyValue, catalogue.TemplateState, map[string]string{"objects-max-mib": "512"}), objects: "key-value mesh-knowledge_drafts {64 MiB, age 0, history 1, new, size 262144}; object-store mesh-knowledge_drafts-objects {512 MiB, age 0, history 0, new, size 0}", binding: "bucket mesh-knowledge_drafts"}, diff --git a/modules/nats/internal/keeper/plan.go b/modules/nats/internal/keeper/plan.go index 5880e14bc..396f8b82c 100644 --- a/modules/nats/internal/keeper/plan.go +++ b/modules/nats/internal/keeper/plan.go @@ -315,7 +315,14 @@ func stateSettings(o options) (Settings, error) { } return Settings{}, fmt.Errorf("the option %s (one bucket per machine) is not made by the bus module yet: the module keeps one bucket", catalogue.OptionPerMachine) } - return Settings{MaxBytes: StateCap, MaxAgeSeconds: ttl, History: history, Discard: DiscardNew, MaxMsgSize: ValueMost, KeyTTL: keyTTL}, nil + capMiB, err := o.int(catalogue.OptionCapMiB, StateCap/MiB) + if err != nil { + return Settings{}, err + } + if capMiB <= 0 { + return Settings{}, fmt.Errorf("the option %s of a state is %d, not a size above 0", catalogue.OptionCapMiB, capMiB) + } + return Settings{MaxBytes: capMiB * MiB, MaxAgeSeconds: ttl, History: history, Discard: DiscardNew, MaxMsgSize: ValueMost, KeyTTL: keyTTL}, nil } func logSettings(o options) (Settings, error) {