DMC-14: a state put answers its bucket's fill beside its revision
mesh/state.put answers {"revision", "fill": {"count", "bytes", "max_bytes"}}, buscalls.Fill's
form, read from the bound stream's info once per put, since the key-value put answers no figures;
a bundle's prune reads it from the put.
Builds: design 47 H2 DMC-14, H-A-350, H-A-386
This commit is contained in:
@@ -1264,7 +1264,12 @@ func (b *moduleBus) State(verb string, params json.RawMessage) (json.RawMessage,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
answer = map[string]any{"revision": revision}
|
||||
// With the bucket's fill, so a bundle's prune reads it from the put (design 47 H2 DMC-14, H-A-386).
|
||||
fill, err := conn.StateFill(b.module, asked.State)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s was put at revision %d, but its state's fill is not read: %w", asked.Key, revision, err)
|
||||
}
|
||||
answer = map[string]any{"revision": revision, "fill": fill}
|
||||
case "delete":
|
||||
if err := conn.StateDelete(b.module, asked.State, asked.Key); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
||||
|
||||
"github.com/novox/mesh-tools/node-tools/internal/bus"
|
||||
"github.com/novox/mesh-tools/node-tools/internal/launch"
|
||||
mt "github.com/novox/mesh-tools/node-tools/internal/meshtest"
|
||||
@@ -71,16 +73,26 @@ func TestAKeysHistoryIsEveryValueKeptOldestFirst(t *testing.T) {
|
||||
owner, reader, _ := historyBuses(t)
|
||||
before := time.Now().Add(-time.Second)
|
||||
var revisions []uint64
|
||||
for _, v := range []string{`{"state":"open"}`, `{"state":"fixing"}`, `{"state":"resolved"}`} {
|
||||
// each put answers the bucket's fill with its revision, buscalls.Fill's form (design 47 H2 DMC-14, H-A-386): the messages
|
||||
// kept (every value of the key, the bucket keeping 8), their bytes, and no cap (0)
|
||||
var bytes uint64
|
||||
for i, v := range []string{`{"state":"open"}`, `{"state":"fixing"}`, `{"state":"resolved"}`} {
|
||||
raw, err := ask(owner, "put", map[string]any{"state": "issues", "key": "502", "value": json.RawMessage(v)})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var r struct {
|
||||
Revision uint64 `json:"revision"`
|
||||
Revision uint64 `json:"revision"`
|
||||
Fill *buscalls.Fill `json:"fill"`
|
||||
}
|
||||
_ = json.Unmarshal(raw, &r)
|
||||
revisions = append(revisions, r.Revision)
|
||||
if r.Fill == nil || r.Fill.Count != uint64(i+1) || r.Fill.Bytes <= bytes || r.Fill.MaxBytes != 0 {
|
||||
t.Errorf("put %d answered %s, want its revision and the fill of %d messages, more bytes than %d, no cap", i, raw, i+1, bytes)
|
||||
}
|
||||
if r.Fill != nil {
|
||||
bytes = r.Fill.Bytes
|
||||
}
|
||||
}
|
||||
if _, err := ask(owner, "put", map[string]any{"state": "issues", "key": "503", "value": 1}); err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
Reference in New Issue
Block a user