I9 dropped-subjects-acked: the hub acknowledges toolchain-agreed and wait-ended with no work and says each subject once
Builds: design 47 H2 H-A-578 (2), H-A-651, H-A-706
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||
)
|
||||
|
||||
// droppedSubjects are the subjects the indexer's manifest no longer consumes while its durable consumer's filter still
|
||||
// holds them, since the grants part never narrows a filter for a dropped entry (design 47 H2 H-A-578 (2), H-A-651): the
|
||||
// toolchain agreement of the builder and the end of a want's wait. Listed once, here, beside the hub's handlers.
|
||||
var droppedSubjects = []string{meshbuilds.SubjectToolchainAgreed, meshwants.SubjectWaitEnded}
|
||||
|
||||
// ackDropped is the hub's handler of a subject no longer consumed: it acknowledges each message at once, with no work, so
|
||||
// the finding event-unhandled stays clear, and says one journal line for the subject at the first one after the start.
|
||||
func ackDropped(subject string, logf func(string, ...any)) func(jetstream.Msg) {
|
||||
var once sync.Once
|
||||
return func(m jetstream.Msg) {
|
||||
once.Do(func() {
|
||||
logf("%s is no longer consumed: its events are acknowledged with no work (design 47 H2 H-A-578 (2))", subject)
|
||||
})
|
||||
_ = m.Ack()
|
||||
}
|
||||
}
|
||||
@@ -616,6 +616,11 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
if err := hub.Handle(decidedSubject(cred.Module), func(m jetstream.Msg) { heardDecided(ctx, registry, m, logger.Printf) }); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, subject := range droppedSubjects {
|
||||
if err := hub.Handle(subject, ackDropped(subject, logger.Printf)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// The indexer's own room wakes every take-in held on a full catalog store (design 47 H §744, H-A-50).
|
||||
if err := hub.Handle(meshcatalog.SubjectRoom, func(m jetstream.Msg) { _ = m.Ack(); go sources.takeAgain() }); err != nil {
|
||||
return err
|
||||
|
||||
@@ -3,6 +3,8 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -113,3 +115,19 @@ func (h *startedHub) StartKept(context.Context, jetstream.JetStream, process.Acc
|
||||
h.kept = true
|
||||
return 1
|
||||
}
|
||||
|
||||
// H-A-578 (2): an event of a subject the indexer no longer consumes is acknowledged with no work, and the journal says
|
||||
// the subject once, at the first.
|
||||
func TestASubjectNoLongerConsumedIsAcknowledgedAndSaidOnce(t *testing.T) {
|
||||
if len(droppedSubjects) != 2 {
|
||||
t.Fatalf("the dropped subjects are %v, want the toolchain agreement and the wait's end", droppedSubjects)
|
||||
}
|
||||
var said []string
|
||||
handle := ackDropped(droppedSubjects[0], func(format string, a ...any) { said = append(said, fmt.Sprintf(format, a...)) })
|
||||
first, second := &ackedMsg{}, &ackedMsg{}
|
||||
handle(first)
|
||||
handle(second)
|
||||
if first.acked != 1 || second.acked != 1 || len(said) != 1 || !strings.Contains(said[0], droppedSubjects[0]) {
|
||||
t.Errorf("acked %d and %d, said %q; want both acknowledged and the subject said once", first.acked, second.acked, said)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user