indexer: a branch's durable it makes waits 30 s, delivers 5 times, starts from now

As the grants part gives a module's consumer on a seat event's stream kept by age:
without a start from now a made durable would replay every past source-moved of the
branch past the start's guard; the current revision is read at the start already.

Builds: design 47 H §743, H-A-134 (hq 8d30cc42), H-A-129, H-A-130

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
2026-11-20 12:19:50 +01:00
parent f95a164941
commit e54bf7f346
2 changed files with 15 additions and 1 deletions
@@ -7,6 +7,7 @@ import (
"fmt"
"slices"
"sync"
"time"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
@@ -105,15 +106,26 @@ func bindBranch(js jetstream.JetStream, cred process.Account, logf func(string,
// branchConsumerConfig is the indexer's durable of one watched branch as the mesh gives a module's seat-event consumer
// (mesh-sdk's SeatEventConsumerConfig), named <node>_<indexer>_<branch> as NamedEventConsumer binds it, filtered to the
// branch's source-moved and delivering one message at a time (design 47 H §743, H-A-90, H-A-134).
// branch's source-moved and delivering one message at a time, with the ack wait of 30 s, the at most 5 deliveries and the
// start from now the grants part gives a module's consumer on a seat event's stream kept by age (mesh-grants buscompose
// heardConsumer): the branch's current source revision is read at the start through the gate's source (H-A-129, H-A-130), so
// its past source-moved are never taken in again (design 47 H §743, H-A-90, H-A-134).
func branchConsumerConfig(cred process.Account, branch string) jetstream.ConsumerConfig {
esc := keys.EscapeName(branch)
cfg := cred.SeatEventConsumerConfig([]string{meshdelivery.SubjectSourceMoved(esc, "*")}, false)
cfg.Durable = cred.EventConsumerName() + "_" + esc
cfg.MaxAckPending = 1
cfg.AckWait, cfg.MaxDeliver = branchAckWait, branchMaxDeliver
cfg.DeliverPolicy = jetstream.DeliverNewPolicy
return cfg
}
// The ack wait and the deliveries of a branch's durable, as the grants part gives a module's consumers (H-A-134, H-A-133).
const (
branchAckWait = 30 * time.Second
branchMaxDeliver = 5
)
// refresh binds the consumer of every watched branch not bound yet: at the start and on each registration-changed. A consumer
// not there yet is said and bound at the next registration-changed or start. The start's refresh reads every watched branch's
// source revision, a later one each branch whose consumer could not be bound (H-A-129), after the binds.
@@ -8,6 +8,7 @@ import (
"slices"
"strings"
"testing"
"time"
"github.com/nats-io/nats.go/jetstream"
@@ -226,6 +227,7 @@ func TestABranchDurableNotThereIsMadeAndHeard(t *testing.T) {
}
want := cred.SeatEventConsumerConfig([]string{meshdelivery.SubjectSourceMoved(keys.EscapeName("main"), "*")}, false)
want.Durable, want.MaxAckPending = name, 1
want.AckWait, want.MaxDeliver, want.DeliverPolicy = 30*time.Second, 5, jetstream.DeliverNewPolicy
if len(js.made) != 1 || !reflect.DeepEqual(js.made[0], want) {
t.Fatalf("made %+v, want once %+v", js.made, want)
}