N2 remove-never-delivered: nats_consumer_remove removes a durable never delivered with no pull waiting, whatever its twin
Builds: design 47 H §837 1., H-A-852, H-A-860 (1984/AC-837b)
This commit is contained in:
@@ -392,7 +392,7 @@ func removalTools(bus Bus, said Said, newForm heldEntries, accepted acceptedModu
|
||||
}
|
||||
return []stdio.Tool{
|
||||
{Name: "nats_consumer_remove",
|
||||
Description: "Removes (deletes) one named JetStream consumer of one stream, e.g. a consumer the controller left, such as `controller` of DEAD_LETTER_NOTICES or `controller-merges` of EVENTS (novox/hq ADR 0590 §6), or an orphan on a module's kept-data stream. Refuses a durable named <node>_<module> or beginning <node>_<module>_ for a module of an accepted manifest, on any stream, unless it is an orphan: no pulls waiting on it while its twin (<node>_<module> for <node>_<module>_tools, and back) on the same stream is current, with pulls waiting and a delivery within the setting twin-current-hours (24 by default), both read at the call, and the hand act names that twin (design 47 H2, H-A-472); any other durable goes. Needs `why`, its warrant, kept in the audit trail and recorded as a hand act through mesh-hand-acts (design 47 H, H-A-127); refuses an unknown stream or consumer; reads the consumer first and answers what it was (filters, pending, unacknowledged); the stream and its other consumers are not touched. The bus refuses any consumer the module's credential is not granted.",
|
||||
Description: "Removes (deletes) one named JetStream consumer of one stream, e.g. a consumer the controller left, such as `controller` of DEAD_LETTER_NOTICES or `controller-merges` of EVENTS (novox/hq ADR 0590 §6), or an orphan on a module's kept-data stream. Refuses a durable named <node>_<module> or beginning <node>_<module>_ for a module of an accepted manifest, on any stream, unless it is an orphan: no pulls waiting on it and either it was never delivered (delivered stream sequence 0), whatever its twin (design 47 H, H-A-852), or its twin (<node>_<module> for <node>_<module>_tools, and back) on the same stream is current, with pulls waiting and a delivery within the setting twin-current-hours (24 by default), both read at the call, and the hand act names that twin (design 47 H2, H-A-472); any other durable goes. Needs `why`, its warrant, kept in the audit trail and recorded as a hand act through mesh-hand-acts (design 47 H, H-A-127); refuses an unknown stream or consumer; reads the consumer first and answers what it was (filters, pending, unacknowledged); the stream and its other consumers are not touched. The bus refuses any consumer the module's credential is not granted.",
|
||||
Input: map[string]any{"stream": str("the stream, e.g. DEAD_LETTER_NOTICES"), "consumer": str("the consumer's name, e.g. controller"), "why": str("why it is removed, for the audit trail (required)")},
|
||||
Run: removeConsumer},
|
||||
{Name: "nats_stream_remove",
|
||||
@@ -615,7 +615,8 @@ func NarrowConsumer(ctx context.Context, bus Bus, accepted acceptedModules, cons
|
||||
// module's program's durable <node>_<module> and its tool runner's <node>_<module>_tools (design 47 G, A-340): a module
|
||||
// that moved into the tool runner left the first, one that runs its own program again left the second. A module's
|
||||
// only durable, any other suffix, a durable with pulls waiting, and a durable or twin that cannot be read or a twin
|
||||
// that is not current, stay refused (H-A-127/128). within is the bound of "current", the setting twin-current-hours.
|
||||
// that is not current, stay refused (H-A-127/128), but a durable never delivered (delivered stream sequence 0) with no pull
|
||||
// waiting goes whatever its twin (H-A-852). within is the bound of "current", the setting twin-current-hours.
|
||||
func refuseAcceptedDurable(ctx context.Context, bus Bus, accepted acceptedModules, stream, consumer string, now time.Time, within time.Duration) (string, error) {
|
||||
if accepted == nil {
|
||||
return "", nil
|
||||
@@ -651,6 +652,11 @@ func refuseAcceptedDurable(ctx context.Context, bus Bus, accepted acceptedModule
|
||||
if self.NumWaiting > 0 {
|
||||
return "", fmt.Errorf("%v (it is no orphan: %d pulls waiting on it)", refused, self.NumWaiting)
|
||||
}
|
||||
if self.Delivered.Stream == 0 {
|
||||
// Design 47 H §837 1., H-A-852, H-A-860: a durable never delivered with no pull waiting is removed whatever
|
||||
// its twin; there is no twin to name.
|
||||
return "", nil
|
||||
}
|
||||
sctx, cancel = step(ctx)
|
||||
info, err := readConsumer(sctx, js, stream, twin)
|
||||
cancel()
|
||||
|
||||
@@ -250,7 +250,7 @@ accounts { MESH { jetstream: enabled, users: [
|
||||
if _, err := ajs.Publish(ctx, "mesh.events.one", []byte("{}")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, d := range []string{"novox_m_tools", "ace_q", "g14_both", "g14_both_tools"} {
|
||||
for _, d := range []string{"novox_m", "novox_m_tools", "ace_q", "ace_solo", "g14_both", "g14_both_tools"} {
|
||||
c, _ := ajs.Consumer(ctx, "EVENTS", d)
|
||||
if _, err := c.Next(jetstream.FetchMaxWait(2 * time.Second)); err != nil {
|
||||
t.Fatalf("a delivery to %s: %v", d, err)
|
||||
@@ -286,11 +286,12 @@ accounts { MESH { jetstream: enabled, users: [
|
||||
}
|
||||
for _, row := range []struct{ consumer, refused string }{
|
||||
{"novox_m_tools", "it is no orphan: 1 pulls waiting on it"},
|
||||
{"ace_q_tools", "its twin ace_q on EVENTS is not current"},
|
||||
{"ace_q", "its twin ace_q_tools on EVENTS is not current"},
|
||||
{"ace_solo", "a module of an accepted manifest"},
|
||||
{"g14_both", "it is no orphan: 1 pulls waiting on it"},
|
||||
{"g14_both_tools", "it is no orphan: 1 pulls waiting on it"},
|
||||
{"novox_m", ""},
|
||||
{"ace_q_tools", ""}, // H-A-852: never delivered, no pull waiting, its twin ace_q not current: it goes
|
||||
} {
|
||||
_, err := removeConsumer(map[string]any{"stream": "EVENTS", "consumer": row.consumer, "why": "an orphaned durable"})
|
||||
_, still := ajs.Consumer(ctx, "EVENTS", row.consumer)
|
||||
@@ -304,7 +305,7 @@ accounts { MESH { jetstream: enabled, users: [
|
||||
t.Fatalf("%s: %v (still there: %v), want a refusal saying %q", row.consumer, err, still == nil, row.refused)
|
||||
}
|
||||
}
|
||||
if len(handActs) != 1 || !strings.Contains(handActs[0].What, "novox_m of the stream EVENTS") || !strings.Contains(handActs[0].What, "twin novox_m_tools") {
|
||||
if len(handActs) != 2 || !strings.Contains(handActs[1].What, "ace_q_tools of the stream EVENTS") || !strings.Contains(handActs[0].What, "novox_m of the stream EVENTS") || !strings.Contains(handActs[0].What, "twin novox_m_tools") {
|
||||
t.Fatalf("the orphan's hand act: %+v", handActs)
|
||||
}
|
||||
if r, err := RemoveStream(ctx, bus, say, map[string]any{"stream": "KV_mesh-controller_rollouts", "why": "the controller ended"}); err != nil || !r.(StreamRemoved).Removed || r.(StreamRemoved).Messages != 1 {
|
||||
@@ -353,7 +354,7 @@ accounts { MESH { jetstream: enabled, users: [
|
||||
if k := keys(other); k != "g14.1" {
|
||||
t.Fatalf("another bucket changed: %s", k)
|
||||
}
|
||||
if strings.Join(said, ",") != "consumer-removed,stream-removed,consumer-removed,consumer-removed,consumer-removed,stream-removed,bucket-keys-removed" {
|
||||
if strings.Join(said, ",") != "consumer-removed,stream-removed,consumer-removed,consumer-removed,consumer-removed,consumer-removed,stream-removed,bucket-keys-removed" {
|
||||
t.Fatalf("the audit events said: %v", said)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user