diff --git a/go/state.go b/go/state.go index bfcd6fe9..92883f83 100644 --- a/go/state.go +++ b/go/state.go @@ -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) diff --git a/go/state_test.go b/go/state_test.go index 6a0ea03c..8ed8b89b 100644 --- a/go/state_test.go +++ b/go/state_test.go @@ -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) {