S4 page by cursor: a state page continues from an opaque cursor in sequence order
The runtime's mesh/state.page takes the cursor the page before answered as next, so a state is read once however many pages it takes; a key written again since an earlier page comes marked seen-again. Builds: design 47 H2 §779
This commit is contained in:
+14
-7
@@ -22,6 +22,9 @@ type StateEntry struct {
|
||||
Value json.RawMessage `json:"value"`
|
||||
Revision uint64 `json:"revision"`
|
||||
At time.Time `json:"at,omitzero"`
|
||||
// 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"`
|
||||
}
|
||||
|
||||
// The operations a watch hands over (StateChange.Op).
|
||||
@@ -107,18 +110,22 @@ func (s KeptState) Get(key string) (*StateEntry, error) {
|
||||
return &e, json.Unmarshal(raw, &e)
|
||||
}
|
||||
|
||||
// StatePage is the values of one bulk read: those after a key, in key order, and the key to ask after for the rest.
|
||||
// StatePage is the values of one page of a read: those the bus wrote after the cursor's sequence, in sequence order,
|
||||
// and the cursor to hand back for the rest (design 47 H2 §779).
|
||||
type StatePage struct {
|
||||
Entries []StateEntry `json:"entries"`
|
||||
// Next is the last key of Entries when more follow it, else empty.
|
||||
// Next is the opaque cursor that continues the read, empty at its end.
|
||||
Next string `json:"next,omitempty"`
|
||||
}
|
||||
|
||||
// Page is the current values in key order after the key `after`, as many as fit maxBytes (keys and values) or the time budget allows, at least
|
||||
// one: one request for many values, where Get is one request each. 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(after string, maxBytes int, budget time.Duration) (StatePage, error) {
|
||||
raw, err := s.ask("page", map[string]any{"after": after, "max_bytes": maxBytes, "budget_ms": budget.Milliseconds()})
|
||||
// Page is one page of the state's values, in the order the bus wrote them, after the opaque cursor (empty: from the
|
||||
// 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. 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) {
|
||||
raw, err := s.ask("page", map[string]any{"cursor": cursor, "max_bytes": maxBytes, "budget_ms": budget.Milliseconds()})
|
||||
if err != nil {
|
||||
return StatePage{}, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user