R1-1: a page hands a kept delete, so a deleted key never comes back alive

The page watch ignored delete markers, so a reader following pages of a bucket with history kept
a deleted key's last value. A kept delete (a purge reads as one) is now an entry deleted: true with
no value at its sequence, seen-again like any message (review round 1, finding 1, state.go:375).

Builds: design 47 H2 §779, H-A-451 (1), H-A-382 (2)
This commit is contained in:
2026-11-22 02:19:43 +01:00
parent 026fb780d6
commit cab76319b8
2 changed files with 35 additions and 8 deletions
+14 -5
View File
@@ -40,14 +40,18 @@ type StateIssued struct {
// StateEntry is one key's current value.
type StateEntry struct {
Key string `json:"key"`
Value json.RawMessage `json:"value"`
Key string `json:"key"`
// Value is none on a delete a page hands (Deleted).
Value json.RawMessage `json:"value,omitempty"`
Revision uint64 `json:"revision"`
// At is when the bus wrote this value (the entry's created time), as stdio.StateEntry.At reads it.
At time.Time `json:"at,omitzero"`
// SeenAgain is set in a page on a value the bus wrote after the read reached its bucket, so a reader knows it replaces
// any value it holds for the key (design 47 H2 §779, H-A-382).
SeenAgain bool `json:"seen-again,omitempty"`
// Deleted is set in a page on a key's kept delete (a purge reads as one), handed at its sequence with no value, so a
// reader following pages removes the key and a deleted key never comes back alive (design 47 H2 §779, H-A-451 (1)).
Deleted bool `json:"deleted,omitempty"`
}
// StateChange is one change a watch delivers: a key put, deleted, or expired (its own time to live, or the
@@ -372,7 +376,8 @@ func (r *pageRead) bucket(kv jetstream.KeyValue, from pageCursor, reached bool)
}
from.mark = bs.StreamInfo().State.LastSeq
}
opts := []jetstream.WatchOpt{jetstream.IncludeHistory(), jetstream.IgnoreDeletes()}
// Deletes are handed too: a page that dropped them would bring a deleted key with history back alive (H-A-451 (1)).
opts := []jetstream.WatchOpt{jetstream.IncludeHistory()}
if from.after > 0 {
opts = append(opts, jetstream.ResumeFromRevision(from.after+1))
}
@@ -399,14 +404,18 @@ func (r *pageRead) bucket(kv jetstream.KeyValue, from pageCursor, reached bool)
}
e = got
}
value := valueOf(e.Value())
deleted := e.Operation() != jetstream.KeyValuePut
var value json.RawMessage
if !deleted {
value = valueOf(e.Value())
}
full := len(r.page.Entries) > 0 && (r.size+len(e.Key())+len(value) > r.maxBytes || PageClock().Sub(r.started) >= r.budget)
if full {
r.page.Next = from.String()
return nil
}
r.page.Entries = append(r.page.Entries, StateEntry{Key: e.Key(), Value: value, Revision: e.Revision(), At: e.Created().UTC(),
SeenAgain: e.Revision() > from.mark})
SeenAgain: e.Revision() > from.mark, Deleted: deleted})
r.size += len(e.Key()) + len(value)
from.after = e.Revision()
}