jetstream_bridge 2.4.0 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/jetstream_bridge/core/duration.rb +1 -1
- data/lib/jetstream_bridge/topology/stream.rb +42 -44
- data/lib/jetstream_bridge/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c35f196b9196a72202963a0cd3bd6c69cac3f69b24ffa088acec1da028626b08
|
4
|
+
data.tar.gz: cc6fd1ee6669d29bfb25f9ce0c88102df0e19a764b0402ff7cc2314bdec93fdb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb054b30229005b00cbe3d39c1a798fdf6fe90cce7b8e440105528fa4b3415ecec78058daeaa3c38e43894cca57ccae0b12dff037cbbda260da5959253873ca9
|
7
|
+
data.tar.gz: fd3ed465ab7601c221ba861032467bcef304bf17b0e45335df92c5f862900dfc03592ba95c0bc30ae32ff03b81484f6975709d609d317a9d1e81154bbd8df17a
|
@@ -37,8 +37,7 @@ module JetstreamBridge
|
|
37
37
|
def log_all_blocked(name, blocked)
|
38
38
|
if blocked.any?
|
39
39
|
Logging.warn(
|
40
|
-
"Stream #{name}: all missing subjects belong to other streams; unchanged. "
|
41
|
-
"blocked=#{blocked.inspect}",
|
40
|
+
"Stream #{name}: all missing subjects belong to other streams; unchanged. blocked=#{blocked.inspect}",
|
42
41
|
tag: 'JetstreamBridge::Stream'
|
43
42
|
)
|
44
43
|
else
|
@@ -54,8 +53,7 @@ module JetstreamBridge
|
|
54
53
|
|
55
54
|
def log_not_created(name, blocked)
|
56
55
|
Logging.warn(
|
57
|
-
"Not creating stream #{name}: all desired subjects belong to other streams. "
|
58
|
-
"blocked=#{blocked.inspect}",
|
56
|
+
"Not creating stream #{name}: all desired subjects belong to other streams. blocked=#{blocked.inspect}",
|
59
57
|
tag: 'JetstreamBridge::Stream'
|
60
58
|
)
|
61
59
|
end
|
@@ -70,10 +68,24 @@ module JetstreamBridge
|
|
70
68
|
msg += " (skipped overlapped=#{blocked.inspect})" if blocked.any?
|
71
69
|
Logging.info(msg, tag: 'JetstreamBridge::Stream')
|
72
70
|
end
|
71
|
+
|
72
|
+
def log_config_updated(name, storage:)
|
73
|
+
Logging.info(
|
74
|
+
"Updated stream #{name} config; storage=#{storage.inspect}",
|
75
|
+
tag: 'JetstreamBridge::Stream'
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
79
|
+
def log_retention_mismatch(name, have:, want:)
|
80
|
+
Logging.warn(
|
81
|
+
"Stream #{name} retention mismatch (have=#{have.inspect}, want=#{want.inspect}). " \
|
82
|
+
"Retention is immutable; skipping retention change.",
|
83
|
+
tag: 'JetstreamBridge::Stream'
|
84
|
+
)
|
85
|
+
end
|
73
86
|
end
|
74
87
|
|
75
|
-
# Ensures a stream exists and updates only uncovered subjects, using work-queue semantics
|
76
|
-
# Persist with zero consumers; delete after the first ack (retention: 'workqueue').
|
88
|
+
# Ensures a stream exists and updates only uncovered subjects, using work-queue semantics.
|
77
89
|
class Stream
|
78
90
|
RETENTION = 'workqueue'
|
79
91
|
STORAGE = 'file'
|
@@ -89,17 +101,12 @@ module JetstreamBridge
|
|
89
101
|
info ? ensure_update(jts, name, info, desired) : ensure_create(jts, name, desired)
|
90
102
|
rescue NATS::JetStream::Error => e
|
91
103
|
if StreamSupport.overlap_error?(e) && (attempts += 1) <= 1
|
92
|
-
Logging.warn(
|
93
|
-
"Overlap race while ensuring #{name}; retrying once...",
|
94
|
-
tag: 'JetstreamBridge::Stream'
|
95
|
-
)
|
104
|
+
Logging.warn("Overlap race while ensuring #{name}; retrying once...", tag: 'JetstreamBridge::Stream')
|
96
105
|
sleep(0.05)
|
97
106
|
retry
|
98
107
|
elsif StreamSupport.overlap_error?(e)
|
99
|
-
Logging.warn(
|
100
|
-
|
101
|
-
tag: 'JetstreamBridge::Stream'
|
102
|
-
)
|
108
|
+
Logging.warn("Overlap persists ensuring #{name}; leaving unchanged. err=#{e.message.inspect}",
|
109
|
+
tag: 'JetstreamBridge::Stream')
|
103
110
|
nil
|
104
111
|
else
|
105
112
|
raise
|
@@ -109,18 +116,27 @@ module JetstreamBridge
|
|
109
116
|
|
110
117
|
private
|
111
118
|
|
112
|
-
# ---- keep ensure_update small (<=20 lines, lower ABC) ----
|
113
119
|
def ensure_update(jts, name, info, desired_subjects)
|
114
120
|
existing = StreamSupport.normalize_subjects(info.config.subjects || [])
|
115
121
|
to_add = StreamSupport.missing_subjects(existing, desired_subjects)
|
122
|
+
add_subjects(jts, name, existing, to_add) if to_add.any?
|
116
123
|
|
117
|
-
|
124
|
+
# Retention is immutable; warn if different and do not include on update.
|
125
|
+
have_ret = info.config.retention.to_s.downcase
|
126
|
+
if have_ret != RETENTION
|
127
|
+
StreamSupport.log_retention_mismatch(name, have: have_ret, want: RETENTION)
|
128
|
+
end
|
118
129
|
|
119
|
-
|
120
|
-
|
121
|
-
|
130
|
+
# Storage can be updated; do it without passing retention.
|
131
|
+
have_storage = info.config.storage.to_s.downcase
|
132
|
+
if have_storage != STORAGE
|
133
|
+
apply_update(jts, name, existing, storage: STORAGE)
|
134
|
+
StreamSupport.log_config_updated(name, storage: STORAGE)
|
135
|
+
return
|
122
136
|
end
|
123
137
|
|
138
|
+
return if to_add.any?
|
139
|
+
|
124
140
|
StreamSupport.log_already_covered(name)
|
125
141
|
end
|
126
142
|
|
@@ -129,36 +145,18 @@ module JetstreamBridge
|
|
129
145
|
allowed, blocked = OverlapGuard.partition_allowed(jts, name, to_add)
|
130
146
|
return StreamSupport.log_all_blocked(name, blocked) if allowed.empty?
|
131
147
|
|
132
|
-
target =
|
148
|
+
target = (existing + allowed).uniq
|
133
149
|
OverlapGuard.check!(jts, name, target)
|
150
|
+
# Do not pass retention on update to avoid 10052.
|
134
151
|
apply_update(jts, name, target)
|
135
152
|
StreamSupport.log_updated(name, allowed, blocked)
|
136
153
|
end
|
137
154
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
info.config.retention.to_s.downcase != RETENTION ||
|
144
|
-
info.config.storage.to_s.downcase != STORAGE
|
145
|
-
end
|
146
|
-
|
147
|
-
def apply_update(jts, name, subjects)
|
148
|
-
jts.update_stream(
|
149
|
-
name: name,
|
150
|
-
subjects: subjects,
|
151
|
-
retention: RETENTION,
|
152
|
-
storage: STORAGE
|
153
|
-
)
|
154
|
-
end
|
155
|
-
|
156
|
-
def log_config_updated(name)
|
157
|
-
Logging.info(
|
158
|
-
"Updated stream #{name} config; retention=#{RETENTION.inspect} " \
|
159
|
-
"storage=#{STORAGE.inspect}",
|
160
|
-
tag: 'JetstreamBridge::Stream'
|
161
|
-
)
|
155
|
+
# Only include mutable fields on update (subjects, storage). Never retention.
|
156
|
+
def apply_update(jts, name, subjects, storage: nil)
|
157
|
+
params = { name: name, subjects: subjects }
|
158
|
+
params[:storage] = storage if storage
|
159
|
+
jts.update_stream(**params)
|
162
160
|
end
|
163
161
|
|
164
162
|
def ensure_create(jts, name, desired_subjects)
|