S4 page by cursor: a page hands a kept delete as an entry marked deleted with no value

A reader following pages removes the key, so a deleted key never comes back
alive from a bucket with history.

Builds: design 47 H2 §779, H-A-451 (1)
This commit is contained in:
2026-11-22 02:19:27 +01:00
parent ed281663fd
commit 03e2aca59f
2 changed files with 11 additions and 4 deletions
+5 -1
View File
@@ -25,6 +25,10 @@ type StateEntry struct {
// SeenAgain is set in a page (Page) on a key written again since an earlier page of the same read handed it over,
// so a reader knows this value replaces the one it holds (design 47 H2 §779). Get never sets it.
SeenAgain bool `json:"seen-again,omitempty"`
// Deleted is set in a page (Page) on a key's delete marker, at its sequence, with no value: a reader following pages
// removes the key, so a deleted key never comes back alive from a bucket with history (design 47 H2 §779, H-A-451
// (1)). Get never sets it.
Deleted bool `json:"deleted,omitempty"`
}
// The operations a watch hands over (StateChange.Op).
@@ -122,7 +126,7 @@ type StatePage struct {
// start), as many as fit maxBytes (keys and values; the runtime holds a page to 768 KB at most) or the time budget
// allows, at least one: runtime verb `mesh/state.page`, read from an ordered consumer after the cursor's sequence, so a
// state is read once however many pages it takes (design 47 H2 §779). A key written again between two pages comes
// again in a later page with SeenAgain set. A keep (KeepPrefix) is not an entry and is left out. Hand Next back for the next page. A runtime that does not answer it gives an
// again in a later page with SeenAgain set, and a key deleted comes as an entry with Deleted set and no value. A keep (KeepPrefix) is not an entry and is left out. Hand Next back for the next page. A runtime that does not answer it gives an
// error satisfying errors.Is(err, errors.ErrUnsupported), and the reader asks Get per key instead.
func (s KeptState) Page(cursor string, maxBytes int, budget time.Duration) (StatePage, error) {
p, err := s.page(cursor, maxBytes, budget)
+6 -3
View File
@@ -251,17 +251,20 @@ func TestABundleKeepsAndWatchesStateThroughTheRuntime(t *testing.T) {
t.Fatalf("a take with no ask id answered %v", r)
}
// Design 47 H2 §779: a page read hands the runtime the opaque cursor and answers the cursor that continues it, and a
// key written again since an earlier page comes marked seen-again.
// key written again since an earlier page comes marked seen-again; a kept delete comes as an entry marked deleted with
// no value (H-A-451 (1)).
send(map[string]any{"jsonrpc": "2.0", "id": 43, "method": "tools/call", "params": map[string]any{"name": "page",
"arguments": map[string]any{"cursor": "c.17"}}})
if asked := next(); asked["method"] != "mesh/state.page" || asked["params"].(map[string]any)["cursor"] != "c.17" || asked["params"].(map[string]any)["after"] != nil {
t.Fatalf("asked %v", asked)
} else {
send(map[string]any{"jsonrpc": "2.0", "id": asked["id"], "result": map[string]any{"next": "c.19", "entries": []any{
map[string]any{"key": "a", "value": 1, "revision": 18}, map[string]any{"key": "b", "value": 2, "revision": 19, "seen-again": true}}}})
map[string]any{"key": "a", "value": 1, "revision": 18}, map[string]any{"key": "b", "value": 2, "revision": 19, "seen-again": true},
map[string]any{"key": "c", "revision": 20, "deleted": true}}}})
}
if r := next(); r["id"] != float64(43) || !strings.Contains(fmt.Sprint(r), `"next":"c.19"`) || !strings.Contains(fmt.Sprint(r), `"revision":19,"seen-again":true`) ||
strings.Count(fmt.Sprint(r), "seen-again") != 1 {
strings.Count(fmt.Sprint(r), "seen-again") != 1 || !strings.Contains(fmt.Sprint(r), `"key":"c","value":null,"revision":20,"deleted":true`) ||
strings.Count(fmt.Sprint(r), "deleted") != 1 {
t.Fatalf("the page answered %v", r)
}
if !errors.Is(&refused{code: CodeChanged, message: "x"}, ErrChanged) {