indexer: say a message given up on the last delivery its consumer allows
The indexer leaves an event it cannot take for the bus to give again, and the bus drops it after the fifth delivery its durable allows without either saying so: a package-published lost so leaves a version unreleased silently. On that last delivery the indexer now says it gives the message up, naming its subject, what it carries (for a package-published the artifact and version) and the last refusal. Builds: design 47 G A-420
This commit is contained in:
@@ -180,6 +180,33 @@ func TestAMessageIsIndexedAndAcked(t *testing.T) { // 1238/AC2 (unit part)
|
||||
}
|
||||
}
|
||||
})
|
||||
// Design 47 G A-420: a package-published that cannot be kept is left for the bus, and on its last delivery said given up,
|
||||
// naming its subject, the artifact and version and the last refusal; before it, nothing more is said.
|
||||
for _, n := range []uint64{4, EventDeliveries} {
|
||||
var said []string
|
||||
m := &deliveredMsg{subject: "mesh.seat.mesh-builds.event.package-published", data: []byte(`{"artifact":"m:program","version":"0.1.6"}`), n: n}
|
||||
heardPackagePublished(context.Background(), &index.Indexer{}, m, func(f string, a ...any) { said = append(said, fmt.Sprintf(f, a...)) })
|
||||
givenUp := strings.Contains(strings.Join(said, "\n"), "gives up mesh.seat.mesh-builds.event.package-published: the package-published of m:program 0.1.6, delivered 5 times")
|
||||
if !m.naked || givenUp != (n == EventDeliveries) || (givenUp && !strings.Contains(strings.Join(said, "\n"), "the last refusal: the state versions is not kept here")) {
|
||||
t.Errorf("delivery %d: naked %v, said %q", n, m.naked, said)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// deliveredMsg is a message delivered n times, which records a Nak.
|
||||
type deliveredMsg struct {
|
||||
jetstream.Msg
|
||||
subject string
|
||||
data []byte
|
||||
n uint64
|
||||
naked bool
|
||||
}
|
||||
|
||||
func (d *deliveredMsg) Subject() string { return d.subject }
|
||||
func (d *deliveredMsg) Data() []byte { return d.data }
|
||||
func (d *deliveredMsg) Nak() error { d.naked = true; return nil }
|
||||
func (d *deliveredMsg) Metadata() (*jetstream.MsgMetadata, error) {
|
||||
return &jetstream.MsgMetadata{NumDelivered: d.n}, nil
|
||||
}
|
||||
|
||||
// opener is a bus that answers every bucket with err.
|
||||
|
||||
@@ -48,6 +48,20 @@ func sayVersionReleased(conn *nats.Conn, cred process.Account) func(context.Cont
|
||||
}
|
||||
}
|
||||
|
||||
// EventDeliveries is how many times the bus gives a message of the indexer's events consumer: the MaxDeliver the grants part
|
||||
// composes a module's durable with (mesh-grants buscompose).
|
||||
const EventDeliveries = 5
|
||||
|
||||
// leftForBus leaves a message the indexer could not take for the bus to give again, and on the last delivery its consumer allows
|
||||
// says that it gives the message up, naming its subject, what it carries and the last refusal (design 47 G A-420): past it the bus
|
||||
// drops the message without a word.
|
||||
func leftForBus(m jetstream.Msg, what string, err error, logf func(string, ...any)) {
|
||||
_ = m.Nak()
|
||||
if md, merr := m.Metadata(); merr == nil && md != nil && md.NumDelivered >= EventDeliveries {
|
||||
logf("gives up %s: %s, delivered %d times, the most its consumer allows; the last refusal: %v", m.Subject(), what, md.NumDelivered, err)
|
||||
}
|
||||
}
|
||||
|
||||
// heardPackagePublished takes one package-published of the seat mesh-builds into the catalog's versions (design 47 G §349):
|
||||
// one that does not decode is said and acknowledged; one that cannot be kept is left, so the bus gives it again.
|
||||
func heardPackagePublished(ctx context.Context, ix *index.Indexer, m jetstream.Msg, logf func(string, ...any)) {
|
||||
@@ -59,7 +73,7 @@ func heardPackagePublished(ctx context.Context, ix *index.Indexer, m jetstream.M
|
||||
}
|
||||
if err := ix.HearPackagePublished(ctx, p); err != nil {
|
||||
logf("versions: the package-published of %s %s could not be kept, so the bus gives it again: %v", p.Artifact, p.Version, err)
|
||||
_ = m.Nak()
|
||||
leftForBus(m, fmt.Sprintf("the package-published of %s %s", p.Artifact, p.Version), err, logf)
|
||||
return
|
||||
}
|
||||
_ = m.Ack()
|
||||
@@ -76,7 +90,7 @@ func heardToolchainAgreed(ctx context.Context, ix *index.Indexer, m jetstream.Ms
|
||||
}
|
||||
if err := ix.HearToolchainAgreed(ctx, t); err != nil {
|
||||
logf("versions: the toolchain-agreed of %s could not be kept, so the bus gives it again: %v", t.Language, err)
|
||||
_ = m.Nak()
|
||||
leftForBus(m, "the toolchain-agreed of "+t.Language, err, logf)
|
||||
return
|
||||
}
|
||||
_ = m.Ack()
|
||||
@@ -93,7 +107,7 @@ func heardVersionDelivered(ctx context.Context, ix *index.Indexer, m jetstream.M
|
||||
}
|
||||
if err := ix.HearVersionDelivered(ctx, d); err != nil {
|
||||
logf("versions: the version-delivered of %s %s could not be kept, so the bus gives it again: %v", d.Module, d.Version, err)
|
||||
_ = m.Nak()
|
||||
leftForBus(m, fmt.Sprintf("the version-delivered of %s %s", d.Module, d.Version), err, logf)
|
||||
return
|
||||
}
|
||||
_ = m.Ack()
|
||||
@@ -109,7 +123,7 @@ func heardWaitEnded(ctx context.Context, ix *index.Indexer, m jetstream.Msg, log
|
||||
}
|
||||
if err := ix.HearWaitEnded(ctx, w); err != nil {
|
||||
logf("versions: the wait-ended of %s for %s could not be kept, so the bus gives it again: %v", w.Part, w.Module, err)
|
||||
_ = m.Nak()
|
||||
leftForBus(m, fmt.Sprintf("the wait-ended of %s for %s", w.Part, w.Module), err, logf)
|
||||
return
|
||||
}
|
||||
_ = m.Ack()
|
||||
@@ -128,13 +142,13 @@ func heardStepEnded(ctx context.Context, ix *index.Indexer, m jetstream.Msg, log
|
||||
if err := json.Unmarshal(m.Data(), &end); err == nil {
|
||||
if err := ix.HearValidationEnded(ctx, end); err != nil {
|
||||
logf("take-in: the end of the validation ask %s is not taken in, so the bus gives it again: %v", end.Ask, err)
|
||||
_ = m.Nak()
|
||||
leftForBus(m, "the end of the validation ask "+end.Ask, err, logf)
|
||||
return
|
||||
}
|
||||
}
|
||||
if err := ix.HearInputEnded(ctx, e); err != nil {
|
||||
logf("inputs: the input of the ask %s could not be deleted, so the bus gives it again: %v", e.Ask, err)
|
||||
_ = m.Nak()
|
||||
leftForBus(m, "the step-ended of the ask "+e.Ask, err, logf)
|
||||
return
|
||||
}
|
||||
_ = m.Ack()
|
||||
|
||||
Reference in New Issue
Block a user