B7 (1) acted-lifetimes: acted is key-ttl with max-mib 4; marks take the lifetime acted-days (30), the release record none; keys of no form go at the start
Builds: design 47 H2 H-A-720 (1) (2) (3) (4)
This commit is contained in:
@@ -294,6 +294,13 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
return err
|
||||
}
|
||||
pq.ackWait = publishSet.PauseMax // a sent item unheard is delivered again after the longest pause (H-A-440 (1))
|
||||
actedDays, err := numberFile(getenv("MESH_BUILDER_ACTED_DAYS_FILE"), versions.DefaultActedDays)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if actedDays > 365 {
|
||||
return fmt.Errorf("the setting acted-days is %d, at most 365", actedDays)
|
||||
}
|
||||
releasedKept, err := numberFile(getenv("MESH_BUILDER_RELEASED_KEPT_FILE"), versions.DefaultReleasedKept)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -329,7 +336,8 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
}
|
||||
// The operator is asked once a key's event builds are spent (design 47 G §568): the builder's asker on the seat operator-channel.
|
||||
decided := &decisions{subject: oc.SubjectDecided(cred.Module)}
|
||||
retakeActed := awaitedReserved{awaitedState{b: actedKV, bucket: own.acted}}
|
||||
retakeActed := markLifetime{awaitedReserved{awaitedState{b: actedKV, bucket: own.acted}}, actedDays}
|
||||
actedKV.Ready(func(kv jetstream.KeyValue) { deleteUnknown(ctx, kv, logger.Printf) })
|
||||
asker := &operatorask.Asker[oc.Warrant]{Module: cred.Module, Call: calls.Call, Record: calls.Ask, Publish: publishVia(ctx, js), Subscribe: decided.hear(logger.Printf),
|
||||
Contract: operatorask.Contract{Seat: oc.Seat, StateAsks: oc.StateAsks},
|
||||
AskSubject: oc.AcceptSubjectAsk, DecidedSubject: oc.SubjectDecided}
|
||||
|
||||
@@ -123,3 +123,75 @@ func emitSeatEvent(ctx context.Context, js jetstream.JetStream, cred process.Acc
|
||||
_, err = js.PublishMsg(pub, msg, jetstream.WithMsgID(id))
|
||||
return err
|
||||
}
|
||||
|
||||
// markLifetime writes the marks of the state acted with the bus's per-message lifetime of the setting acted-days, each write giving
|
||||
// it again (design 47 H2 H-A-720 (1)); the release record and every other key it writes with none (H-A-720 (2)). An update is the
|
||||
// compare-and-set delete of the revision and the create that carries the lifetime, since the bus gives a lifetime at a create.
|
||||
type markLifetime struct {
|
||||
awaitedReserved
|
||||
days int
|
||||
}
|
||||
|
||||
func (s markLifetime) life(key string) (time.Duration, bool) {
|
||||
if mark, _ := versions.ActedFormOf(key); mark {
|
||||
return time.Duration(s.days) * 24 * time.Hour, true
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
|
||||
func (s markLifetime) Create(ctx context.Context, key string, value []byte) (uint64, error) {
|
||||
ttl, ok := s.life(key)
|
||||
if !ok {
|
||||
return s.awaitedReserved.Create(ctx, key, value)
|
||||
}
|
||||
kv, err := s.kv()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
rev, err := kv.Create(ctx, key, value, jetstream.KeyTTL(ttl))
|
||||
return rev, versionsConflict(err)
|
||||
}
|
||||
|
||||
func (s markLifetime) Update(ctx context.Context, key string, value []byte, revision uint64) (uint64, error) {
|
||||
ttl, ok := s.life(key)
|
||||
if !ok {
|
||||
return s.awaitedReserved.Update(ctx, key, value, revision)
|
||||
}
|
||||
kv, err := s.kv()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if err := kv.Delete(ctx, key, jetstream.LastRevision(revision)); err != nil {
|
||||
return 0, versionsConflict(err)
|
||||
}
|
||||
rev, err := kv.Create(ctx, key, value, jetstream.KeyTTL(ttl))
|
||||
return rev, versionsConflict(err)
|
||||
}
|
||||
|
||||
// deleteUnknown deletes each key of the state acted of a form the builder does not write (design 47 H2 H-A-720 (3)) and says the
|
||||
// count once.
|
||||
func deleteUnknown(ctx context.Context, kv jetstream.KeyValue, logf func(string, ...any)) {
|
||||
l, err := kv.ListKeys(ctx)
|
||||
if err != nil {
|
||||
logf("the keys of the state %s are not listed, so none of no form is deleted: %v", versions.ActedState, err)
|
||||
return
|
||||
}
|
||||
var gone []string
|
||||
for k := range l.Keys() {
|
||||
if _, known := versions.ActedFormOf(k); !known {
|
||||
gone = append(gone, k)
|
||||
}
|
||||
}
|
||||
_ = l.Stop()
|
||||
n := 0
|
||||
for _, k := range gone {
|
||||
if err := kv.Delete(ctx, k); err != nil {
|
||||
logf("the key %s of the state %s, of no form the builder writes, is not deleted: %v", k, versions.ActedState, err)
|
||||
continue
|
||||
}
|
||||
n++
|
||||
}
|
||||
if len(gone) > 0 {
|
||||
logf("the state %s: %d keys of no form the builder writes were deleted at the start", versions.ActedState, n)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ const (
|
||||
PublishesLocal = "publishes"
|
||||
// ActedState holds, one key per subject, the last stream sequence the builder acted on; capped at ActedMiB.
|
||||
ActedState = "acted"
|
||||
ActedMiB = 1
|
||||
ActedMiB = 4
|
||||
// PublishQueueTool is builder_publish_queue.
|
||||
PublishQueueTool = "builder_publish_queue"
|
||||
// QueueFull is what version-unreleased says of a version the work queue's cap refused.
|
||||
@@ -331,6 +331,23 @@ func (r *Republisher) end(ctx context.Context, module, version, why string) {
|
||||
}
|
||||
}
|
||||
|
||||
// The forms of the keys of the state acted (design 47 H2 H-A-720): the marks of an event or an ask acted on, each written with the
|
||||
// lifetime of the setting acted-days, and the release record `released.<module>`, written with none. A key of no form is deleted at
|
||||
// the start.
|
||||
const DefaultActedDays = 30
|
||||
|
||||
var actedMarkForms = []string{EscapeToken("retake:"), EscapeToken("retake-asked:"), EscapeToken("retake-ask:")}
|
||||
|
||||
// ActedFormOf says whether key is a mark (known, with a lifetime) or the release record (known, with none), or of no form.
|
||||
func ActedFormOf(key string) (mark, known bool) {
|
||||
for _, f := range actedMarkForms {
|
||||
if strings.HasPrefix(key, f) {
|
||||
return true, true
|
||||
}
|
||||
}
|
||||
return false, strings.HasPrefix(key, ReleasedKey(""))
|
||||
}
|
||||
|
||||
// ActedKey is the acted key of a subject.
|
||||
func ActedKey(subject string) string { return EscapeToken(subject) }
|
||||
|
||||
|
||||
@@ -540,3 +540,23 @@ func TestThePublishQueueToolAnswersAtAnySize(t *testing.T) {
|
||||
t.Errorf("a reader with no bulk read answered %d (%v) with %d single reads, want every key read one by one", b.Total, err, gets)
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 H2 H-A-720: the forms of the keys of the state acted: marks take a lifetime, the release record none, any other key of no
|
||||
// form is deleted at the start.
|
||||
func TestActedKeysHaveForms(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
key string
|
||||
mark, known bool
|
||||
}{
|
||||
{ActedKey("retake:mesh.seat.node-engine.event.running.ace.m"), true, true},
|
||||
{ActedKey("retake-asked:m\x00abc"), true, true},
|
||||
{ActedKey("retake-ask:ask-1"), true, true},
|
||||
{ReleasedKey("m"), false, true},
|
||||
{"junk", false, false},
|
||||
{ActedKey("publish:x"), false, false},
|
||||
} {
|
||||
if mark, known := ActedFormOf(c.key); mark != c.mark || known != c.known {
|
||||
t.Errorf("%q: mark %v, known %v, want %v, %v", c.key, mark, known, c.mark, c.known)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ func TestManifestDeclarations(t *testing.T) { // 1607/AC1
|
||||
if m.Module != "mesh-delivery-builder" {
|
||||
t.Errorf("module = %q", m.Module)
|
||||
}
|
||||
if want := []state{{Name: "builds", History: 5, MaxMiB: 128}, {Name: "engine-reads", History: 1, MaxMiB: 8}, {Name: "findings", History: 5, MaxMiB: 32}, {Name: "hearing", History: 1, MaxMiB: 8}, {Name: "instances", History: 1, MaxMiB: 8}, {Name: "old-form", History: 1, MaxMiB: 8}, {Name: "bounds", History: 1, KeyTTL: true, MaxMiB: 16}, {Name: "taken", History: 1, KeyTTL: true, MaxMiB: 8}, {Name: "queues", History: 1, MaxMiB: 8}, {Name: "toolchains-heard", History: 1, MaxMiB: 8}, {Name: "waits", History: 1, MaxMiB: 4}, {Name: "reserved", History: 1, MaxMiB: 8}, {Name: "acted", History: 1, MaxMiB: 1}, {Name: "asked", History: 1, MaxMiB: 8}, {Name: "reasks", History: 1, MaxMiB: 8}, {Name: "first-views", History: 1, MaxMiB: 8}, {Name: "unbuildable", History: 1, MaxMiB: 8}, {Name: "consumers", History: 1, MaxMiB: 8}}; !reflect.DeepEqual(m.State, want) { // builds.BuilderBuildsHistory // caps per H-A-437 over the fills read on novox 2026-11-22 (design 47 H2 §812, §814)
|
||||
if want := []state{{Name: "builds", History: 5, MaxMiB: 128}, {Name: "engine-reads", History: 1, MaxMiB: 8}, {Name: "findings", History: 5, MaxMiB: 32}, {Name: "hearing", History: 1, MaxMiB: 8}, {Name: "instances", History: 1, MaxMiB: 8}, {Name: "old-form", History: 1, MaxMiB: 8}, {Name: "bounds", History: 1, KeyTTL: true, MaxMiB: 16}, {Name: "taken", History: 1, KeyTTL: true, MaxMiB: 8}, {Name: "queues", History: 1, MaxMiB: 8}, {Name: "toolchains-heard", History: 1, MaxMiB: 8}, {Name: "waits", History: 1, MaxMiB: 4}, {Name: "reserved", History: 1, MaxMiB: 8}, {Name: "acted", History: 1, KeyTTL: true, MaxMiB: 4}, {Name: "asked", History: 1, MaxMiB: 8}, {Name: "reasks", History: 1, MaxMiB: 8}, {Name: "first-views", History: 1, MaxMiB: 8}, {Name: "unbuildable", History: 1, MaxMiB: 8}, {Name: "consumers", History: 1, MaxMiB: 8}}; !reflect.DeepEqual(m.State, want) { // builds.BuilderBuildsHistory // caps per H-A-437 over the fills read on novox 2026-11-22 (design 47 H2 §812, §814)
|
||||
t.Errorf("state = %+v, want %+v", m.State, want)
|
||||
}
|
||||
// 1887/A4c: the builder chooses no node, so it reads neither presence nor have, invokes no build module's tool and
|
||||
@@ -198,7 +198,8 @@ func TestManifestDeclarations(t *testing.T) { // 1607/AC1
|
||||
m.Streams[3].Duplicates != 24 || m.Streams[3].MaxDeliveries != 10 || m.Streams[3].MaxAgeDays != 7 || m.Streams[3].MaxMiB != 64 {
|
||||
t.Errorf("streams = %+v, want waits with wait-held.** and wait-ended.**, 7 days, 16 MiB, the builds' stream (build.ended.**, 7 days, kept last per subject: design 47 G A-181) and the findings' stream", m.Streams)
|
||||
}
|
||||
if c, ok := m.Config["toolchain-wait-minutes"]; !ok || c.Default != float64(60) || len(m.Config) != 13 ||
|
||||
if c, ok := m.Config["toolchain-wait-minutes"]; !ok || c.Default != float64(60) || len(m.Config) != 14 || m.Config["acted-days"].Default != float64(30) || m.Config["acted-days"].Maximum != 365 || // H-A-720 (1)
|
||||
|
||||
// design 47 H2 §775, H-A-381 (2): the kept-call pace and the taken key's bound, read by the process
|
||||
m.Config["kept-call-pace-first"].Default != "1s" || m.Config["kept-call-pace-max"].Default != "30s" || m.Config["ask-taken-bound"].Default != "10m" ||
|
||||
!m.Config["kept-call-pace-first"].Runtime || !m.Config["kept-call-pace-max"].Runtime || !m.Config["ask-taken-bound"].Runtime ||
|
||||
@@ -267,7 +268,7 @@ func TestManifestProcess(t *testing.T) { // 1607/AC1
|
||||
t.Errorf("health = %v, want kind unit alone", p["health"])
|
||||
}
|
||||
env, _ := p["env"].(map[string]any)
|
||||
if len(env) != 9 || env["MESH_BUILDER_RECORD_BOUND_FILE"] != "${dir:state}/record-bound-seconds" || env["MESH_BUILDER_REVISION_WAIT_FILE"] != "${dir:state}/revision-wait-minutes" || env["MESH_BUILDER_PACKAGE_WAIT_FILE"] != "${dir:state}/package-wait-minutes" || env["MESH_BUILDER_PUBLISH_TRIES_FILE"] != "${dir:state}/publish-tries" || env["MESH_BROKER_FILE"] != "${dir:state}/broker" || env["MESH_BUILDER_TOOLCHAIN_WAIT_FILE"] != "${dir:state}/toolchain-wait-minutes" {
|
||||
if len(env) != 10 || env["MESH_BUILDER_RECORD_BOUND_FILE"] != "${dir:state}/record-bound-seconds" || env["MESH_BUILDER_REVISION_WAIT_FILE"] != "${dir:state}/revision-wait-minutes" || env["MESH_BUILDER_PACKAGE_WAIT_FILE"] != "${dir:state}/package-wait-minutes" || env["MESH_BUILDER_PUBLISH_TRIES_FILE"] != "${dir:state}/publish-tries" || env["MESH_BROKER_FILE"] != "${dir:state}/broker" || env["MESH_BUILDER_TOOLCHAIN_WAIT_FILE"] != "${dir:state}/toolchain-wait-minutes" {
|
||||
t.Errorf("env = %v, want the broker file and the path of the toolchain wait's file, never the setting itself (design 47 G §672, A-71)", p["env"])
|
||||
}
|
||||
for k, v := range env {
|
||||
|
||||
@@ -135,7 +135,7 @@
|
||||
{ "name": "toolchains-heard", "history": 1, "max-mib": 8 },
|
||||
{ "name": "waits", "history": 1, "max-mib": 4 },
|
||||
{ "name": "reserved", "history": 1, "max-mib": 8 },
|
||||
{ "name": "acted", "history": 1, "max-mib": 1 },
|
||||
{ "name": "acted", "history": 1, "key-ttl": true, "max-mib": 4 },
|
||||
{ "name": "asked", "history": 1, "max-mib": 8 },
|
||||
{ "name": "reasks", "history": 1, "max-mib": 8 },
|
||||
{ "name": "first-views", "history": 1, "max-mib": 8 },
|
||||
@@ -232,6 +232,14 @@
|
||||
"trusted": false,
|
||||
"default": 30
|
||||
},
|
||||
"acted-days": {
|
||||
"type": "number",
|
||||
"description": "how many days a mark of an event or an ask acted on (state acted) is kept after its last write; the mark outlives every delivery of its event by far (design 47 H2 H-A-720).",
|
||||
"minimum": 1,
|
||||
"maximum": 365,
|
||||
"trusted": false,
|
||||
"default": 30
|
||||
},
|
||||
"released-kept": {
|
||||
"type": "number",
|
||||
"description": "how many of a module's last releases the builder keeps, by fingerprint, to judge a rerun of a released build's step (design 47 G A-456b); the oldest is dropped.",
|
||||
@@ -332,6 +340,14 @@
|
||||
"mode": "0600",
|
||||
"content": "${config:publish-pause-max}"
|
||||
},
|
||||
{
|
||||
"id": "acted-days",
|
||||
"type": "file",
|
||||
"path": "${dir:state}/acted-days",
|
||||
"owner": "mesh-delivery-builder",
|
||||
"mode": "0600",
|
||||
"content": "${config:acted-days}"
|
||||
},
|
||||
{
|
||||
"id": "released-kept",
|
||||
"type": "file",
|
||||
@@ -371,6 +387,7 @@
|
||||
"MESH_BUILDER_PUBLISH_PAUSE_FILE": "${dir:state}/publish-pause",
|
||||
"MESH_BUILDER_PUBLISH_PAUSE_MAX_FILE": "${dir:state}/publish-pause-max",
|
||||
"MESH_BUILDER_PUBLISH_TRIES_FILE": "${dir:state}/publish-tries",
|
||||
"MESH_BUILDER_ACTED_DAYS_FILE": "${dir:state}/acted-days",
|
||||
"MESH_BUILDER_RELEASED_KEPT_FILE": "${dir:state}/released-kept"
|
||||
},
|
||||
"user": "mesh-delivery-builder",
|
||||
|
||||
Reference in New Issue
Block a user