G14 ledger-lifetimes-planned: a ledger giving ended-days is planned with lifetimes, its snapshot store refuses when full, its binding says ended-days once the bus holds them
The bus module plans a ledger whose own configuration gives ended-days with a lifetime per key on its state and index buckets and a lifetime per message on its snapshot store, reads a held stream's lifetime back, plans every ledger's snapshot store to refuse when full, names ended-days in the binding only once every object that asks a lifetime holds one, and says created again when the binding it would say differs from the one it last said (Made.Said). Builds: design 47 H2 H-A-634 (3), H-A-636, H-A-685 (1) (2), H-A-687 (1) (5)
This commit is contained in:
@@ -638,6 +638,25 @@ func TestTheBusModuleRunsWhole(t *testing.T) {
|
||||
onBranch("main", "sb", 6, nil)
|
||||
eventually(t, "sb's plan deleted", func() bool { _, _, found, _ := store.Get(keeper.StatePlans, "sb"); return !found })
|
||||
})
|
||||
// Design 47 H2 H-A-634 (3), H-A-687 (1): a ledger giving ended-days is made with a lifetime per key on its state and
|
||||
// index buckets and a lifetime per message on its snapshot store, which refuses when full.
|
||||
t.Run("a ledger giving ended-days is made with lifetimes and a snapshot store that refuses when full", func(t *testing.T) {
|
||||
ending := entry("records", "ledger", "ledger", map[string]string{"max-mib": "4"})
|
||||
ending.Configuration = map[string]json.RawMessage{"ended-days": json.RawMessage("30"), "max-age-days": json.RawMessage("90")}
|
||||
ending.Types = []catalogue.LedgerType{{Name: "record", EndsWith: "ended", Schema: map[string]catalogue.LedgerField{"ended": {Type: "map"}},
|
||||
Operations: []catalogue.LedgerOperation{{Name: "end", Effect: catalogue.EffectSetFields, Fields: []string{"ended"}}}}}
|
||||
accepted("ld", 9, ending)
|
||||
eventually(t, "created ld records", saidHas("created ld records"))
|
||||
if info, ok := held("ld_records_snapshot"); !ok || !info.Config.AllowMsgTTL || info.Config.Discard != jetstream.DiscardNew {
|
||||
t.Errorf("the snapshot store is %+v: a lifetime per message, refusing when full", info)
|
||||
}
|
||||
if info, ok := held("KV_ld_records_state"); !ok || !info.Config.AllowMsgTTL {
|
||||
t.Errorf("the state bucket is %+v: a lifetime per key", info)
|
||||
}
|
||||
if got := k.Held()["ld"].Made["records"].Plan.Binding.EndedDays; got != 30 {
|
||||
t.Errorf("the binding names ended-days %d, want 30: the bus holds every lifetime", got)
|
||||
}
|
||||
})
|
||||
t.Run("nats_first_view_again asks at once and records the hand act", func(t *testing.T) {
|
||||
raw, _ := json.Marshal(keeper.Request{ID: "r3", Verb: keeper.VerbFirstViewAgain, Why: "a verdict thought missed", Caller: "person.jo"})
|
||||
_, _ = store.Put(keeper.StateRequests, "r3", raw)
|
||||
|
||||
@@ -80,6 +80,7 @@ func SettingsOf(kind string, c jetstream.StreamConfig) Settings {
|
||||
case KindObjects:
|
||||
s.DuplicatesSeconds = 0
|
||||
default:
|
||||
s.KeyTTL = c.AllowMsgTTL
|
||||
if c.MaxMsgsPerSubject > 0 {
|
||||
s.History = c.MaxMsgsPerSubject
|
||||
}
|
||||
@@ -119,7 +120,8 @@ func limitMarker(on bool) time.Duration {
|
||||
func streamConfig(o Object) jetstream.StreamConfig {
|
||||
c := jetstream.StreamConfig{Name: o.Name, Subjects: o.Subjects, Retention: jetstream.LimitsPolicy,
|
||||
MaxBytes: o.Settings.MaxBytes, MaxAge: time.Duration(o.Settings.MaxAgeSeconds) * time.Second,
|
||||
Discard: jetstream.DiscardOld, Storage: jetstream.FileStorage, Replicas: 1, MaxMsgs: -1, MaxMsgsPerSubject: -1}
|
||||
Discard: jetstream.DiscardOld, Storage: jetstream.FileStorage, Replicas: 1, MaxMsgs: -1, MaxMsgsPerSubject: -1,
|
||||
AllowMsgTTL: o.Settings.KeyTTL}
|
||||
if o.Settings.Discard == DiscardNew {
|
||||
c.Discard = jetstream.DiscardNew
|
||||
}
|
||||
|
||||
@@ -174,6 +174,9 @@ type Made struct {
|
||||
Fill int64 `json:"fill,omitempty"`
|
||||
// Orphaned says no manifest asks for it any more: it goes only by drop.
|
||||
Orphaned bool `json:"orphaned,omitempty"`
|
||||
// Said is the binding its last `created` or `recreated` said (design 47 H2 H-A-685 (2)): a binding the keeper would say
|
||||
// that differs from it is said again with `created`. Absent where none was kept, which differs from any.
|
||||
Said *membership.BusBinding `json:"said,omitempty"`
|
||||
}
|
||||
|
||||
// Status is the keeper's own state, KeyStatus: what its health tool reads.
|
||||
@@ -813,7 +816,11 @@ func (k *Keeper) ensureMade(held *Asked, m *Made, create bool) {
|
||||
if wasRefused {
|
||||
k.clear(conditionRefused, held.Module, m.Plan.Local)
|
||||
}
|
||||
if !m.Created || madeLater {
|
||||
// The binding names ended-days only once the bus holds every object that asks a lifetime with one (design 47 H2 H-A-685
|
||||
// (1)); one that differs from the binding last said is said again (H-A-685 (2)), by an entry the keeper creates alone.
|
||||
m.Plan.Binding = bindingHeld(m.Plan, holds)
|
||||
changed := create && m.Created && !sameBinding(m.Said, m.Plan.Binding)
|
||||
if !m.Created || madeLater || changed {
|
||||
// Marked created only once `created` is said whole: the grants part binds on it, so one the bus did not take is
|
||||
// said again on the backoff (Waiting), never marked made and forgotten.
|
||||
if err := k.sayNow(EventCreated, m.Plan, held.Revision, "", asked, holds); err != nil {
|
||||
@@ -821,6 +828,8 @@ func (k *Keeper) ensureMade(held *Asked, m *Made, create bool) {
|
||||
return
|
||||
}
|
||||
m.Created = true
|
||||
said := m.Plan.Binding
|
||||
m.Said = &said
|
||||
}
|
||||
drift := strings.Join(drifts, "; ")
|
||||
switch {
|
||||
@@ -837,6 +846,43 @@ func (k *Keeper) ensureMade(held *Asked, m *Made, create bool) {
|
||||
}
|
||||
}
|
||||
|
||||
// endedDaysOf is the ended-days a ledger entry's own configuration gives, 0 where it gives none.
|
||||
func endedDaysOf(e catalogue.BusStateEntry) int {
|
||||
n, err := options{raw: e.Configuration}.int(catalogue.ConfigEndedDays, 0)
|
||||
if err != nil || n < 1 {
|
||||
return 0
|
||||
}
|
||||
return int(n)
|
||||
}
|
||||
|
||||
// bindingHeld is the plan's binding as the keeper says it given what the bus holds: it names ended-days only when the
|
||||
// ledger's configuration gives it and every object the plan asks a lifetime of, a bucket's key or a stream's message, is held
|
||||
// with one (design 47 H2 H-A-685 (1)).
|
||||
func bindingHeld(p Plan, holds map[string]Settings) membership.BusBinding {
|
||||
b := p.Binding
|
||||
b.EndedDays = endedDaysOf(p.Entry)
|
||||
if b.EndedDays == 0 {
|
||||
return b
|
||||
}
|
||||
for _, o := range p.Objects {
|
||||
if o.Settings.KeyTTL && !holds[o.Name].KeyTTL {
|
||||
b.EndedDays = 0
|
||||
break
|
||||
}
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// sameBinding is whether the binding last said is the one the keeper would say; none said differs from any.
|
||||
func sameBinding(said *membership.BusBinding, b membership.BusBinding) bool {
|
||||
if said == nil {
|
||||
return false
|
||||
}
|
||||
a, _ := json.Marshal(*said)
|
||||
c, _ := json.Marshal(b)
|
||||
return string(a) == string(c)
|
||||
}
|
||||
|
||||
// CheckAll compares every entry the keeper holds with the bus, making what is missing (design 25 § 12.2's check at
|
||||
// start) and making again what waits; it answers what it found, one line per entry.
|
||||
func (k *Keeper) CheckAll() []CheckLine {
|
||||
|
||||
@@ -332,6 +332,13 @@ func TestEachTemplateIsPlannedUnderTheModulesNames(t *testing.T) {
|
||||
bigLedger.Types = ledger.Types
|
||||
plainLedger := entry("records", catalogue.StorageLedger, catalogue.TemplateLedger, nil)
|
||||
plainLedger.Types = ledger.Types
|
||||
// A ledger whose own configuration gives ended-days: its state and index buckets with a lifetime per key, its snapshot
|
||||
// store refusing when full with a lifetime per message (design 47 H2 H-A-634 (3), H-A-687 (1)).
|
||||
endingLedger := entry("records", catalogue.StorageLedger, catalogue.TemplateLedger, map[string]string{"max-mib": "1024"})
|
||||
endingLedger.Types = ledger.Types
|
||||
endingLedger.Configuration = map[string]json.RawMessage{"max-age-days": json.RawMessage("90"), "ended-days": json.RawMessage("30")}
|
||||
badEnding := endingLedger
|
||||
badEnding.Configuration = map[string]json.RawMessage{"ended-days": json.RawMessage("3651")}
|
||||
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)
|
||||
@@ -375,20 +382,27 @@ func TestEachTemplateIsPlannedUnderTheModulesNames(t *testing.T) {
|
||||
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}",
|
||||
"stream mesh-knowledge_records_snapshot [mesh.ledger.mesh-knowledge.records.snapshot.>] {16 MiB, age 0, history 1, new, 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}",
|
||||
"stream mesh-knowledge_records_snapshot [mesh.ledger.mesh-knowledge.records.snapshot.>] {1024 MiB, age 0, history 1, new, 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.>] {1024 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, new, 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 giving ended-days 30 and max-age-days 90: key-ttl on its state, index and snapshot, its history aged 90 days, the binding naming ended-days (H-A-634 (3), H-A-687)", entry: endingLedger,
|
||||
objects: "stream mesh-knowledge_records [mesh.ledger.mesh-knowledge.records.history.>] {1024 MiB, age 7776000, history 0, new, size 262144}; " +
|
||||
"key-value mesh-knowledge_records_state {1024 MiB, age 0, history 1, new, size 262144, key-ttl}; " +
|
||||
"key-value mesh-knowledge_records_index-by-topic {1024 MiB, age 0, history 1, new, size 262144, key-ttl}; " +
|
||||
"stream mesh-knowledge_records_snapshot [mesh.ledger.mesh-knowledge.records.snapshot.>] {1024 MiB, age 0, history 1, new, size 0, key-ttl}",
|
||||
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, ended-days 30"},
|
||||
{name: "a ledger giving ended-days past 3650", entry: badEnding, refused: "not a whole number of days from 1 to 3650"},
|
||||
{name: "bare stream", entry: bare,
|
||||
objects: "stream mesh-knowledge_raw [mesh.bus.mesh-knowledge.raw.>] {8 MiB, age 259200, history 0, old, size 0}",
|
||||
binding: "stream mesh-knowledge_raw on mesh.bus.mesh-knowledge.raw"},
|
||||
@@ -428,6 +442,9 @@ func TestEachTemplateIsPlannedUnderTheModulesNames(t *testing.T) {
|
||||
if s.WorkQueue {
|
||||
w += fmt.Sprintf(", work-queue, duplicates %d", s.DuplicatesSeconds)
|
||||
}
|
||||
if s.KeyTTL {
|
||||
w += ", key-ttl"
|
||||
}
|
||||
objs = append(objs, w+"}")
|
||||
}
|
||||
if got := strings.Join(objs, "; "); got != row.objects {
|
||||
@@ -438,6 +455,9 @@ func TestEachTemplateIsPlannedUnderTheModulesNames(t *testing.T) {
|
||||
switch {
|
||||
case b.History != "":
|
||||
binding = fmt.Sprintf("history %s on %s, state %s, indexes %v, snapshot %s", b.History, b.Subject, b.State, b.Indexes, b.Snapshot)
|
||||
if b.EndedDays > 0 {
|
||||
binding += fmt.Sprintf(", ended-days %d", b.EndedDays)
|
||||
}
|
||||
case b.Stream != "":
|
||||
binding = fmt.Sprintf("stream %s on %s", b.Stream, b.Subject)
|
||||
case b.Bucket != "":
|
||||
@@ -697,6 +717,61 @@ func TestTheKeeperMakesWhatAVerdictAsksForAndSaysIt(t *testing.T) {
|
||||
t.Errorf("said %v %v: cleared once asked as held", out.events, out.conds)
|
||||
}
|
||||
}},
|
||||
// Design 47 H2 H-A-634 (3), H-A-685 (1) (2), H-A-687 (1) (5): a held snapshot store that drops its oldest differs from one
|
||||
// that refuses; a binding names ended-days only once every object that asks a lifetime holds one, and is said again
|
||||
// when it differs from the one last said.
|
||||
{"a ledger's binding names ended-days once its held objects allow lifetimes, and a changed binding is said again (H-A-685)", func(t *testing.T, k *Keeper, bus *fakeBus, out *said) {
|
||||
plain := entry("records", catalogue.StorageLedger, catalogue.TemplateLedger, map[string]string{"max-mib": "16"})
|
||||
plain.Types = []catalogue.LedgerType{{Name: "record", Operations: []catalogue.LedgerOperation{{Name: "open"}}}}
|
||||
k.Heard(Accepted{Module: "m", Revision: 1, BusState: []catalogue.BusStateEntry{plain}})
|
||||
ending := plain
|
||||
ending.Configuration = map[string]json.RawMessage{"ended-days": json.RawMessage("30")}
|
||||
out.reset()
|
||||
k.Heard(Accepted{Module: "m", Revision: 2, BusState: []catalogue.BusStateEntry{ending}})
|
||||
drift := k.Held()["m"].Made["records"].Drift
|
||||
if !strings.Contains(drift, "m_records_state: key-ttl asked true, held false") || !strings.Contains(drift, "m_records_snapshot") ||
|
||||
fmt.Sprint(out.events) != "[drifted m records]" || out.bodies[0].Binding.EndedDays != 0 {
|
||||
t.Fatalf("drift %q, said %v %+v: lifetimes asked of objects that allow none drift, the binding naming no ended-days", drift, out.events, out.bodies)
|
||||
}
|
||||
// The bus now allows them (as a recreate in place leaves them): the binding is said again with ended-days.
|
||||
for _, name := range []string{"KV_m_records_state", "m_records_snapshot"} {
|
||||
s := bus.held[name]
|
||||
s.KeyTTL = true
|
||||
bus.held[name] = s
|
||||
}
|
||||
s := bus.held["m_records_snapshot"]
|
||||
s.Discard = DiscardNew
|
||||
bus.held["m_records_snapshot"] = s
|
||||
out.reset()
|
||||
k.CheckAll()
|
||||
if fmt.Sprint(out.events) != "[created m records drift-cleared m records]" || out.bodies[0].Binding.EndedDays != 30 {
|
||||
t.Fatalf("said %v (%q): the drift cleared and created said again naming ended-days 30", out.events, k.Held()["m"].Made["records"].Drift)
|
||||
}
|
||||
out.reset()
|
||||
k.CheckAll()
|
||||
if len(out.events) != 0 {
|
||||
t.Errorf("said %v: a binding the same as the one said is said no more", out.events)
|
||||
}
|
||||
// A type gaining an operation changes the binding: created again with it, and no recreate.
|
||||
more := ending
|
||||
more.Types = []catalogue.LedgerType{{Name: "record", Operations: []catalogue.LedgerOperation{{Name: "open"}, {Name: "end"}}}}
|
||||
k.Heard(Accepted{Module: "m", Revision: 3, BusState: []catalogue.BusStateEntry{more}})
|
||||
if fmt.Sprint(out.events) != "[created m records]" || len(out.bodies[0].Binding.Types[0].Operations) != 2 || len(bus.deleted) != 0 {
|
||||
t.Errorf("said %v %+v deleted %v: created again with the new operation", out.events, out.bodies, bus.deleted)
|
||||
}
|
||||
}},
|
||||
{"a held snapshot store that drops its oldest differs from one that refuses when full (H-A-687 (1))", func(t *testing.T, k *Keeper, bus *fakeBus, out *said) {
|
||||
ledger := entry("records", catalogue.StorageLedger, catalogue.TemplateLedger, map[string]string{"max-mib": "16"})
|
||||
k.Heard(Accepted{Module: "m", Revision: 1, BusState: []catalogue.BusStateEntry{ledger}})
|
||||
s := bus.held["m_records_snapshot"]
|
||||
s.Discard = DiscardOld
|
||||
bus.held["m_records_snapshot"] = s
|
||||
out.reset()
|
||||
k.CheckAll()
|
||||
if d := k.Held()["m"].Made["records"].Drift; !strings.Contains(d, "m_records_snapshot: discard asked new, held old") || fmt.Sprint(out.events) != "[drifted m records]" {
|
||||
t.Errorf("drift %q, said %v: a snapshot store that drops its oldest drifts", d, out.events)
|
||||
}
|
||||
}},
|
||||
{"a plan whose caps pass the account's storage limit is refused, naming the sum and the limit, and the caps made stay (§547)", func(t *testing.T, k *Keeper, bus *fakeBus, out *said) {
|
||||
// drafts: 64 MiB state + 16 MiB objects = 80 MiB; log: 1024 MiB.
|
||||
bus.limits = Limits{AccountBytes: 100 * MiB}
|
||||
|
||||
@@ -37,6 +37,8 @@ const (
|
||||
ValueMost = 256 << 10
|
||||
EntryMost = 256 << 10
|
||||
DefaultCapMiB = 1024
|
||||
// EndedDaysMost is the most whole days a ledger's ended-days gives (design 47 H2 H-A-634 (3)).
|
||||
EndedDaysMost = 3650
|
||||
EventsDays = 7
|
||||
)
|
||||
|
||||
@@ -83,7 +85,7 @@ type Settings struct {
|
||||
MaxMsgSize int64 `json:"max-msg-size,omitempty"`
|
||||
// DuplicatesSeconds is a work queue's duplicate window.
|
||||
DuplicatesSeconds int64 `json:"duplicates-seconds,omitempty"`
|
||||
// KeyTTL says a bucket's key may be given a lifetime of its own.
|
||||
// KeyTTL says a bucket's key, or a stream's message, may be given a lifetime of its own.
|
||||
KeyTTL bool `json:"key-ttl,omitempty"`
|
||||
}
|
||||
|
||||
@@ -229,6 +231,15 @@ func PlanOf(module string, e catalogue.BusStateEntry) (Plan, error) {
|
||||
return Plan{}, err
|
||||
}
|
||||
history.MaxAgeSeconds = days(age)
|
||||
// A ledger whose own configuration gives ended-days has its ended instances' keys go by the bus's lifetime per key
|
||||
// and per message (design 47 H2 H-A-634 (3), ADR 0690 §2): whole days, 1 to 3650.
|
||||
endedDays, err := conf.int(catalogue.ConfigEndedDays, 0)
|
||||
if err != nil {
|
||||
return Plan{}, err
|
||||
}
|
||||
if _, given := conf.raw[catalogue.ConfigEndedDays]; given && (endedDays < 1 || endedDays > EndedDaysMost) {
|
||||
return Plan{}, fmt.Errorf("the configuration %s of %q is %d, not a whole number of days from 1 to %d", catalogue.ConfigEndedDays, e.Name, endedDays, EndedDaysMost)
|
||||
}
|
||||
// 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{}
|
||||
@@ -239,12 +250,14 @@ func PlanOf(module string, e catalogue.BusStateEntry) (Plan, error) {
|
||||
if err != nil {
|
||||
return Plan{}, err
|
||||
}
|
||||
state.KeyTTL = endedDays > 0
|
||||
subject := buscompose.LedgerHistorySubject(module, e.Name)
|
||||
snapshot := buscompose.LedgerSnapshotSubject(module, e.Name)
|
||||
p.Binding.History, p.Binding.Subject = name, subject
|
||||
p.Binding.State = name + "_state"
|
||||
p.Binding.Snapshot = snapshot
|
||||
p.Binding.Types = e.Types
|
||||
p.Binding.EndedDays = int(endedDays)
|
||||
p.Objects = []Object{
|
||||
{Kind: KindStream, Name: name, Subjects: []string{subject + ".>"}, Settings: history},
|
||||
{Kind: KindBucket, Name: p.Binding.State, Settings: state},
|
||||
@@ -266,9 +279,11 @@ func PlanOf(module string, e catalogue.BusStateEntry) (Plan, error) {
|
||||
p.Binding.Indexes[ix] = name + "_index-" + ix
|
||||
p.Objects = append(p.Objects, Object{Kind: KindBucket, Name: p.Binding.Indexes[ix], Settings: state})
|
||||
}
|
||||
// The snapshot: the latest state per instance, never expiring (ADR 0597 §8), one message per subject.
|
||||
// The snapshot: the latest state per instance, one message per subject, refusing when full at the ledger's cap (ADR 0595
|
||||
// §3, ADR 0597 §8, ADR 0690 §2: a snapshot goes only with its key), with a lifetime per message where the ledger gives
|
||||
// ended-days (design 47 H2 H-A-634 (3), H-A-687 (1)).
|
||||
p.Objects = append(p.Objects, Object{Kind: KindStream, Name: name + "_snapshot", Subjects: []string{snapshot + ".>"},
|
||||
Settings: Settings{MaxBytes: history.MaxBytes, History: 1, Discard: DiscardOld}})
|
||||
Settings: Settings{MaxBytes: history.MaxBytes, History: 1, Discard: DiscardNew, KeyTTL: endedDays > 0}})
|
||||
case e.Storage == catalogue.StorageStream && e.Template == "":
|
||||
// A bare stream: its own configuration, which must give when full, a cap and an age (design 25 § 12.1).
|
||||
var full string
|
||||
|
||||
@@ -281,6 +281,14 @@ func (k *Keeper) act(r *Request) (string, error) {
|
||||
}
|
||||
wasDrift := m.Drift != ""
|
||||
m.Drift = ""
|
||||
// Every object is as asked again, so its binding names ended-days as the ledger's configuration gives it (H-A-685 (1)).
|
||||
madeAs := map[string]Settings{}
|
||||
for _, o := range m.Plan.Objects {
|
||||
madeAs[o.Name] = o.Settings
|
||||
}
|
||||
m.Plan.Binding = bindingHeld(m.Plan, madeAs)
|
||||
said := m.Plan.Binding
|
||||
m.Said = &said
|
||||
held.Made[r.Local] = m
|
||||
k.write(held)
|
||||
k.emit(EventRecreated, m.Plan, held.Revision, r.Why, nil, nil)
|
||||
|
||||
Reference in New Issue
Block a user