T4: a waiting read lists an ask handed out and not acknowledged, marked again
mesh/queue.waiting reads from each worker's acknowledgement floor, so an ask a worker holds or handed back is listed with again: true; the holder tells the two apart by its own state taken. Builds: design 47 H2 §777, H-A-410 (second addendum)
This commit is contained in:
@@ -19,6 +19,9 @@ type WaitingAsk struct {
|
||||
ID string `json:"id"`
|
||||
Module string `json:"module"`
|
||||
AgeSeconds int64 `json:"age_seconds"`
|
||||
// Again says the ask was handed to a worker at least once and not acknowledged: held now, or handed back to wait again;
|
||||
// the holder tells the two apart by its own state taken (H-A-410, second addendum).
|
||||
Again bool `json:"again,omitempty"`
|
||||
}
|
||||
|
||||
// QueueWaiting is what waits on a seat's work queue, oldest first, and whether the read stopped at QueueWaitingMost.
|
||||
@@ -34,8 +37,8 @@ func seatStream(seat string) string {
|
||||
|
||||
// QueueWaitingOf reads, without consuming, the asks that wait on the seat's work queue for module, the holder whose
|
||||
// membership lists the queue's workers: its own store (ADR 0596). For each of its workers on the seat's stream, every message
|
||||
// the worker has not yet been handed (after its delivered sequence) is read by a direct get by subject, never by a consumer
|
||||
// of its own (design 47 H2 H-A-410).
|
||||
// after the worker's acknowledgement floor is read by a direct get by subject, never by a consumer of its own; one at or
|
||||
// below the worker's delivered sequence is marked again (design 47 H2 H-A-410 and its addenda).
|
||||
func (c *Conn) QueueWaitingOf(module, seat string) (QueueWaiting, error) {
|
||||
t, err := c.trafficOf(module)
|
||||
if err != nil {
|
||||
@@ -77,7 +80,7 @@ func (c *Conn) QueueWaitingOf(module, seat string) (QueueWaiting, error) {
|
||||
if filter == "" {
|
||||
filter = ">"
|
||||
}
|
||||
for seq := info.Delivered.Stream + 1; ; {
|
||||
for seq := info.AckFloor.Stream + 1; ; {
|
||||
m, err := kept.GetMsg(ctx, seq, jetstream.WithGetMsgSubject(filter))
|
||||
if errors.Is(err, jetstream.ErrMsgNotFound) {
|
||||
break
|
||||
@@ -86,7 +89,8 @@ func (c *Conn) QueueWaitingOf(module, seat string) (QueueWaiting, error) {
|
||||
return QueueWaiting{}, fmt.Errorf("reading %s's queue %s: %w", module, stream, err)
|
||||
}
|
||||
seq = m.Sequence + 1
|
||||
ask := WaitingAsk{Module: m.Header.Get("x-source"), AgeSeconds: int64(now.Sub(m.Time) / time.Second)}
|
||||
ask := WaitingAsk{Module: m.Header.Get("x-source"), AgeSeconds: int64(now.Sub(m.Time) / time.Second),
|
||||
Again: m.Sequence <= info.Delivered.Stream}
|
||||
ask.ID = strings.TrimPrefix(m.Header.Get("x-event-id"), ask.Module+".")
|
||||
if size += len(ask.ID) + len(ask.Module) + 48; size > QueueWaitingMost {
|
||||
out.Capped = true
|
||||
|
||||
@@ -231,7 +231,7 @@ func TestABundlePullsAndSettlesThroughItsModulesBus(t *testing.T) {
|
||||
}
|
||||
var got []string
|
||||
for _, a := range w.Asks {
|
||||
got = append(got, fmt.Sprintf("%s:%s:%v", a.Module, a.ID, a.AgeSeconds < 60))
|
||||
got = append(got, fmt.Sprintf("%s:%s:%v", a.Module, a.ID, a.AgeSeconds < 60)+map[bool]string{true: ":again"}[a.Again])
|
||||
}
|
||||
if strings.Join(got, ",") != want {
|
||||
t.Errorf("waiting is %s, want %s", raw, want)
|
||||
@@ -255,8 +255,23 @@ func TestABundlePullsAndSettlesThroughItsModulesBus(t *testing.T) {
|
||||
if _, err := building.Seat("waiting", json.RawMessage(`{"seat":"operator-channel"}`), nil); err == nil {
|
||||
t.Error("the holder read the queue of a seat it holds no worker on")
|
||||
}
|
||||
if _, err := building.Seat("pull", json.RawMessage(`{"worker":"SEAT_NODE_BUILD_GO_DELIVERY_worker","wait_ms":1000}`), nil); err != nil {
|
||||
raw, err = building.Seat("pull", json.RawMessage(`{"worker":"SEAT_NODE_BUILD_GO_DELIVERY_worker","wait_ms":1000}`), nil)
|
||||
if err != nil || json.Unmarshal(raw, &p) != nil {
|
||||
t.Fatal(raw, err)
|
||||
}
|
||||
// a pulled ask, held or handed back, is listed again (the holder tells the two apart by its state taken); one acknowledged
|
||||
// is gone
|
||||
waiting("mesh-delivery-pipeline:ask2:true:again,mesh-delivery-pipeline:ask3:true")
|
||||
if _, err := building.Seat("settle", json.RawMessage(`{"id":"`+p.ID+`","fate":"nak-after","delay_ms":60000}`), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
waiting("mesh-delivery-pipeline:ask3:true") // the pulled ask is taken, no longer waiting
|
||||
waiting("mesh-delivery-pipeline:ask2:true:again,mesh-delivery-pipeline:ask3:true")
|
||||
raw, err = building.Seat("pull", json.RawMessage(`{"worker":"SEAT_NODE_BUILD_GO_DELIVERY_worker","wait_ms":1000}`), nil)
|
||||
if err != nil || json.Unmarshal(raw, &p) != nil {
|
||||
t.Fatal(raw, err)
|
||||
}
|
||||
if _, err := building.Seat("settle", json.RawMessage(`{"id":"`+p.ID+`","fate":"ack"}`), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
waiting("mesh-delivery-pipeline:ask2:true:again")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user